strategy.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. L = []
  37. for line in detail_list:
  38. key = "{}_{}".format(line['gh_id'], line['index'])
  39. article_read = line['increase_read_count']
  40. avg_read = accountBaseInfo[key]['readAvg']
  41. # 计算比率
  42. level_rate = article_read / avg_read - 1
  43. print(level_rate, article_read, avg_read)
  44. print(line)
  45. print("\n")
  46. obj = {
  47. "key": key,
  48. "avg_read": avg_read,
  49. "article_read": article_read,
  50. }