TestRunner.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import target as target
  2. from sccd.runtime.statecharts_core import Event
  3. import threading
  4. import matplotlib.pyplot as plt
  5. sim_time_data = []
  6. act_time_data = []
  7. if __name__ == '__main__':
  8. controller = target.Controller()
  9. def raw_inputter():
  10. while 1:
  11. controller.addInput(Event(input(), "input", []))
  12. input_thread = threading.Thread(target=raw_inputter)
  13. input_thread.daemon = True
  14. input_thread.start()
  15. output_listener = controller.addOutputListener(["output"])
  16. def outputter():
  17. sim_time = 0
  18. act_time = 0
  19. while sim_time <= 3:
  20. event = output_listener.fetch(-1)
  21. sim_time = event.getParameters()[0] / 1000.0 # Convert from milliseconds to seconds
  22. act_time = event.getParameters()[1]
  23. # Append times to the lists
  24. sim_time_data.append(sim_time)
  25. act_time_data.append(act_time)
  26. print("SIMTIME: %.2fs" % (sim_time))
  27. print("ACTTIME: %.2fs" % (act_time))
  28. controller.stop()
  29. output_thread = threading.Thread(target=outputter)
  30. output_thread.daemon = True
  31. output_thread.start()
  32. controller.start()
  33. # Now plot the data in the main thread
  34. plt.figure(figsize=(10, 6))
  35. plt.plot(sim_time_data, label='SIMTIME (s)')
  36. plt.plot(act_time_data, label='ACTTIME (s)')
  37. plt.xlabel('Event Index')
  38. plt.ylabel('Time (s)')
  39. plt.title('Simulation Time vs. Actual Time (SCCD Python)')
  40. plt.legend()
  41. plt.grid(True)
  42. plt.show()