1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- """
- @author: luojunhui
- """
- import json
- from tqdm import tqdm
- from applications.functions import Functions
- from config import accountBaseInfo, pool_level_detail
- class ArticlePoolStrategy(object):
- """
- 长文策略池
- """
- Fun = Functions()
- @classmethod
- def getData(cls, article_list):
- """
- :param article_list: 每天召回的文章list
- :return: {
- "Level1": [],
- "Level2": [],
- "Level3": []
- }
- """
- detail_list = []
- print("查询文章url......")
- for i in tqdm(article_list):
- detail = cls.Fun.matchLinkById(i['article_id'])
- i['gh_id'], i['url'], i['index'] = detail
- detail_list.append(i)
- print("查询完成, 开始排序")
- return detail_list
- @classmethod
- def splitByStrategy(cls, detail_list):
- """
- 账号-位置-阅读倍数
- :return:
- """
- L = []
- for line in detail_list:
- key = "{}_{}".format(line['gh_id'], line['index'])
- article_read = line['increase_read_count']
- if accountBaseInfo.get(key):
- avg_read = accountBaseInfo[key]['readAvg']
- # 计算比率
- level_rate = article_read / avg_read - 1
- obj = {
- "key": key,
- "avg_read": avg_read,
- "article_read": article_read,
- "level_rate": level_rate,
- "url": line['url']
- }
- L.append(obj)
- L = sorted(L, key=lambda x: x["level_rate"], reverse=True)
- for index, i in enumerate(L):
- print(index,"\t", i['key'], "\t", i['level_rate'])
- result = {
- "Level1": [],
- "Level2": []
- }
- c = 0
- for line in L:
- print(json.dumps(line, ensure_ascii=False, indent=4))
- if line['level_rate'] > 0.2:
- c += 1
- gh_key = line['key']
- if pool_level_detail.get(gh_key):
- now_level = pool_level_detail[gh_key]
- if now_level == "3":
- result['Level2'].append(line['url'])
- elif now_level == "2":
- result['Level1'].append(line['url'])
- else:
- continue
- else:
- result['Level2'].append(line['url'])
- print(c)
- return result
|