Commit a91354de authored by 高雅喆's avatar 高雅喆

data 2 gmkv

parent ac81bcc4
......@@ -17,6 +17,7 @@ import numpy as np
import pandas as pd
from pyspark.sql.functions import lit
from pyspark.sql.functions import concat_ws
import redis
def send_email(app,id,e):
......@@ -66,7 +67,12 @@ def get_user_history_order_service_tag(user_id, stat_date):
cur_zhengxing.execute(sql)
tags_dict = cur_zhengxing.fetchall()
tags_list = [i["tag_id"] for i in tags_dict]
# 写gmkv
gm_kv_cli = redis.Redis(host="172.16.40.135", port=5379, db=6, socket_timeout=2000)
user_history_order_tags_key = "user:history_order:tags:user_id:" + str(user_id)
tags_list_json = json.dumps(tags_list)
gm_kv_cli.set(user_history_order_tags_key, tags_list_json)
# 写tidb
sql_cl_id = "select device_id from statistic_device where id = (select max(device_id) from statistic_device_user where user_id = %d) " % (int(user_id))
cur_zhengxing.execute(sql_cl_id)
cl_id = cur_zhengxing.fetchall()[0]["device_id"]
......
......@@ -17,6 +17,7 @@ import numpy as np
import pandas as pd
from pyspark.sql.functions import lit
from pyspark.sql.functions import concat_ws
import redis
def send_email(app,id,e):
......@@ -109,7 +110,12 @@ def get_user_tag_score(cl_id, all_log_df, stat_date, size=10):
finally_score.drop_duplicates(subset="tag_id", inplace=True)
finally_score_lst = finally_score[["tag_id","tag_score"]].to_dict('record')
tag_id_list = tag_list2dict(finally_score_lst, size)
# 写gmkv
gm_kv_cli = redis.Redis(host="172.16.40.135", port=5379, db=6, socket_timeout=2000)
cl_id_portrait_key = "user:portrait_tags:cl_id:" + str(cl_id)
tag_id_list_json = json.dumps(tag_id_list)
gm_kv_cli.set(cl_id_portrait_key, tag_id_list_json)
# 写tidb
replace_sql = """replace into user_portrait_tags (stat_date, cl_id, tag_list) values("{stat_date}","{cl_id}","{tag_list}")"""\
.format(stat_date=stat_date, cl_id=cl_id, tag_list=tag_id_list)
cur_jerry_test.execute(replace_sql)
......
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