threadinfo.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. from api import ChanAPI
  2. import utils
  3. import matplotlib.pyplot as plt
  4. class ThreadInfo:
  5. def __init__(self, board, number):
  6. api = ChanAPI(board)
  7. self.__data = api.getThread(number)
  8. self.no = number
  9. self.board = board
  10. def __process(self):
  11. self.posts = utils.getThreadObjects(self.__data)
  12. def calculateTimeDeltas(self):
  13. self.__process()
  14. deltas = []
  15. totalPosts = len(self.posts)
  16. for i, _ in enumerate(self.posts):
  17. if (i+1) < totalPosts:
  18. firstPostTime = self.posts[i]["time"]
  19. secondPostTime = self.posts[i+1]["time"]
  20. delta = firstPostTime - secondPostTime
  21. deltas.append(abs(delta))
  22. return deltas
  23. def draw(self):
  24. plt.ylabel("seconds between post")
  25. plt.xlabel("post")
  26. plt.title(f"Time between posts for thread {self.no} on board {self.board}")
  27. deltas = self.calculateTimeDeltas()
  28. plt.plot(deltas)
  29. plt.savefig(f"{self.board}{self.no}.png")
  30. plt.show()