Commit 1ef54615 authored by 张彦钊's avatar 张彦钊

测试获取用户画像方法

parent 1ed4a89f
......@@ -192,9 +192,9 @@ def diary_write(device_id,cid):
# ssc.start()
# ssc.awaitTermination()
def make_data(device_id,city_id):
def make_data(device_id,city_id,key_head):
r = redis.StrictRedis.from_url("redis://redis.paas-test.env:6379/2")
key = "device_diary_queue_rerank:device_id:" + device_id + ":city_id:" + city_id
key = key_head + device_id + ":city_id:" + city_id
r.hset(name=key, key="native_queue", value=native)
r.hset(name=key, key="nearby_queue", value=nearby)
r.hset(name=key, key="nation_queue", value=nation)
......@@ -202,11 +202,14 @@ def make_data(device_id,city_id):
print(r.hgetall(key))
if __name__ == "__main__":
native = ",".join([str(i) for i in (range(2, 6))])
nearby = ",".join([str(i) for i in (range(6, 10))])
nation = ",".join([str(i) for i in (range(10, 13))])
megacity = ",".join([str(i) for i in (range(13, 16))])
make_data("hello","beijing")
native = ",".join([str(i) for i in (range(69, 72))])
nearby = ",".join([str(i) for i in (range(73, 76))])
nation = ",".join([str(i) for i in (range(77, 80))])
megacity = ",".join([str(i) for i in (range(81, 83))])
# key_head = "device_diary_queue_rerank:device_id:"
key_head = "device_diary_queue:device_id:"
make_data("868663038800471", "beijing", key_head)
......
......@@ -173,64 +173,44 @@ def to_data_base(df):
print("insert done")
def get_all_users():
try:
sql = "select distinct device_id,city_id from esmm_device_diary_queue"
result = get_mysql_data('172.16.40.158', 4000, 'root','3SYz54LS9#^9sBvC','jerry_test',sql)
result = list(result)
return result
except:
return []
if __name__ == "__main__":
# users_list = get_esmm_users()
# print("user number")
# print(len(users_list))
#
# name_tag = get_searchworlds_to_tagid()
# n = 1000
# split_users_list = [users_list[i:i + n] for i in range(0, len(users_list), n)]
# for child_users_list in split_users_list:
# total_samples = list()
# for uid_city in child_users_list:
# tag_list = get_user_profile(uid_city[0])
# queues = get_queues(uid_city[0], uid_city[1])
# if len(queues) > 0 and len(tag_list) > 0:
# new_native = tag_boost(queues[0], tag_list)
# new_nearby = tag_boost(queues[1], tag_list)
#
# insert_time = str(datetime.datetime.now().strftime('%Y%m%d%H%M'))
# sample = [uid_city[0], uid_city[1], new_native, new_nearby, queues[2], queues[3], insert_time]
# total_samples.append(sample)
#
# if len(total_samples) > 0:
# df = pd.DataFrame(total_samples)
# df = df.rename(columns={0: "device_id", 1: "city_id",2:"native_queue",
# 3:"nearby_queue",4:"nation_queue",5:"megacity_queue",6:"time"})
#
# to_data_base(df)
users_list = get_all_users()
name_tag = get_searchworlds_to_tagid()
device_id = "00B75E84-7EFC-40A4-8380-E1AA439A0B0D"
tag_list = get_user_profile(device_id)
print("用户画像标签:")
print(tag_list)
device_id = "00C6F623-297E-4608-9988-9774F503639C"
tag_list = get_user_profile(device_id)
print("用户画像标签:")
print(tag_list)
# 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(x)
# new_native = tag_boost(x, tag_list)
# print("排序后:")
# print(new_native)
# cid_str = "16473983,16296886,16199213,16193883,16419499,16372783,16430184,16617593,16498902,16238415,16214258,15715721,16213338,15349114,14091428,16268804,15485655,16448547,16179842,16685025,16612412,16683132,15646229,16482213,16485831,16436136,16353856,16400696,16193006,16294202,16393228,16716816,16713343,16780702,16107140,16647027,16112786,16503037,16372681,16207971,16179934,16480641,16295094,16204980,16317847,16434907,16117929,15633591,16116818"
# print(tag_boost(cid_str))
n = 1000
split_users_list = [users_list[i:i + n] for i in range(0, len(users_list), n)]
for child_users_list in split_users_list:
total_samples = list()
for uid_city in child_users_list:
tag_list = get_user_profile(uid_city[0])
queues = get_queues(uid_city[0], uid_city[1])
if len(queues) > 0 and len(tag_list) > 0:
new_native = tag_boost(queues[0], tag_list)
new_nearby = tag_boost(queues[1], tag_list)
insert_time = str(datetime.datetime.now().strftime('%Y%m%d%H%M'))
sample = [uid_city[0], uid_city[1], new_native, new_nearby, queues[2], queues[3], insert_time]
total_samples.append(sample)
if len(total_samples) > 0:
df = pd.DataFrame(total_samples)
df = df.rename(columns={0: "device_id", 1: "city_id",2:"native_queue",
3:"nearby_queue",4:"nation_queue",5:"megacity_queue",6:"time"})
to_data_base(df)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment