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
5b36cb84
Commit
5b36cb84
authored
Aug 09, 2018
by
张彦钊
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify add_data_to_redis,change main for test
parent
b1a057d2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
29 deletions
+17
-29
predictDiary.py
predictDiary.py
+13
-12
utils.py
utils.py
+4
-17
No files found.
predictDiary.py
View file @
5b36cb84
...
...
@@ -90,16 +90,17 @@ def router(device_id):
if
__name__
==
"__main__"
:
# TODO 如果耗时小于一分钟,下一次取到的device_id和上一次相同
while
True
:
start
=
time
.
time
()
empty
,
device_id_list
=
get_active_users
()
if
empty
:
time
.
sleep
(
10
)
else
:
for
device_id
in
device_id_list
:
router
(
device_id
)
end
=
time
.
time
()
time_cost
=
(
end
-
start
)
print
(
"预测耗时{}秒"
.
format
(
time_cost
))
router
(
'358035085192742'
)
# while True:
# start = time.time()
# empty,device_id_list = get_active_users()
# if empty:
# time.sleep(10)
# else:
# for device_id in device_id_list:
# router(device_id)
#
# end = time.time()
# time_cost = (end - start)
# print("预测耗时{}秒".format(time_cost))
utils.py
View file @
5b36cb84
...
...
@@ -15,25 +15,12 @@ def con_sql(sql):
db
.
close
()
return
df
class
Database
:
def
__init__
(
self
):
self
.
host
=
'10.30.50.58'
self
.
port
=
6379
self
.
db
=
12
self
.
write_pool
=
{}
def
add_write
(
self
,
key
,
val
):
self
.
write_pool
[
key
]
=
val
def
batch_write
(
self
):
r
=
redis
.
StrictRedis
(
host
=
self
.
host
,
port
=
self
.
port
,
db
=
self
.
db
)
r
.
mset
(
self
.
write_pool
)
# 把数据写到redis里
def
add_data_to_redis
(
key
,
val
):
db
=
Database
()
db
.
add_write
(
key
,
val
)
db
.
batch_write
()
r
=
redis
.
StrictRedis
(
host
=
'10.30.50.58'
,
port
=
6379
,
db
=
12
)
r
.
set
(
key
,
val
)
# 设置key的过期时间
r
.
expire
(
key
,
36
*
60
)
# ffm 格式转换函数、类
...
...
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