strategy.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. """
  2. @author: luojunhui
  3. """
  4. from tqdm import tqdm
  5. from applications.functions import Functions
  6. from config import accountBaseInfo
  7. class ArticlePoolStrategy(object):
  8. """
  9. 长文策略池
  10. """
  11. Fun = Functions()
  12. @classmethod
  13. def getData(cls, article_list):
  14. """
  15. :param article_list: 每天召回的文章list
  16. :return: {
  17. "Level1": [],
  18. "Level2": [],
  19. "Level3": []
  20. }
  21. """
  22. detail_list = []
  23. print("查询文章url......")
  24. for i in tqdm(article_list):
  25. detail = cls.Fun.matchLinkById(i['article_id'])
  26. i['gh_id'], i['url'], i['index'] = detail
  27. detail_list.append(i)
  28. print("查询完成, 开始排序")
  29. return detail_list
  30. @classmethod
  31. def splitByStrategy(cls, detail_list):
  32. """
  33. 账号-位置-阅读倍数
  34. :return:
  35. """
  36. for line in detail_list:
  37. key = "{}_{}".format(line['gh_id'], line['index'])
  38. article_read = line['increase_read_count']
  39. avg_read = accountBaseInfo[key]['readAvg']
  40. # 计算比率
  41. level_rate = article_read / avg_read - 1
  42. print(level_rate)