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
5814566a
Commit
5814566a
authored
Sep 03, 2019
by
张彦钊
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change test file
parent
9b94cc89
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
141 deletions
+6
-141
rerank_esmm.py
rerank_esmm.py
+6
-4
userProfile.py
userProfile.py
+0
-137
No files found.
rerank_esmm.py
View file @
5814566a
...
@@ -200,13 +200,15 @@ if __name__ == "__main__":
...
@@ -200,13 +200,15 @@ if __name__ == "__main__":
# to_data_base(df)
# to_data_base(df)
name_tag
=
get_searchworlds_to_tagid
()
name_tag
=
get_searchworlds_to_tagid
()
tag_list
=
get_user_profile
(
"00
C6F623-297E-4608-9988-9774F503639C
"
)
tag_list
=
get_user_profile
(
"00
B75E84-7EFC-40A4-8380-E1AA439A0B0D
"
)
print
(
"用户画像标签:"
)
print
(
"用户画像标签:"
)
print
(
tag_list
)
print
(
tag_list
)
queues
=
get_queues
(
"00C6F623-297E-4608-9988-9774F503639C"
,
"nanchang"
)
# queues = get_queues("00C6F623-297E-4608-9988-9774F503639C", "nanchang")
x
=
"16483286,16358665,16932522,16429516,16269827,16334967,16234359,16337498,16473714,16256535,16450230,16350135,16435631,16443193,16397523,16249791,16372681,16269779,16482897,16399574,16397714,16429944,16374620,16269363,16313830,16876171,16877289,16824936,16846592,16858419,16844128,16839080,16854148,16854225,16847409,16827213,16840833,16855941,16435621,16358297,16845431,16844187,16847341,16856619,16456357,16264922,16317774,16253214,16422248,16441765,16856606,16438172,16468841,16306349,16431036,16427188,16265277,16062215,16113301,16451481,16857833,16298669,16062199,16441783,16358790,16431490,15973050,16457012,16234158,16284713,16858053,16471030,15123644,16406373,16356735,16295054,16417495,15574288,16423459,16332744,16443157,16491555,16270783,16442975,13986185,16055221,16242967,15225580,16191576,15276945,16056374,13163949,16348283,16129213,16171575,16375846,15194582,16334885,15591116,15649596,16062113,14542485,16354162,16270502,16121377,15082216,16441747,16236180,15481104,15321860,16438202,12284918,15655737,15297405,15769263,15506071,16296538,16776595,16775242,16715127,16479675,12747475,15856889,16618155,16620825,16690926,16688188,16668876,16665668,16717035,16307981,12777586,16134876,16657521,16779369,16620025,16703026,16823798,16804088,16625227,16059763,15253194,16690994,16650127,16696796,16687610,16696464,16610968,16618007,16706079,15461348,16688101,16715613,16607555,16701068,16609057,16776674,16608139,16620830,16666242,16816503,16788077,16798520,16705802,16610489,16823787,16791526,13278160,16427651,15260261,16689189,16663385,16616078,16823794,16610510,15417319,16456036,15423815,16570577,16198415,16707732,16715436,16665725,16472481,16468029,15475055,16250197,16166170,16240840,15512772,16797491,16380008,15443404,15758722,16429996,16399500,15632741,15629799,15466226,16246259,15419823,16211097,15361627,16928406,16950721,16244240,16949241,16279200,16416925,16944121,15338446,16942326,16279399,16238390,16359075,16455230,15544727,15261387,16484867,16455701,14492168,16443064,15428870,15360356,16435286,16430510,16477842,15322880,14469877,15442944,16438190,16069784,15345305,16451747,15492383,16334548,14922485,15565836,16237296,15564699,16944496,15753452,12931667,15295334,15268987,16265372,16258635,16271149,15203377,15615019,16949391,15433862,16153967,16122408,15595074,15214791,15578022,16431331,16314789,16458602,16944404,15603296,14054836,16473501,16437363,15286752,16054673,16457116,16469558,16444587,16487795,15420743,15302848,15292671,15506406,15212535,15731191,15718163,16414074,16302087,16942236,15208786,14316913,15271888,16061296,15904499,16148117,15505172,15481940,15900835,16431669,16075233,15753100,15629822,16447594,16480882,16436110,14971705,15364829,14937934,16942151,15569041,12827394,15298676,16456253,16107296,15425892,15442997,16484053,16203962,15432122,15477293,16126021,15265054,16065406,16429890,15788197,15483564,15232783,16118068,16397586,15632328,15398697,15341888,15447955,16278605,16051650,15428485,15441925,15499495,16175364,15466859,16399988,16335645,16295945,11971997,15381803,14133049,16449541,16206894,16062023,15362667,15417338,15299545,15465521,15857981,15445539,15302734,15492424,15293277,15430264,15253079,13641594,15199298,16356559,15322815,15563625,15359651,15329012,15289253,16269608,15211946,15342423,16293219,15418588,15420332,15950975,14442951,16193694,15429146,16390045,16334668,16451583,15298045,16417623,15529394,16245862,15444252,15360456,16234512,15730601,16312240,15968859,16441558,16445451,15340484,15624659,15539778,15634535,15451719,16278815,15574949,16286903,15323056,15204510,15729450,16308061,14548975,15778306,15656572,15553322,15328591,15499454,15322657,15322057,14142174,15574285,15730836,16431824,16271436,14471640,15329892,15531526,15526215,15573353,15655387,16417416,15525680,16186814,15568380,15468859,14688720,13362735,15370774,16430570,16356416,16035495,15803783,16261431,14315672,15709396,14316094,15199981,15293261,13670242,15356996,15711642,15135363,15427590,16335497,15850770,15485913,15198600,16266340,15637086,15329411,15545824,16201819,9238528,15216408,15419266,15296861,15825261,15296971,15434426,15585114,14782223,15293587,15245075,15488696,15582718,16295949,16552274,12458246,10323051,15764136,16401259,15227154,15494384,15757822,15961808,15239922,15863022,12599691,13758360,11813529,16338075,13706853,15724812,15415088,15222137,15334490,16228942,14328858,15415181,15628848,15118962,15639895,15969234,15635897,16038195,13930203,15610177,16443179,15330767,15569408,15487552,15843663,16234869,16242618,13056043,14619375,15365547,16470867,15776414,16071401,15358705,14441823,16184302,15329873,15265238,15757398,15989529,16241205,13512722,15522899,15598142,14074436,15238001,16439961,15788022,15432126,15875737,15216397,16353856,15394056,15256584,15466647,15299111,15335800,16487670,15504163,16201643,15207895,15298339,16078179,15394050,15806965,15429632,16295383,16837810,16258188,16457420,16848897,16429750,16491125,16547504,16496107,16547384,16457148,16444221,16827371,16233887,16854345,16394902,16825413,16428327,16427251,16829919,16598511,16411651,16455223,16456272,16400913,16530851,16456769,16852230,16836120,16566748,16444753,16845968,16831026,16329454,16339360,16840963,16287271,16533075,16484502,16834769,16836875,16433917,16826229,16417380,16293449,16481368,16267021,16854110,16446993,16317847,16435669,16830877,16883902,16598662,16435628,16908951,16373885,16567493,16274601,16310467,16858102,16859669,16427220,16366615,16456364,16847345,16359051,16493824,16457491,16468986,16280425,16451716,16433841,16566800,16446952,16430198,16487309,16841074,16885499,16455696,16882182,16875119,16485634,16433329,16890631,16265011,16515512,16874083,16825348,16373555,16467631,16875322,16381271,16546211,16270259,16547545,16520409,16486899,16393548,16267964,16271267,16443054,16406724,16267125,16836084,16858305,16263877,16459476,16859582,16391402,16860401,16483005,16331464,16577329,16478077,16485610,16878806,16890807,16270574,16251733,16451617,16506594,16419841,16324381,16497164,16266878,16533040,16467438,16379944,16885035,16427994,16482012,16567237,16846792,16473969,16491686,16502950,16891808,16848381,16253253,16261851,16848526,16430160,16497290,16430664,16450194,16468371,16350139,16890822,16397445,16479036,16881402,16880534,16494800,16836842,16470490,16830126,16878923,16442269,16533071,16482564,16547424,16488696,16454994,16268908,16891778,16457443,16477945,16491700,16860307,16299737,16448600,16262148,16443431,16565523,16427663,16836882,16437556,16394394,16847143,16244688,16251770,16445868,16298387,16250802,16238901,16457345,16917080,16847008,16406740,16552830,16848391,16299215,16548366,16312069,16295961,16873872,16468053,16482313,16501807,16836103,16860183,16384420,16309888,16481367,16858254,16827340,16439970,16845977,16577749,16270544,16511025,16480805,16430679,16835856,16844288,16346217,16380030,16393447,16241362,16577636,16858281,16848907,16834548,16264128,16857825,16394522,16430642,16435629,16509055,16396151,16443251,16488821,16882040,16457960,16900706,16251376,16436228,16487248,16581759,16251139,16853713,16407351,16842669,16459711,16384039,16332289,16284044,16457508,16443340,16480943,16582891,16270522,16451738,16479838,16252612,16305663,16406713,16333978,16356395,16286098,16534739,16428343,16399047,16827295,16480628,16825106,16236431,16433448,16864227,16834606,16508375,16469935,16487296,16356667,16256587,16469219,16279556,16430061,16324515,16567447,16412315,16362174,16447730,16424680,16854124,16855918,16890277,16357190,16406869,16846586,16858137,16239084,16336535,16439092,16267518,16397513,16873083,16860375,16284485,16332611,16297112,16488876,16431260,16412245,16559934,16443635,16265804,16426094,16826386,16488660,16873146,16306575,16836934,16293430,16892871,16483434,16270443,16842636,16428315,16844313,16875192,16549944,16471045,16477992,16469112,16298374,16446029,16350910,16456276,16434913,16356496,16891963,16298613,16270888,16251970,16309889,16836850,16847411,16852207,16485471,16858408,16274590,16293417,16484822,16399665,16387439,16424738,16329277,16502897,16391926,16435664,16330475,16406884,16296910,16836941,16459865,16879146,16569395,16259711,16356771,16842899,16567418,16488720,16485950,16487292,16858396,16448221,16528425,16873042,16848873,16355964,16435623,16434962,16308814,16257210,16510986,16267159,16266083,16430120,16439955,16264798,16450200,16295852,16431370,16856337,16843236,16875308,16492991,16358726,16839035,16394378,16491520,16845526,16876747,16429051,16355079,15649490,16483181,16423487,15301454,16827644,16129214,15512622,15358354,15297451,15360927,12456449,15436138,16298364,16376974,16875170,15541884,15383535,15588358,13395096,16049931,15035119,15563821,15469015,15382142,16848176,15272004,15240721,15429446,16428125,15594747,16158706,15206772,15348769,15504439,16864258,15297706,15659286,15880368,16434783,16449914,15518732,15637489,15433219,12035,16884777,15295439,15206940,16286921,16854001,16858427,16469567,16251341,16238838,16451895,16561445,15280334,16489107,16289795,16564434,16602164,16848625,16236842,16845904,15390025"
print
(
"排序前:"
)
print
(
"排序前:"
)
print
(
queues
[
0
]
)
print
(
x
)
new_native
=
tag_boost
(
queues
[
0
]
,
tag_list
)
new_native
=
tag_boost
(
x
,
tag_list
)
print
(
"排序后:"
)
print
(
"排序后:"
)
print
(
new_native
)
print
(
new_native
)
...
...
userProfile.py
View file @
5814566a
...
@@ -8,143 +8,6 @@ import pymysql
...
@@ -8,143 +8,6 @@ import pymysql
import
time
import
time
# 统计尾号6的活跃用户数
def
unique_user_count
(
file_path
,
temp_list
,
now
):
if
os
.
path
.
exists
(
file_path
):
# 尾号是6的活跃用户数
tail_6_list
=
eval
(
pd
.
read_csv
(
file_path
)
.
loc
[
0
,
"list"
])
else
:
tail_6_list
=
[]
tail_6_list
.
extend
(
list
(
filter
(
lambda
x
:
(
str
(
x
)[
-
1
]
==
"6"
),
temp_list
)))
if
tail_6_list
!=
[]:
df_tail_6
=
pd
.
DataFrame
({
"number"
:
[
len
(
set
(
tail_6_list
))],
"time"
:
[
str
(
now
)[:
16
]],
"list"
:
[
list
(
set
(
tail_6_list
))]})
df_tail_6
.
to_csv
(
file_path
,
index
=
None
)
print
(
"截止现在尾号是6的独立活跃数:{}"
.
format
(
len
(
set
(
tail_6_list
))))
# 统计预测过的独立用户数
def
predict_user_count
(
predict_file_path
,
device_list
,
now
):
if
os
.
path
.
exists
(
predict_file_path
):
# 预测过尾号是6的用户数
all_predict_list
=
eval
(
pd
.
read_csv
(
predict_file_path
)
.
loc
[
0
,
"list"
])
else
:
all_predict_list
=
[]
all_predict_list
.
extend
(
device_list
)
if
all_predict_list
!=
[]:
df_predict
=
pd
.
DataFrame
({
"number"
:
[
len
(
set
(
all_predict_list
))],
"time"
:
[
str
(
now
)[:
16
]],
"list"
:
[
list
(
set
(
all_predict_list
))]})
df_predict
.
to_csv
(
predict_file_path
,
index
=
None
)
print
(
"截止现在预测过尾号是6的独立活跃数:{}"
.
format
(
len
(
set
(
all_predict_list
))))
# 获取当下一分钟内活跃用户
def
get_active_users
(
flag
,
path
,
differ
):
if
differ
==
0
:
end
=
time
.
time
()
start
=
time
.
time
()
-
60
elif
0
<
differ
<
10
:
time
.
sleep
(
30
)
differ
+=
30
end
=
time
.
time
()
start
=
end
-
differ
else
:
end
=
time
.
time
()
start
=
end
-
differ
end_datetime
=
str
(
datetime
.
fromtimestamp
(
end
))
start_datetime
=
str
(
datetime
.
fromtimestamp
(
start
))
if
flag
:
sql
=
"select device_id,city_id from user_active_time "
\
"where active_time <= '{}' and active_time >= '{}'"
.
format
(
end_datetime
,
start_datetime
)
db
=
pymysql
.
connect
(
host
=
ACTIVE_USER_DB_ONLINE
[
"host"
],
port
=
ACTIVE_USER_DB_ONLINE
[
"port"
],
user
=
ACTIVE_USER_DB_ONLINE
[
"user"
],
passwd
=
ACTIVE_USER_DB_ONLINE
[
"passwd"
],
db
=
ACTIVE_USER_DB_ONLINE
[
"db"
])
df
=
con_sql
(
db
,
sql
)
else
:
db
=
pymysql
.
connect
(
host
=
ACTIVE_USER_DB_LOCAL
[
"host"
],
port
=
ACTIVE_USER_DB_LOCAL
[
"port"
],
user
=
ACTIVE_USER_DB_LOCAL
[
"user"
],
db
=
ACTIVE_USER_DB_LOCAL
[
"db"
])
sql
=
"select device_id,city_id from user_active_time"
df
=
con_sql
(
db
,
sql
)
if
df
.
empty
:
print
(
"当下没有活跃用户数"
)
return
[]
# 统计活跃用户中尾号是6的用户数
else
:
temp_list
=
df
[
0
]
.
values
.
tolist
()
now
=
datetime
.
now
()
tail6_file_path
=
path
+
"{}tail6Unique.csv"
.
format
(
str
(
now
)[:
10
])
unique_user_count
(
tail6_file_path
,
temp_list
,
now
)
# if os.path.exists(tail6_file_path):
# # 尾号是6的活跃用户数
# tail_6_list = eval(pd.read_csv(tail6_file_path).loc[0, "list"])
# else:
# tail_6_list = []
#
# tail_6_list.extend(list(filter(lambda x: (str(x)[-1] == "6"), temp_list)))
# if tail_6_list != []:
# df_tail_6 = pd.DataFrame({"number": [len(set(tail_6_list))], "time": [str(now)[:16]],
# "list": [list(set(tail_6_list))]})
# df_tail_6.to_csv(tail6_file_path, index=None)
#
# print("截止现在尾号是6的独立活跃数:{}".format(len(set(tail_6_list))))
old_device_id_list
=
pd
.
read_csv
(
path
+
"data_set_device_id.csv"
)[
"device_id"
]
.
values
.
tolist
()
# 求活跃用户和老用户的交集,也就是只预测老用户
df
=
df
.
loc
[
df
[
0
]
.
isin
(
old_device_id_list
)]
if
df
.
empty
:
print
(
"该列表是新用户,不需要预测"
)
return
[]
else
:
# TODO 正式上线后注释下面的只预测尾号是6的代码
# 只预测尾号是6的ID,这块是测试要求的
device_temp_list
=
df
[
0
]
.
values
.
tolist
()
predict_list
=
list
(
filter
(
lambda
x
:
(
str
(
x
)[
-
1
]
==
"6"
)
or
(
str
(
x
)
==
"358035085192742"
)
or
str
(
x
)
==
"AB20292B-5D15-4C44-9429-1C2FF5ED26F6"
,
device_temp_list
))
if
predict_list
==
[]:
print
(
'没有尾号是6和目标用户'
)
return
[]
else
:
df
=
df
.
loc
[
df
[
0
]
.
isin
(
predict_list
)]
device_list
=
df
[
0
]
.
values
.
tolist
()
city_list
=
df
[
1
]
.
values
.
tolist
()
device_city_list
=
list
(
zip
(
device_list
,
city_list
))
print
(
"当下这一分钟预测用户数量:{}"
.
format
(
len
(
device_city_list
)))
#统计尾号6的预测用户
predict_file_path
=
path
+
"{}predictTail6Unique.csv"
.
format
(
str
(
now
)[:
10
])
predict_user_count
(
predict_file_path
,
device_list
,
now
)
# if os.path.exists(predict_file_path):
# # 预测过尾号是6的用户数
# all_predict_list = eval(pd.read_csv(predict_file_path).loc[0, "list"])
# else:
# all_predict_list = []
# all_predict_list.extend(device_list)
# if all_predict_list != []:
# df_predict = pd.DataFrame({"number": [len(set(all_predict_list))], "time": [str(now)[:16]],
# "list": [list(set(all_predict_list))]})
# df_predict.to_csv(predict_file_path, index=None)
return
device_city_list
def
fetch_user_profile
(
device_id
):
db
=
pymysql
.
connect
(
host
=
'10.66.157.22'
,
port
=
4000
,
user
=
'root'
,
passwd
=
'3SYz54LS9#^9sBvC'
,
db
=
'jerry_test'
)
sql
=
"select device_id,city_id from data_feed_click where device_id = '{0}' limit 1"
.
format
(
device_id
)
user_profile
=
con_sql
(
db
,
sql
)
if
user_profile
.
empty
:
print
(
"没有获取到该用户对应的city_id"
)
return
None
,
True
else
:
user_profile
=
user_profile
.
rename
(
columns
=
{
0
:
"device_id"
,
1
:
"city_id"
})
user_profile_dict
=
{}
for
i
in
user_profile
.
columns
:
user_profile_dict
[
i
]
=
user_profile
.
loc
[
0
,
i
]
return
user_profile_dict
,
False
def
fetch_qa
(
device_id
,
card_type
,
size
):
def
fetch_qa
(
device_id
,
card_type
,
size
):
try
:
try
:
key
=
'{device_id}-{card_type}-{date}'
.
format
(
device_id
=
device_id
,
key
=
'{device_id}-{card_type}-{date}'
.
format
(
device_id
=
device_id
,
...
...
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