summaryrefslogtreecommitdiff
path: root/dashboard_website/datastructs.py
diff options
context:
space:
mode:
authorAnson Bridges <bridges.anson@gmail.com>2023-11-10 00:00:10 -0500
committerAnson Bridges <bridges.anson@gmail.com>2023-11-10 00:00:10 -0500
commit0e5d5ea7b26e55a6b83a10c53eada788d87428c2 (patch)
tree4c32407e1e09c1f1063836461f305e41c427bccf /dashboard_website/datastructs.py
parent04f7d71f25078d38a267d8e848bf556e8b6d3a0b (diff)
routes begin to show .
Diffstat (limited to 'dashboard_website/datastructs.py')
-rw-r--r--dashboard_website/datastructs.py81
1 files changed, 81 insertions, 0 deletions
diff --git a/dashboard_website/datastructs.py b/dashboard_website/datastructs.py
new file mode 100644
index 0000000..6870521
--- /dev/null
+++ b/dashboard_website/datastructs.py
@@ -0,0 +1,81 @@
+import time
+# time since last ping before deactivating/deleting
+BIKE_TIMEOUT = 60
+BIKE_DELETE = 1800 # time before bike deletes itself
+
+# data structures
+class Point:
+ def __init__(self, lat, long):
+ self.longitude = long
+ self.latitude = lat
+
+ def toJSON(self):
+ json_dict = {'longitude' : self.longitude,
+ 'latitude' : self.latitude}
+ return json_dict
+
+ def setCoords(self, lat, long):
+ self.longitude = long
+ self.latitude = lat
+
+ def move(self, d_lat, d_long):
+ self.longitude += d_long
+ self.latitude += d_lat
+
+ def __str__(self):
+ return f"{self.longitude},{self.latitude}"
+
+class Clue(Point):
+ def __init__(self, lat, long, name, info, status):
+ self.longitude = long
+ self.latitude = lat
+ self.name = name
+ self.info = info
+ self.status = status # UNVISITED | ASSIGNED | VISITED
+
+ def visit(self):
+ self.status = "VISITED"
+
+ def toJSON(self):
+ json_dict = {'longitude' : self.longitude,
+ 'latitude' : self.latitude,
+ 'clue_name' : self.name.replace('"', "'"),
+ 'clue_info' : self.info.replace('"', "'"),
+ 'clue_status' : self.status}
+ return json_dict
+
+class Bike(Point):
+ def __init__(self, lat, long, name, status):
+ self.longitude = long
+ self.latitude = lat
+ self.name = name
+ self.last_contact = time.time()
+ self.target = "N/A"
+ self.route_to_next = [] # list of coords if target isnt' N/A
+ self.status = status # ACTIVE | INACTIVE
+
+ def setTarget(self, clue_name):
+ self.target = clue_name
+
+ def ping(self):
+ if self.status != "ACTIVE":
+ updateRoutes()
+ self.status = "ACTIVE"
+ self.last_contact = time.time()
+
+ def checkStatus(self):
+ if time.time() - self.last_contact > BIKE_TIMEOUT:
+ self.status = "INACTIVE"
+ self.target = "N/A"
+ if time.time() - self.last_contact > BIKE_DELETE:
+ return -1
+ return 0
+
+ def toJSON(self):
+ json_dict = {'longitude' : self.longitude,
+ 'latitude' : self.latitude,
+ 'time_since_last_contact' : time.time()-self.last_contact,
+ 'team_name' : self.name,
+ 'team_status' : self.status,
+ 'target_clue' : self.target}
+ return json_dict \ No newline at end of file