Commit d638fb58 authored by 张彦钊's avatar 张彦钊

change test file

parent 0ef3def9
...@@ -3,9 +3,11 @@ import datetime ...@@ -3,9 +3,11 @@ 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():
try:
db = pymysql.connect(host='172.16.40.158', port=4000, user='root', db = pymysql.connect(host='172.16.40.158', port=4000, user='root',
passwd='3SYz54LS9#^9sBvC', db='jerry_prod') passwd='3SYz54LS9#^9sBvC', db='jerry_prod')
cursor = db.cursor() cursor = db.cursor()
...@@ -16,6 +18,9 @@ def get_esmm_users(): ...@@ -16,6 +18,9 @@ def get_esmm_users():
result = list(cursor.fetchall()) result = list(cursor.fetchall())
db.close() db.close()
return result 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,22 +66,26 @@ def get_searchworlds_to_tagid(): ...@@ -63,22 +66,26 @@ 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):
try:
db = pymysql.connect(host='172.16.40.158', port=4000, user='root', db = pymysql.connect(host='172.16.40.158', port=4000, user='root',
passwd='3SYz54LS9#^9sBvC', db='jerry_test') passwd='3SYz54LS9#^9sBvC', db='jerry_test')
cursor = db.cursor() cursor = db.cursor()
sql = "select native_queue, nearby_queue, nation_queue, megacity_queue from esmm_device_diary_queue " \ sql = "select native_queue, nearby_queue, nation_queue, megacity_queue from esmm_device_diary_queue " \
"where device_id = '{}' and city_id = '{}'".format(device_id,city_id) "where device_id = '{}' and city_id = '{}'".format(device_id, city_id)
cursor.execute(sql) cursor.execute(sql)
result = cursor.fetchone() result = cursor.fetchone()
db.close() db.close()
if len(result) > 0: if result is not None:
return list(result) return list(result)
else: else:
return [] return []
except:
return []
def tag_boost(cid_str, tag_list): def tag_boost(cid_str, tag_list):
...@@ -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
......
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