From 84cd1770bca064998521cb5f44ddb309d9b5247b Mon Sep 17 00:00:00 2001 From: itsGarrin Date: Tue, 2 Jul 2024 13:05:29 -0700 Subject: reformatted code --- dashboard_website/dashboard.py | 2 +- dashboard_website/datastructs.py | 89 ++++++++++++++++++++++------------------ dashboard_website/router.py | 1 - 3 files changed, 50 insertions(+), 42 deletions(-) diff --git a/dashboard_website/dashboard.py b/dashboard_website/dashboard.py index b9b8bbc..ed2dffa 100644 --- a/dashboard_website/dashboard.py +++ b/dashboard_website/dashboard.py @@ -3,7 +3,7 @@ # dashboard.py contains web interface to clue DB + router # -from flask import Flask, flash, request, redirect, render_template, send_from_directory, jsonify +from flask import Flask, request, render_template, send_from_directory, jsonify import db import router diff --git a/dashboard_website/datastructs.py b/dashboard_website/datastructs.py index 0171d8f..4648fee 100644 --- a/dashboard_website/datastructs.py +++ b/dashboard_website/datastructs.py @@ -2,20 +2,20 @@ import math import time # time since last ping before deactivating/deleting -BIKE_TIMEOUT = 60000 # 3 minutes -BIKE_DELETE = 360000 # time before bike deletes itself +BIKE_TIMEOUT = 60000 # 3 minutes +BIKE_DELETE = 360000 # 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} + json_dict = {"longitude": self.longitude, "latitude": self.latitude} return json_dict - + def setCoords(self, lat, long): self.longitude = long self.latitude = lat @@ -26,19 +26,24 @@ 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(lat_d/2) * math.sin(lat_d/2) + math.cos(math.radians(lat1)) * math.cos(math.radians(lat2)) * math.sin(lon_d/2) * math.sin(lon_d/2) - c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a)); - d = R * c; # Distance in mi + + 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(lat_d / 2) * math.sin(lat_d / 2) + math.cos( + math.radians(lat1) + ) * math.cos(math.radians(lat2)) * math.sin(lon_d / 2) * math.sin(lon_d / 2) + c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a)) + d = R * c + # Distance in mi return d @@ -48,19 +53,22 @@ class Clue(Point): self.latitude = lat self.name = name self.info = info - self.status = status # UNVISITED | ASSIGNED | VISITED - + 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} + 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 @@ -68,35 +76,34 @@ class Bike(Point): self.name = name self.last_contact = time.time() self.target_name = "N/A" - self.cluster = [] # list of clues this bike team is responsible for - self.status = status # ACTIVE | INACTIVE - + self.cluster = [] # list of clues this bike team is responsible for + self.status = status # ACTIVE | INACTIVE + def setTarget(self, 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 self.cluster[0].status == "VISITED": - self.cluster.pop(0) # skip next node if it has been somehow visited + self.cluster.pop(0) # skip next node if it has been somehow visited self.updateTarget() - def ping(self): self.status = "ACTIVE" self.last_contact = time.time() - + def disable(self): self.status = "INACTIVE" self.target = "N/A" @@ -111,10 +118,12 @@ class Bike(Point): 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_name} - return json_dict \ No newline at end of file + 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_name, + } + return json_dict diff --git a/dashboard_website/router.py b/dashboard_website/router.py index e3784d3..8f73c99 100644 --- a/dashboard_website/router.py +++ b/dashboard_website/router.py @@ -1,5 +1,4 @@ import datetime -import time import numpy as np import requests -- cgit v1.2.3