Commit 81986785 authored by 赵威's avatar 赵威

get result

parent 39b08cc5
import datetime
import json
import random
from itertools import chain, zip_longest
from .cache import redis_client2, redis_client4
# merge_lists([1, 2], [3, 5, 6, 7], [4])
# [1, 3, 4, 2, 5, 6, 7]
def merge_lists(*lol):
a = zip_longest(*lol)
return [i for i in chain(*a) if i is not None]
def get_n_unread_data_from_ids(data, size, read_lst):
"""
data: ['852170', '864084', '231589']
......@@ -33,6 +41,34 @@ def get_before_5_days_date():
return [getdate(i) for i in range(5)]
def remove_read_with_size(lol, content_type, read_list, size=500):
"""
content_type: diary, tractate, answer
diary, tractate: [[15358970, 16999710, 16569184, 16457012, 16424738], [17213175, 17203529, 16196387, 15597816, 16715016]]
answer [[['78937', 25449], ['50691', 19437]], [['78937', 25449], ['50691', 19437]]]
"""
read = set(read_list)
res = []
for i in lol:
tmp = []
if (content_type in ["diary", "tractate"]):
for id in i:
if len(tmp) >= size:
break
if id not in read:
tmp.append(id)
res.append(tmp)
else:
for (id_str, question_id) in i:
id = int(id_str)
if len(tmp) >= size:
break
if id not in read:
tmp.append([id_str, question_id])
res.append(tmp)
return res
def _user_portrait_tag3_get_candidate_key(device_id, content_type, latest=False):
"""
content_type: diary, tractate, answer
......@@ -79,6 +115,10 @@ def user_portrait_tag3_get_candidate_unread_list(device_id, content_type):
content_type: diary
return: []
"""
queue = []
read_list, _ = get_user_portrait_tag3_read_v2(device_id, content_type)
candidate_list = list(user_portrait_tag3_get_candidate_dict(device_id, content_type).values())
return get_n_unread_data_from_ids(candidate_list, 500, read_list)
diary_dict = user_portrait_tag3_get_candidate_dict(device_id, "diary")
if diary_dict:
lol = remove_read_with_size(diary_dict.values(), "diary", read_list, 500)
queue = merge_lists(*lol)
return queue
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