diff options
Diffstat (limited to 'dashboard_website/db.py')
| -rw-r--r-- | dashboard_website/db.py | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/dashboard_website/db.py b/dashboard_website/db.py index fc9e992..cda29dc 100644 --- a/dashboard_website/db.py +++ b/dashboard_website/db.py @@ -1,3 +1,72 @@ # stores and manages clue DB # also manages currently available bike teams +import csv +# 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 __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 | 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.status = status # ACTIVE | INACTIVE + + def toJSON(self): + json_dict = {'longitude' : self.longitude, + 'latitude' : self.latitude, + 'team_name' : self.name, + 'team_status' : self.status} + return json_dict + +# variables +homeBase = Point(42.340226, -71.088395) # krentzman, can be changed on dashboard +clues = [] + + + +# interface functions + +def getHomeBaseJSON(): + return homeBase.toJSON() + +def getCluesJSON(): + return [x.toJSON() for x in clues] + +with open("all_clues.csv", newline='') as f: + csvreader = csv.reader(f, delimiter=',', quotechar='"') + i = 1 + for row in csvreader: + coords = row[1].split(",") + coords[0] = float(coords[0]); coords[1] = float(coords[1]); + + newClue = Clue(coords[0], coords[1], f"Clue #{i}", row[0], "UNVISITED" if i < 50 else "VISITED") + clues.append(newClue) + i += 1
\ No newline at end of file |
