diff options
Diffstat (limited to 'dashboard_website/datastructs.py')
| -rw-r--r-- | dashboard_website/datastructs.py | 55 |
1 files changed, 46 insertions, 9 deletions
diff --git a/dashboard_website/datastructs.py b/dashboard_website/datastructs.py index 6870521..6966ca9 100644 --- a/dashboard_website/datastructs.py +++ b/dashboard_website/datastructs.py @@ -1,7 +1,7 @@ -import time +import time, math # time since last ping before deactivating/deleting -BIKE_TIMEOUT = 60 -BIKE_DELETE = 1800 # time before bike deletes itself +BIKE_TIMEOUT = 10 # 3 minutes +BIKE_DELETE = 20 # time before bike deletes itself # data structures class Point: @@ -24,6 +24,21 @@ class Point: def __str__(self): return f"{self.longitude},{self.latitude}" + + def __repr__(self): + return f"{self.longitude},{self.latitude}" + + def distanceTo(self, pt): # distance between points in miles + lat1 = self.latitude; lon1 = self.longitude; + lat2 = pt.latitude; lon2 = pt.longitude; + R = 3958.8 # Radius of the earth + lat_d = math.radians(lat2-lat1); + lon_d = math.radians(lon2-lon1); + a = math.sin(dLat/2) * math.sin(dLat/2) + math.cos(radians(lat1)) * math.cos(radians(lat2)) * math.sin(dLon/2) * math.sin(dLon/2) + c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a)); + d = R * c; # Distance in mi + return d + class Clue(Point): def __init__(self, lat, long, name, info, status): @@ -50,19 +65,41 @@ class Bike(Point): 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.target_name = "N/A" + self.cluster = [] # list of clues this bike team is responsible for self.status = status # ACTIVE | INACTIVE def setTarget(self, clue_name): - self.target = clue_name + self.target_name = clue_name + + def setCluster(self, clue_cluster): + self.cluster = clue_cluster + self.updateTarget() + + def updateTarget(self): + if len(self.cluster) <= 0: + self.target_name = "N/A" + else: + self.target_name = self.cluster[0].name + + def visitTarget(self): + self.cluster[0].visit() + self.cluster.pop(0) + self.updateTarget() + while len(self.cluster) > 0 and cluster[0].status == "VISITED": + self.cluster.pop(0) # skip next node if it has been somehow visited + self.updateTarget() + def ping(self): - if self.status != "ACTIVE": - updateRoutes() self.status = "ACTIVE" self.last_contact = time.time() + def disable(self): + self.status = "INACTIVE" + self.target = "N/A" + self.last_contact = 0 + def checkStatus(self): if time.time() - self.last_contact > BIKE_TIMEOUT: self.status = "INACTIVE" @@ -77,5 +114,5 @@ class Bike(Point): 'time_since_last_contact' : time.time()-self.last_contact, 'team_name' : self.name, 'team_status' : self.status, - 'target_clue' : self.target} + 'target_clue' : self.target_name} return json_dict
\ No newline at end of file |
