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
d638fb58
Commit
d638fb58
authored
Aug 30, 2019
by
张彦钊
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change test file
parent
0ef3def9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
29 deletions
+37
-29
rerank_esmm.py
rerank_esmm.py
+37
-29
No files found.
rerank_esmm.py
View file @
d638fb58
...
@@ -3,19 +3,24 @@ import datetime
...
@@ -3,19 +3,24 @@ import datetime
import
json
import
json
import
redis
import
redis
import
pandas
as
pd
import
pandas
as
pd
import
time
def
get_esmm_users
():
def
get_esmm_users
():
db
=
pymysql
.
connect
(
host
=
'172.16.40.158'
,
port
=
4000
,
user
=
'root'
,
try
:
passwd
=
'3SYz54LS9#^9sBvC'
,
db
=
'jerry_prod'
)
db
=
pymysql
.
connect
(
host
=
'172.16.40.158'
,
port
=
4000
,
user
=
'root'
,
cursor
=
db
.
cursor
()
passwd
=
'3SYz54LS9#^9sBvC'
,
db
=
'jerry_prod'
)
stat_date
=
(
datetime
.
date
.
today
()
-
datetime
.
timedelta
(
days
=
1
))
.
strftime
(
"
%
Y-
%
m-
%
d"
)
cursor
=
db
.
cursor
()
sql
=
"select distinct device_id,city_id from data_feed_exposure_precise "
\
stat_date
=
(
datetime
.
date
.
today
()
-
datetime
.
timedelta
(
days
=
1
))
.
strftime
(
"
%
Y-
%
m-
%
d"
)
"where stat_date = '{}'"
.
format
(
stat_date
)
sql
=
"select distinct device_id,city_id from data_feed_exposure_precise "
\
cursor
.
execute
(
sql
)
"where stat_date = '{}'"
.
format
(
stat_date
)
result
=
list
(
cursor
.
fetchall
())
cursor
.
execute
(
sql
)
db
.
close
()
result
=
list
(
cursor
.
fetchall
())
return
result
db
.
close
()
return
result
except
:
return
[]
def
get_user_profile
(
device_id
):
def
get_user_profile
(
device_id
):
...
@@ -46,8 +51,6 @@ def get_user_profile(device_id):
...
@@ -46,8 +51,6 @@ def get_user_profile(device_id):
return
[]
return
[]
def
get_searchworlds_to_tagid
():
def
get_searchworlds_to_tagid
():
try
:
try
:
sql
=
'select id, name from api_tag where is_online = 1 and tag_type < 4'
sql
=
'select id, name from api_tag where is_online = 1 and tag_type < 4'
...
@@ -63,24 +66,28 @@ def get_searchworlds_to_tagid():
...
@@ -63,24 +66,28 @@ def get_searchworlds_to_tagid():
return
searchworlds_to_tagid
return
searchworlds_to_tagid
except
Exception
as
e
:
except
Exception
as
e
:
print
(
e
)
return
{}
def
get_queues
(
device_id
,
city_id
):
def
get_queues
(
device_id
,
city_id
):
db
=
pymysql
.
connect
(
host
=
'172.16.40.158'
,
port
=
4000
,
user
=
'root'
,
try
:
passwd
=
'3SYz54LS9#^9sBvC'
,
db
=
'jerry_test'
)
db
=
pymysql
.
connect
(
host
=
'172.16.40.158'
,
port
=
4000
,
user
=
'root'
,
cursor
=
db
.
cursor
()
passwd
=
'3SYz54LS9#^9sBvC'
,
db
=
'jerry_test'
)
sql
=
"select native_queue, nearby_queue, nation_queue, megacity_queue from esmm_device_diary_queue "
\
cursor
=
db
.
cursor
()
"where device_id = '{}' and city_id = '{}'"
.
format
(
device_id
,
city_id
)
sql
=
"select native_queue, nearby_queue, nation_queue, megacity_queue from esmm_device_diary_queue "
\
cursor
.
execute
(
sql
)
"where device_id = '{}' and city_id = '{}'"
.
format
(
device_id
,
city_id
)
result
=
cursor
.
fetchone
()
cursor
.
execute
(
sql
)
db
.
close
()
result
=
cursor
.
fetchone
()
if
len
(
result
)
>
0
:
db
.
close
()
return
list
(
result
)
if
result
is
not
None
:
else
:
return
list
(
result
)
else
:
return
[]
except
:
return
[]
return
[]
def
tag_boost
(
cid_str
,
tag_list
):
def
tag_boost
(
cid_str
,
tag_list
):
if
cid_str
is
not
None
and
cid_str
!=
""
:
if
cid_str
is
not
None
and
cid_str
!=
""
:
cids
=
cid_str
.
split
(
","
)
cids
=
cid_str
.
split
(
","
)
...
@@ -96,6 +103,7 @@ def tag_boost(cid_str, tag_list):
...
@@ -96,6 +103,7 @@ def tag_boost(cid_str, tag_list):
cursor
=
db
.
cursor
()
cursor
=
db
.
cursor
()
cursor
.
execute
(
sql
)
cursor
.
execute
(
sql
)
result
=
cursor
.
fetchall
()
result
=
cursor
.
fetchall
()
db
.
close
()
if
len
(
result
)
>
0
:
if
len
(
result
)
>
0
:
tag_cids
=
{}
tag_cids
=
{}
left_cids
=
[]
left_cids
=
[]
...
@@ -157,19 +165,19 @@ if __name__ == "__main__":
...
@@ -157,19 +165,19 @@ if __name__ == "__main__":
for
i
in
users_list
[:
6
]:
for
i
in
users_list
[:
6
]:
tag_list
=
get_user_profile
(
i
[
0
])
tag_list
=
get_user_profile
(
i
[
0
])
queues
=
get_queues
(
i
[
0
],
i
[
1
])
queues
=
get_queues
(
i
[
0
],
i
[
1
])
if
len
(
queues
)
>
0
:
if
len
(
queues
)
>
0
and
len
(
tag_list
)
>
0
:
new_native
=
tag_boost
(
queues
[
0
],
tag_list
)
new_native
=
tag_boost
(
queues
[
0
],
tag_list
)
new_nearby
=
tag_boost
(
queues
[
1
],
tag_list
)
new_nearby
=
tag_boost
(
queues
[
1
],
tag_list
)
sample
=
[
i
[
0
],
i
[
1
],
new_native
,
new_nearby
,
queues
[
2
],
queues
[
3
]]
sample
=
[
i
[
0
],
i
[
1
],
new_native
,
new_nearby
,
queues
[
2
],
queues
[
3
]
,
int
(
time
.
time
())
]
total_samples
.
append
(
sample
)
total_samples
.
append
(
sample
)
if
len
(
total_samples
)
>
0
:
if
len
(
total_samples
)
>
0
:
df
=
pd
.
DataFrame
(
total_samples
)
df
=
pd
.
DataFrame
(
total_samples
)
df
=
df
.
rename
(
columns
=
{
0
:
"device_id"
,
1
:
"city_id"
,
2
:
"native_queue"
,
df
=
df
.
rename
(
columns
=
{
0
:
"device_id"
,
1
:
"city_id"
,
2
:
"native_queue"
,
3
:
"nearby_queue"
,
4
:
"nation_queue"
,
5
:
", megacity_queue"
})
3
:
"nearby_queue"
,
4
:
"nation_queue"
,
5
:
", megacity_queue"
,
6
:
"insert_time"
})
print
(
total_samples
)
print
(
total_samples
[:
2
]
)
print
(
df
.
head
(
6
))
print
(
df
.
head
(
2
))
# to_data_base(df)
# to_data_base(df)
# to kv
# to kv
...
...
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