Commit 17a27d53 authored by 高雅喆's avatar 高雅喆

service_portrait into tidb

parent 9cce3629
......@@ -210,14 +210,22 @@ def get_user_service_portrait(cl_id, all_word_tags, all_tag_tag_type, all_3tag_2
"where cl_id ='{}' and action not in " \
"('api/order/validate','api/settlement/alipay_callback','do_search')".format(cl_id)
cur_jerry_test.execute(user_df_service_sql)
user_df_service = pd.DataFrame(list(cur_jerry_test.fetchall()))
user_df_service.columns = ["time", "cl_id", "score_type", "tag_id", "tag_referrer", "action"]
data = list(cur_jerry_test.fetchall())
if data:
user_df_service = pd.DataFrame()
user_df_service.columns = ["time", "cl_id", "score_type", "tag_id", "tag_referrer", "action"]
else:
user_df_service = pd.DataFrame(columns=["time", "cl_id", "score_type", "tag_id", "tag_referrer", "action"])
# 用户的搜索行为
user_df_search_sql = "select time,cl_id,score_type,tag_id,tag_referrer,action from user_new_tag_log " \
"where cl_id ='{}' and action = 'do_search'".format(cl_id)
cur_jerry_test.execute(user_df_search_sql)
user_df_search = pd.DataFrame(list(cur_jerry_test.fetchall()))
user_df_search.columns = ["time", "cl_id", "score_type", "tag_id", "tag_referrer", "action"]
data_search = list(cur_jerry_test.fetchall())
if data_search:
user_df_search = pd.DataFrame()
user_df_search.columns = ["time", "cl_id", "score_type", "tag_id", "tag_referrer", "action"]
else:
user_df_search = pd.DataFrame(columns=["time", "cl_id", "score_type", "tag_id", "tag_referrer", "action"])
db_jerry_test.close()
# 搜索词转成tag
......@@ -255,6 +263,13 @@ def get_user_service_portrait(cl_id, all_word_tags, all_tag_tag_type, all_3tag_2
tag_id_list_json = json.dumps(gmkv_tag_score_sum)
gm_kv_cli.set(cl_id_portrait_key, tag_id_list_json)
gm_kv_cli.expire(cl_id_portrait_key, time=30 * 24 * 60 * 60)
# 写tidb
stat_date = datetime.datetime.today().strftime('%Y-%m-%d')
replace_sql = """replace into user_service_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=gmkv_tag_score_sum)
cur_jerry_test.execute(replace_sql)
db_jerry_test.commit()
db_jerry_test.close()
return gmkv_tag_score_sum
except Exception as e:
print(e)
......
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