main.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. from inputs.snap7_server import SiemensServer
  2. from inputs.snap7_connect import SiemensCPU
  3. from inputs.balluff_html import Balluff
  4. from inputs.allen_bradley_connect import AllenBradleyCPU
  5. from database import *
  6. import logging
  7. import time
  8. logging.basicConfig(level=logging.WARNING)
  9. logging.info("starting")
  10. sources = [
  11. SiemensCPU("192.168.10.6"),
  12. SiemensServer(),
  13. #Balluff(),
  14. AllenBradleyCPU("192.168.10.5"),
  15. ]
  16. sinks = [
  17. InfluxDB("http://localhost:8086"),
  18. CSVFile("logs"),
  19. ]
  20. for source in sources:
  21. source.start()
  22. logging.info("started sources")
  23. startTime = 0
  24. def printStats(values):
  25. global startTime
  26. counts = {}
  27. dt = time.monotonic() - startTime
  28. startTime = time.monotonic()
  29. text = ""
  30. for meas in values:
  31. id = "{} {}".format(meas.series, meas.source)
  32. if id in counts:
  33. counts[id] += 1
  34. else:
  35. counts[id] = 1
  36. if counts:
  37. ids = list(counts.keys())
  38. ids.sort()
  39. for id in ids:
  40. text += "{}: {:4d} in {:.03f}s, {:.1f}/s ".format(id, counts[id], dt, counts[id] / dt)
  41. else:
  42. text = "0 Messungen in {:.03f}s ".format(dt)
  43. print(text, end='\r')
  44. while True:
  45. values = []
  46. for source in sources:
  47. values.extend(source.read())
  48. for sink in sinks:
  49. sink.write(values)
  50. printStats(values)
  51. time.sleep(1.9)