ActualObject.py 802 B

1234567891011121314151617181920212223242526272829
  1. import pandas as pd
  2. import time as ptime
  3. from twin.networking.mqtt import MQTTClient
  4. TIME_FACTOR = 300
  5. ivef = "results-de2/plan-anomaly.csv"
  6. ivef = pd.read_csv(ivef, usecols=["mmsi", "start", "ETA", "source", "target", "task"], dtype={"mmsi": str})
  7. ivef.sort_values("start", inplace=True)
  8. initial_start = ivef.iloc[0]["start"]
  9. ivef["start"] -= initial_start
  10. ivef["ETA"] -= initial_start
  11. ivef["start"] /= 1000
  12. ivef["ETA"] /= 1000
  13. client = MQTTClient("ActualObject")
  14. client.spin()
  15. client.publish("initial_time", [initial_start / 1000, TIME_FACTOR])
  16. time = 0
  17. for ridx, row in ivef.iterrows():
  18. if row["start"] == time:
  19. client.publish("tasks", row.to_list())
  20. else:
  21. duration = row["start"] - time
  22. ptime.sleep(duration / TIME_FACTOR)
  23. client.publish("tasks", row.to_list())
  24. time = row["start"]