Commit 51937cd8 authored by 赵威's avatar 赵威

update user

parent c099f57b
...@@ -187,6 +187,7 @@ def _get_all_by_projects(name_lst): ...@@ -187,6 +187,7 @@ def _get_all_by_projects(name_lst):
def update_tag3_user_portrait(cl_id): def update_tag3_user_portrait(cl_id):
user_df = get_tag3_user_log(cl_id) user_df = get_tag3_user_log(cl_id)
order_df = get_tag3_user_order_log(cl_id)
if not user_df.empty: if not user_df.empty:
user_df["first_solutions"] = list(zip(user_df["first_solutions"].apply(lambda x: x.split(",")), user_df["tag_score"])) user_df["first_solutions"] = list(zip(user_df["first_solutions"].apply(lambda x: x.split(",")), user_df["tag_score"]))
user_df["second_solutions"] = list(zip(user_df["second_solutions"].apply(lambda x: x.split(",")), user_df["tag_score"])) user_df["second_solutions"] = list(zip(user_df["second_solutions"].apply(lambda x: x.split(",")), user_df["tag_score"]))
...@@ -240,6 +241,24 @@ def update_tag3_user_portrait(cl_id): ...@@ -240,6 +241,24 @@ def update_tag3_user_portrait(cl_id):
if k not in forbidden_set: if k not in forbidden_set:
projects_score[k] = v projects_score[k] = v
paid_business_tags_score = {}
validate_business_tags_score = {}
if not order_df.empty:
paid_order_df = order_df[order_df["event_cn"] == "支付订单"]
if not paid_order_df.empty:
paid_order_df["business_tags"] = list(zip(paid_order_df["business_tags"].apply(lambda x: x.split(",")), user_df["tag_score"]))
paid_order_df["business_tags_dict"] = paid_order_df["business_tags"].apply(lambda x: make_dict_from_pair(x))
paid_business_tags_list = paid_order_df["business_tags_dict"].tolist()
paid_business_tags_score = merge_values(paid_business_tags_list)
validate_order_df = order_df[order_df["event_cn"] == "验证订单"]
if not validate_order_df.empty:
validate_order_df["business_tags"] = list(zip(validate_order_df["business_tags"].apply(lambda x: x.split(",")), user_df["tag_score"]))
validate_order_df["business_tags_dict"] = validate_order_df["business_tags"].apply(lambda x: make_dict_from_pair(x))
validate_business_tags_list = validate_order_df["business_tags_dict"].tolist()
validate_business_tags_score = merge_values(validate_business_tags_list)
tmp_res = {} tmp_res = {}
if (len(first_demands_score) == 0) and (len(first_solutions_score) == 0) and (len(first_positions_score) == 0) and ( if (len(first_demands_score) == 0) and (len(first_solutions_score) == 0) and (len(first_positions_score) == 0) and (
len(second_demands_score) == 0) and (len(second_solutions_score) == 0) and (len(second_positions_score) == 0): len(second_demands_score) == 0) and (len(second_solutions_score) == 0) and (len(second_positions_score) == 0):
...@@ -253,7 +272,9 @@ def update_tag3_user_portrait(cl_id): ...@@ -253,7 +272,9 @@ def update_tag3_user_portrait(cl_id):
"first_positions": first_positions_score, "first_positions": first_positions_score,
"second_positions": second_positions_score, "second_positions": second_positions_score,
"projects": projects_score, "projects": projects_score,
"business_tags": business_tags_score "business_tags": business_tags_score,
"paid_business_tags": paid_business_tags_score,
"validate_business_tags": validate_business_tags_score
} }
if tmp_res: if tmp_res:
res.update(tmp_res) res.update(tmp_res)
...@@ -351,7 +372,7 @@ if __name__ == "__main__": ...@@ -351,7 +372,7 @@ if __name__ == "__main__":
# update_tag3_user_portrait(cl_id) # update_tag3_user_portrait(cl_id)
cl_id = "867617044159377" cl_id = "867617044159377"
print(get_tag3_user_order_log(cl_id)) print(update_tag3_user_portrait(cl_id))
# consume_kafka() TODO # consume_kafka() TODO
end = datetime.datetime.now() end = datetime.datetime.now()
......
...@@ -442,7 +442,8 @@ def get_tag3_user_log(cl_id): ...@@ -442,7 +442,8 @@ def get_tag3_user_log(cl_id):
return pd.DataFrame(columns=columns) return pd.DataFrame(columns=columns)
def 1get_tag3_user_order_log(cl_id): # select log_time, score_type, business_tags, event_cn from kafka_tag3_log where cl_id = '867617044159377' and event_cn in ('支付订单', '验证订单');
def get_tag3_user_order_log(cl_id):
columns = [ columns = [
"log_time", "score_type", "business_tags", "event_cn" "log_time", "score_type", "business_tags", "event_cn"
] ]
...@@ -465,6 +466,7 @@ def 1get_tag3_user_order_log(cl_id): ...@@ -465,6 +466,7 @@ def 1get_tag3_user_order_log(cl_id):
user_df["days_diff_now"] = round((int(time.time()) - user_df["log_time"].astype(float)) / (24 * 60 * 60)) user_df["days_diff_now"] = round((int(time.time()) - user_df["log_time"].astype(float)) / (24 * 60 * 60))
user_df["tag_score"] = user_df.apply(lambda x: compute_tag3_score(x), axis=1) user_df["tag_score"] = user_df.apply(lambda x: compute_tag3_score(x), axis=1)
user_df["business_tags"] = user_df["business_tags"].fillna("") user_df["business_tags"] = user_df["business_tags"].fillna("")
return user_df
except Exception as e: except Exception as e:
print(e) print(e)
return pd.DataFrame(columns=columns) return pd.DataFrame(columns=columns)
......
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