Anders and Briegel in Python
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

34 rindas
813B

  1. """
  2. Allows us to visualize the state in a browser
  3. """
  4. import atexit
  5. import threading
  6. import time
  7. from websocket import create_connection
  8. from graphstate import GraphState
  9. import json
  10. class VisibleGraphState(GraphState):
  11. def __init__(self, *args, **kwargs):
  12. GraphState.__init__(self, *args, **kwargs)
  13. self.ws = create_connection("ws://localhost:5001")
  14. atexit.register(self.shutdown)
  15. #self.ws.send(json.dumps({"method":"clear"}))
  16. def shutdown(self):
  17. self.update()
  18. self.ws.close()
  19. def to_json(self):
  20. ngbh = {a: {b : True for b in self.ngbh[a]}
  21. for a in self.ngbh}
  22. return {"vops": self.vops, "ngbh": ngbh, "meta": self.meta}
  23. def update(self):
  24. data = json.dumps(self.to_json())
  25. self.ws.send(data)