get_intervals.py 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # -*- coding: utf-8 -*-
  2. # @Author: wangkun
  3. # @Time: 2023/7/18
  4. import datetime
  5. # 读取日志文件并将每行日志存储到一个列表中
  6. # with open('../logs/benshanzhufu-recommend-2023-07-17.log', 'r') as file:
  7. # with open('../logs/douyin-author-2023-07-17.log', 'r') as file:
  8. with open('../logs/douyin-recommend-2023-07-19.log', 'r') as file:
  9. # with open('../logs/kuaishou-author-2023-07-17.log', 'r') as file:
  10. # with open('../logs/kuaishou-recommend-2023-07-17.log', 'r') as file:
  11. # with open('../logs/xigua-author-2023-07-17.log', 'r') as file:
  12. # with open('../logs/xigua-search-2023-07-17.log', 'r') as file:
  13. # with open('../logs/xiaoniangao-author-2023-07-17.log', 'r') as file:
  14. # with open('../logs/xiaoniangao-play-2023-07-17.log', 'r') as file:
  15. # with open('../logs/xiaoniangao-hour-2023-07-17.log', 'r') as file:
  16. # with open('../logs/suisuiniannianyingfuqi-recommend-2023-07-17.log', 'r') as file:
  17. # with open('../logs/gongzhonghao-author1-2023-07-18.log', 'r') as file:
  18. # with open('../logs/gongzhonghao-author2-2023-07-18.log', 'r') as file:
  19. # with open('../logs/gongzhonghao-author3-2023-07-18.log', 'r') as file:
  20. # with open('../logs/gongzhonghao-author4-2023-07-18.log', 'r') as file:
  21. # with open('../logs/gongzhonghao-author5-2023-07-18.log', 'r') as file:
  22. # with open('../logs/gongzhonghao-author6-2023-07-18.log', 'r') as file:
  23. log_lines = file.readlines()
  24. # 存储间隔时间的列表
  25. intervals = []
  26. # 遍历日志列表,计算相邻两条日志的时间间隔
  27. for i in range(1, len(log_lines)):
  28. if "2023-" not in log_lines[i-1] or "2023-" not in log_lines[i]:
  29. continue
  30. # 解析时间戳
  31. timestamp1 = datetime.datetime.strptime(log_lines[i - 1].split(".")[0], '%Y-%m-%d %H:%M:%S')
  32. timestamp2 = datetime.datetime.strptime(log_lines[i].split(".")[0], '%Y-%m-%d %H:%M:%S')
  33. # 计算时间间隔
  34. interval = timestamp2 - timestamp1
  35. # 将时间间隔添加到间隔时间列表中
  36. intervals.append(interval)
  37. # 对间隔时间列表进行倒序排序
  38. intervals.sort(reverse=True)
  39. # 取前10条间隔时间
  40. top_10_intervals = intervals[:10]
  41. # 取前10条间隔时间的秒数
  42. top_10_intervals_seconds = [int(interval.total_seconds()) for interval in top_10_intervals]
  43. # 打印结果
  44. print(top_10_intervals_seconds)
  45. # benshanzhufu [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
  46. # douyin_author [30, 28, 25, 20, 18, 18, 17, 17, 17, 16]
  47. # douyin_recommend [62, 50, 38, 34, 33, 31, 31, 31, 31, 31]
  48. # kuaishou_author [31, 27, 23, 21, 21, 21, 19, 19, 17, 15]
  49. # kuaishou_recommend [27, 23, 23, 23, 23, 22, 22, 22, 21, 21]
  50. # xigua_author [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
  51. # xigua_search [18, 14, 14, 13, 13, 12, 11, 11, 11, 10]
  52. # xiaoniangao_author [4, 4, 4, 4, 4, 4, 4, 4, 4, 4]
  53. # xiaoniangao_play [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
  54. # xiaoniangao_hour [61, 3, 2, 2, 2, 2, 2, 2, 1, 1]
  55. # suisuiniannian [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
  56. # gzh1 [26, 26, 26, 25, 25, 25, 25, 24, 24, 24]
  57. # gzh2 [28, 26, 25, 25, 24, 24, 24, 24, 24, 24]
  58. # gzh3 [27, 26, 26, 25, 25, 25, 24, 24, 24, 24]
  59. # gzh4 [26, 26, 25, 24, 24, 24, 24, 24, 24, 24]
  60. # gzh5 [29, 26, 25, 25, 24, 24, 24, 24, 24, 24]
  61. # gzh6 [26, 25, 25, 25, 25, 24, 24, 24, 24, 24]