print_stats.py 805 B

1234567891011121314151617181920212223242526272829303132
  1. import logging
  2. import time
  3. logger = logging.getLogger(__name__)
  4. class PrintStats:
  5. def __init__(self, parent):
  6. self.startTime = time.monotonic()
  7. def execute(self, values):
  8. counts = {}
  9. dt = time.monotonic() - self.startTime
  10. self.startTime = time.monotonic()
  11. text = ""
  12. for meas in values:
  13. id = "{} {}".format(meas.series, meas.source)
  14. if id in counts:
  15. counts[id] += 1
  16. else:
  17. counts[id] = 1
  18. if counts:
  19. ids = list(counts.keys())
  20. ids.sort()
  21. for id in ids:
  22. text += "{}: {:4d} in {:.03f}s, {:.1f}/s ".format(id, counts[id], dt, counts[id] / dt)
  23. else:
  24. text = "0 Messungen in {:.03f}s ".format(dt)
  25. if not counts or len(ids) < 3:
  26. logger.warning(text)
  27. else:
  28. logger.info(text)