TimeStamp.py 900 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import time
  2. class TimeStamp:
  3. keys: [str]
  4. values: [int]
  5. total: int
  6. def __init__(self):
  7. self.keys = []
  8. self.values = []
  9. self.total = 0
  10. def save(self, key: str):
  11. tm = time.time()
  12. self.keys.append(key)
  13. self.values.append(tm)
  14. def info(self):
  15. lastKey = None
  16. lastValue = None
  17. msg: [str] = []
  18. for i in enumerate(self.keys):
  19. k = self.keys[i[0]]
  20. v = self.values[i[0]]
  21. if lastValue is None:
  22. lastKey = k
  23. lastValue = v
  24. else:
  25. use = round(v - lastValue, 4)
  26. msg.append(k + " -> " + lastKey + " use " + str(use))
  27. lastKey = k
  28. lastValue = v
  29. self.total += use
  30. msg.append("total: " + str(self.total))
  31. for s in msg:
  32. print(s)