Commit 05bcb84f authored by 段英荣's avatar 段英荣

modify

parent 443cf875
...@@ -68,7 +68,6 @@ class CollectData(object): ...@@ -68,7 +68,6 @@ class CollectData(object):
if len(recommend_tag_list) > 0: if len(recommend_tag_list) > 0:
tag_recommend_redis_key = self.linucb_recommend_redis_prefix + str(device_id) tag_recommend_redis_key = self.linucb_recommend_redis_prefix + str(device_id)
redis_client.set(tag_recommend_redis_key, json.dumps(recommend_tag_list)) redis_client.set(tag_recommend_redis_key, json.dumps(recommend_tag_list))
# Todo:设置过期时间,调研set是否支持
redis_client.expire(tag_recommend_redis_key, 7*24*60*60) redis_client.expire(tag_recommend_redis_key, 7*24*60*60)
have_read_topic_id_list = Tools.get_have_read_topic_id_list(device_id,user_id,TopicPageType.HOME_RECOMMEND) have_read_topic_id_list = Tools.get_have_read_topic_id_list(device_id,user_id,TopicPageType.HOME_RECOMMEND)
...@@ -80,38 +79,35 @@ class CollectData(object): ...@@ -80,38 +79,35 @@ class CollectData(object):
recommend_topic_id_list_click = list() recommend_topic_id_list_click = list()
recommend_topic_id_list_click_dict = dict() recommend_topic_id_list_click_dict = dict()
if click_topic_tag_list and len(click_topic_tag_list)>0:
if click_topic_tag_list: recommend_topic_id_list_click,recommend_topic_id_list_click_dict = ESPerform.get_tag_topic_list_dict(click_topic_tag_list,
if len(click_topic_tag_list)>0:
recommend_topic_id_list_click,recommend_topic_id_list_click_dict = ESPerform.get_tag_topic_list_dict(click_topic_tag_list,
have_read_topic_id_list,size=2) have_read_topic_id_list,size=2)
if len(recommend_topic_id_list_click) > 0: if len(recommend_topic_id_list_click) > 0:
recommend_topic_id_list.extend(recommend_topic_id_list_click) recommend_topic_id_list.extend(recommend_topic_id_list_click)
recommend_topic_id_list_dict.update(recommend_topic_id_list_click_dict) recommend_topic_id_list_dict.update(recommend_topic_id_list_click_dict)
have_read_topic_id_list.extend(recommend_topic_id_list_click) # have_read_topic_id_list.extend(recommend_topic_id_list_click)
click_recommend_redis_key = self.click_recommend_redis_key_prefix + str(device_id) # click_recommend_redis_key = self.click_recommend_redis_key_prefix + str(device_id)
click_redis_data_dict = { # click_redis_data_dict = {
"data": json.dumps(recommend_topic_id_list), # "data": json.dumps(recommend_topic_id_list),
"datadict":json.dumps(recommend_topic_id_list_dict), # "datadict":json.dumps(recommend_topic_id_list_dict),
"cursor": 0 # "cursor": 0
} # }
redis_client.hmset(click_recommend_redis_key, click_redis_data_dict) # redis_client.hmset(click_recommend_redis_key, click_redis_data_dict)
tag_id_list = recommend_tag_list[0:100] tag_id_list = recommend_tag_list[0:100]
topic_recommend_redis_key = self.linucb_recommend_topic_id_prefix + str(device_id) topic_recommend_redis_key = self.linucb_recommend_topic_id_prefix + str(device_id)
redis_topic_data_dict = redis_client.hgetall(topic_recommend_redis_key) # redis_topic_data_dict = redis_client.hgetall(topic_recommend_redis_key)
redis_topic_list = list() # redis_topic_list = list()
cursor = -1 # cursor = -1
if b"data" in redis_topic_data_dict: # if b"data" in redis_topic_data_dict:
redis_topic_list = json.loads(redis_topic_data_dict[b"data"]) if redis_topic_data_dict[ # redis_topic_list = json.loads(redis_topic_data_dict[b"data"]) if redis_topic_data_dict[
b"data"] else [] # b"data"] else []
cursor = int(str(redis_topic_data_dict[b"cursor"], encoding="utf-8")) # cursor = int(str(redis_topic_data_dict[b"cursor"], encoding="utf-8"))
if len(recommend_topic_id_list)==0 and cursor==0 and len(redis_topic_list)>0: # if len(recommend_topic_id_list)==0 and cursor==0 and len(redis_topic_list)>0:
have_read_topic_id_list.extend(redis_topic_list[:2]) # have_read_topic_id_list.extend(redis_topic_list[:2])
tag_topic_dict = dict()
if len(new_user_click_tag_list)>0: if len(new_user_click_tag_list)>0:
tag_topic_id_list,tag_topic_dict = ESPerform.get_tag_topic_list_dict(new_user_click_tag_list, have_read_topic_id_list) tag_topic_id_list,tag_topic_dict = ESPerform.get_tag_topic_list_dict(new_user_click_tag_list, have_read_topic_id_list)
...@@ -119,7 +115,7 @@ class CollectData(object): ...@@ -119,7 +115,7 @@ class CollectData(object):
tag_topic_id_list,tag_topic_dict = ESPerform.get_tag_topic_list_dict(tag_id_list,have_read_topic_id_list) tag_topic_id_list,tag_topic_dict = ESPerform.get_tag_topic_list_dict(tag_id_list,have_read_topic_id_list)
if len(recommend_topic_id_list)>0 or len(new_user_click_tag_list) > 0: if len(recommend_topic_id_list)>0 or len(tag_topic_id_list)>0 or len(new_user_click_tag_list) > 0:
tag_topic_id_list = recommend_topic_id_list + tag_topic_id_list tag_topic_id_list = recommend_topic_id_list + tag_topic_id_list
tag_topic_dict.update(recommend_topic_id_list_dict) tag_topic_dict.update(recommend_topic_id_list_dict)
redis_data_dict = { redis_data_dict = {
...@@ -128,11 +124,6 @@ class CollectData(object): ...@@ -128,11 +124,6 @@ class CollectData(object):
"cursor":0 "cursor":0
} }
redis_client.hmset(topic_recommend_redis_key,redis_data_dict) redis_client.hmset(topic_recommend_redis_key,redis_data_dict)
else:
if cursor<=0 and len(redis_topic_list)>0:
tag_topic_dict = list()
tag_topic_dict = redis_topic_list[:2]
tag_topic_dict = list(set(tag_topic_dict))
return True return True
except: except:
......
...@@ -89,22 +89,22 @@ def get_home_recommend_topic_ids(user_id, device_id, tag_id, offset, size, query ...@@ -89,22 +89,22 @@ def get_home_recommend_topic_ids(user_id, device_id, tag_id, offset, size, query
recommend_topic_dict = redis_client.hgetall(topic_recommend_redis_key) recommend_topic_dict = redis_client.hgetall(topic_recommend_redis_key)
if b"data" in recommend_topic_dict: if b"data" in recommend_topic_dict:
recommend_topic_id_list = json.loads(recommend_topic_dict[b"data"]) linucb_recommend_topic_id_list = json.loads(recommend_topic_dict[b"data"])
# 推荐帖子是强插的,要保证推荐帖子不在已读里 # 推荐帖子是强插的,要保证推荐帖子不在已读里
# recommend_topic_id_list = list(set(recommend_topic_id_list) - set(have_read_topic_id_list)) recommend_topic_id_list = list(set(linucb_recommend_topic_id_list) - set(have_read_topic_id_list))
cursor = int(str(recommend_topic_dict[b"cursor"], encoding="utf-8")) recommend_topic_id_list.sort(key=linucb_recommend_topic_id_list.index)
newcursor = cursor + 6 # cursor = int(str(recommend_topic_dict[b"cursor"], encoding="utf-8"))
if len(recommend_topic_id_list) > newcursor: # newcursor = cursor + 6
recommend_topic_list = recommend_topic_id_list[cursor:newcursor] if len(recommend_topic_id_list) > 6:
redis_client.hset(topic_recommend_redis_key, "cursor", newcursor) recommend_topic_list = recommend_topic_id_list[0:6]
# redis_client.hset(topic_recommend_redis_key, "cursor", newcursor)
if b"datadict" in recommend_topic_dict: if b"datadict" in recommend_topic_dict:
recommend_topic_id_dict = json.loads(recommend_topic_dict[b"datadict"]) linucb_recommend_topic_id_dict = json.loads(recommend_topic_dict[b"datadict"])
if len(recommend_topic_list) == 6 and recommend_topic_id_dict is not None: if len(recommend_topic_list) == 6 and linucb_recommend_topic_id_dict is not None:
for i in recommend_topic_list: for i in recommend_topic_list:
recommend_topic_user_list.append(recommend_topic_id_dict[str(i)]) recommend_topic_user_list.append(linucb_recommend_topic_id_dict[str(i)])
# 用户关注标签 # 用户关注标签
redis_tag_data = redis_client.hget("physical:linucb:register_user_tag_info", user_id) redis_tag_data = redis_client.hget("physical:linucb:register_user_tag_info", user_id)
attention_tag_list = json.loads(redis_tag_data) if redis_tag_data else [] attention_tag_list = json.loads(redis_tag_data) if redis_tag_data else []
......
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