task_analysis.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. """
  2. @author: luojunhui
  3. """
  4. import json
  5. import pandas as pd
  6. with open("AccountInfo.json", encoding="utf-8") as f:
  7. account_base_info = json.loads(f.read())
  8. new_d = {}
  9. for key in account_base_info:
  10. value = account_base_info[key]
  11. name = value['accountName']
  12. position = value['position']
  13. read_avg = value['readAvg']
  14. new_key = "{}_{}".format(name, position)
  15. new_d[new_key] = read_avg
  16. df = pd.read_excel("非实验数据.xlsx")
  17. L = []
  18. a = 0
  19. b = 0
  20. for line in df.values.tolist():
  21. dt = line[0]
  22. account_name = line[1]
  23. title = line[2]
  24. link = line[3]
  25. pos = line[4]
  26. read = line[5]
  27. avg_read = new_d.get("{}_{}".format(account_name, pos), 0)
  28. if avg_read:
  29. avg_times = read / avg_read
  30. if avg_times > 1.3:
  31. is_up = 1
  32. a += 1
  33. else:
  34. is_up = 0
  35. b += 1
  36. strategy = line[-7]
  37. # if "军事" in strategy or "历史" in strategy:
  38. # ac_t = "实验"
  39. # else:
  40. ac_t = "对照"
  41. L.append([dt, account_name, title, link, pos, read, avg_read, avg_times, is_up, ac_t, strategy])
  42. print([dt, account_name, title, link, pos, read, avg_read, avg_times, is_up, ac_t, strategy])
  43. print(b)
  44. print(a)
  45. print(a + b)
  46. print(a / (a + b))
  47. # out_df = pd.DataFrame(
  48. # L,
  49. # columns=['日期', '账号名称', '标题', '链接', '文章位置', '阅读量', '阅读均值', '阅读均值倍数', '是否晋升', '实验/对照', '冷启品类']
  50. # )
  51. #
  52. # out_df.to_excel("result.xlsx", index=False)