Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
F
ffm-baseline
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ML
ffm-baseline
Commits
0a9947c2
Commit
0a9947c2
authored
Aug 16, 2018
by
张彦钊
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add multi process predict
parent
df7a805c
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
8 deletions
+35
-8
predictDiary.py
predictDiary.py
+35
-8
No files found.
predictDiary.py
View file @
0a9947c2
...
@@ -89,6 +89,18 @@ def router(device_id):
...
@@ -89,6 +89,18 @@ def router(device_id):
predict
(
user_profile
)
predict
(
user_profile
)
# 多进程预测
def
multi_predict
(
predict_list
,
processes
=
8
):
pool
=
Pool
(
processes
)
for
device_id
in
predict_list
:
start
=
time
.
time
()
pool
.
apply_async
(
router
,
(
device_id
,))
end
=
time
.
time
()
print
(
"该用户{}预测耗时{}秒"
.
format
(
device_id
,
(
end
-
start
)))
pool
.
close
()
pool
.
join
()
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
# TODO 如果耗时小于一分钟,下一次取到的device_id和上一次相同
# TODO 如果耗时小于一分钟,下一次取到的device_id和上一次相同
while
True
:
while
True
:
...
@@ -100,14 +112,29 @@ if __name__ == "__main__":
...
@@ -100,14 +112,29 @@ if __name__ == "__main__":
time
.
sleep
(
58
)
time
.
sleep
(
58
)
else
:
else
:
old_device_id_list
=
pd
.
read_csv
(
DIRECTORY_PATH
+
"data_set_device_id.csv"
)[
"device_id"
]
.
values
.
tolist
()
old_device_id_list
=
pd
.
read_csv
(
DIRECTORY_PATH
+
"data_set_device_id.csv"
)[
"device_id"
]
.
values
.
tolist
()
for
device_id
in
device_id_list
:
predict_list
=
list
(
set
(
device_id_list
)
&
set
(
old_device_id_list
))
if
device_id
in
old_device_id_list
:
multi_predict
(
predict_list
)
start
=
time
.
time
()
router
(
device_id
)
# while True:
end
=
time
.
time
()
# empty,device_id_list = get_active_users()
print
(
"该用户预测耗时{}秒"
.
format
(
end
-
start
))
# if empty:
else
:
# for eachFile in os.listdir("/tmp"):
print
(
"该用户不是老用户,不能预测"
)
# if "xlearn" in eachFile:
# os.remove("/tmp" + "/" + eachFile)
# time.sleep(58)
# else:
# old_device_id_list = pd.read_csv(DIRECTORY_PATH + "data_set_device_id.csv")["device_id"].values.tolist()
# for device_id in device_id_list:
# if device_id in old_device_id_list:
# start = time.time()
# router(device_id)
# end = time.time()
# print("该用户预测耗时{}秒".format(end - start))
# else:
# print("该用户不是老用户,不能预测")
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment