summaryrefslogtreecommitdiff
path: root/dashboard_website/dashboard.py
diff options
context:
space:
mode:
authorAnson Bridges <bridges.anson@gmail.com>2023-11-10 16:46:09 -0500
committerAnson Bridges <bridges.anson@gmail.com>2023-11-10 16:46:09 -0500
commita3db30e2a06685aa2976ac8062040b4657109523 (patch)
tree0611c4ea4d36403969051799b69af5ef8a4a31e0 /dashboard_website/dashboard.py
parent0e5d5ea7b26e55a6b83a10c53eada788d87428c2 (diff)
ROUGH DRAFT
Diffstat (limited to 'dashboard_website/dashboard.py')
-rw-r--r--dashboard_website/dashboard.py160
1 files changed, 131 insertions, 29 deletions
diff --git a/dashboard_website/dashboard.py b/dashboard_website/dashboard.py
index 59fa0df..aab38b0 100644
--- a/dashboard_website/dashboard.py
+++ b/dashboard_website/dashboard.py
@@ -21,30 +21,43 @@ app = Flask(__name__)
# "longitude" : xx.xxxxxx, float //current team location
# "latitude" : xx.xxxxxx, float }
# Returns JSON
-# {"team_name" : "XXXX", str
-# "status" : "OK"/"ERROR XX", str
-# "clue_name" : "XXXX", str
-# "clue_long" : xx.xxxxxx, float
-# "clue_lat" : xx.xxxxxx, float
-# "clue_info" : "Xxxx xxx xxx", str
-# "route" : {...}, JSON } expect something like: http://acetyl.net:5000/route/v1/bike/-71.0553792,42.3688272;-71.0688746,42.3576234 without the waypoints section
-# ERROR CODES: 1 = missing fields, 2 = invalid field types, 3 = invalid coordinates, 4 = team does not exist, 5 = could not find route, 10 = other/network error
+# {"status" : "OK"/"ERROR XX", str } expect something like: http://acetyl.net:5000/route/v1/bike/-71.0553792,42.3688272;-71.0688746,42.3576234 without the waypoints section
+# ERROR CODES: 1 = missing fields, 2 = invalid coordinates, 4 = team ALREADY exists,
def enableTeam():
- pass
+ content = request.get_json()
+ if not ('team_name' in content and 'longitude' in content and 'latitude' in content):
+ status = "ERROR 1"
+ return jsonify({'status' : status})
+
+ if not ( (type(content['longitude']) is float ) and (type(content['latitude']) is float )):
+ status = "ERROR 2"
+ return jsonify({'status' : status})
+
+ if db.addBike(content['team_name'], content['latitude'], content['longitude']) == 4:
+ status = "ERROR 4"
+ return jsonify({'status' : status})
+
+ return jsonify({'status' : "OK"})
# disable eligibility to receive routes, e.g. if team is done while another is not. can be re-enabled either in app or on dashboard
# responds with your next route
@app.route("/disableTeam", methods=['POST'])
# Expected JSON
-# {"team_name" : "XXXX", str
-# "longitude" : xx.xxxxxx, float //current team location
-# "latitude" : xx.xxxxxx, float }
+# {"team_name" : "XXXX", str }
# Returns JSON
-# {"team_name" : "XXXX", str
-# "status" : "OK"/"ERROR XX", str }
-# ERROR CODES: 1 = missing fields, 2 = invalid field types, 3 = invalid coordinates, 4 = team does not exist, 10 = other/network error
+# {"status" : "OK"/"ERROR XX", str }
+# ERROR CODES: 1 = missing fields, 4 = team does not exist,
def disableTeam():
- pass
+ content = request.get_json()
+ if not ('team_name' in content):
+ status = "ERROR 1"
+ return jsonify({'status' : status})
+
+ if db.deleteBike(content['team_name']) == 4:
+ status = "ERROR 4"
+ return jsonify({'status' : status})
+
+ return jsonify({'status' : "OK"})
# requests a route to the best clue given the team's current coordinates
@app.route("/requestRoute", methods=['POST'])
@@ -53,16 +66,43 @@ def disableTeam():
# "longitude" : xx.xxxxxx, float //current team location
# "latitude" : xx.xxxxxx, float }
# Returns JSON
-# {"team_name" : "XXXX", str
-# "status" : "OK"/"ERROR XX", str
+# {"status" : "OK"/"ERROR XX", str
# "clue_name" : "XXXX", str
# "clue_long" : xx.xxxxxx, float
# "clue_lat" : xx.xxxxxx, float
# "clue_info" : "Xxxx xxx xxx", str
# "route" : {...}, JSON } expect something like: http://acetyl.net:5000/route/v1/bike/-71.0553792,42.3688272;-71.0688746,42.3576234 without the waypoints section
-# ERROR CODES: 1 = missing fields, 2 = invalid field types, 3 = invalid coordinates, 5 = could not find route, 10 = other/network error
+# ERROR CODES: 1 = missing fields, 2 = invalid coordinates, 3 = cluster calculation in progress, 4 = team not found, 5 = no more clues, 6 = routing error
def requestRoute():
- pass
+ content = request.get_json()
+ # verify request
+ if not ('team_name' in content and 'longitude' in content and 'latitude' in content):
+ return jsonify({'status' : "ERROR 1"})
+
+ if not ( (type(content['longitude']) is float ) and (type(content['latitude']) is float)):
+ return jsonify({'status' : "ERROR 2"})
+
+ if db.pingBike(content['team_name'], content['latitude'], content['longitude']) == 4:
+ return jsonify({'status' : "ERROR 4"})
+
+ if db.currently_updating:
+ return jsonify({'status' : "ERROR 3"})
+
+ bike, clue = db.getBikeCluePair(content['team_name'])
+ if clue == None:
+ return jsonify({'status' : "ERROR 5"})
+
+ route = getRouteFullJSON(bike, clue)
+ if route['code'] != 'Ok': # or some other code indicating routing problem?
+ return jsonify({'status' : "ERROR 6"})
+
+ reply = {"status" : "OK",
+ "clue_name" : clue.name,
+ "clue_long" : clue.longitude,
+ "clue_lat" : clue.latitude,
+ "clue_info" : clue.info,
+ "route" : route}
+ return jsonify(reply)
# periodically called to update team location in the management dashboard
@app.route("/updateTeamLocation", methods=['POST'])
@@ -71,23 +111,83 @@ def requestRoute():
# "longitude" : xx.xxxxxx, float
# "latitude" : xx.xxxxxx, float }
# Returns JSON
-# {"team_name" : "XXXX", str
-# "status" : "OK"/"ERROR XX" }
-# ERROR CODES: 1 = missing fields, 2 = invalid field types, 3 = invalid coordinates, 10 = other/network error
+# {"status" : "OK"/"ERROR XX" }
+# ERROR CODES: 1 = missing fields, 2 = invalid coordinates, 4 = no active team found under given name,
def updateTeamLocation():
+ status = "OK"
content = request.get_json()
- db.pingBike(content['team_name'], content['latitude'], content['longitude'])
- return jsonify({'team_name' : content['team_name'], 'status' : "OK"})
+ if not ('team_name' in content and 'longitude' in content and 'latitude' in content):
+ status = "ERROR 1"
+ return jsonify({'status' : status})
+
+ if not ( (type(content['longitude']) is float ) and (type(content['latitude']) is float)):
+ status = "ERROR 2"
+ return jsonify({'status' : status})
+
+ if db.pingBike(content['team_name'], content['latitude'], content['longitude']) == 4:
+ status = "ERROR 4"
+ return jsonify({'status' : status})
+
+ return jsonify({'status' : "OK"})
+
+# mark clue as visited from app
+@app.route("/visitClueTeam", methods=['POST'])
+# Expected JSON
+# {"team_name" : xxxx, str
+# "clue_name" : xxxx, str
+# "longitude" : xx.xxxxxx, float
+# "latitude" : xx.xxxxxx, float }
+# Returns JSON
+# {"status" : "OK"/"ERROR XX" }
+# ERROR CODES: 1 = missing fields, 2 = invalid coordinates, 3 = too far from clue location, 4 = no such team, 5 = no such clue, 6 = already visited
+def visitTeam():
+ content = request.get_json()
+ if not ('team_name' in content and 'longitude' in content and 'latitude' in content and 'clue_name' in content):
+ return jsonify({'status' : "ERROR 1"})
+
+ if not ( (type(content['longitude']) is float ) and (type(content['latitude']) is float)):
+ status = "ERROR 2"
+ return jsonify({'status' : status})
+
+ if db.pingBike(content['team_name'], content['latitude'], content['longitude']) == 4:
+ return jsonify({'status' : "ERROR 4"})
+
+ result = db.visitClueTeam(content['team_name'], content['clue_name'])
+ if result != 0:
+ return jsonify({'status' : f"ERROR {result}"})
+ return jsonify({'status' : "OK"})
+
+#
+# DISCORD BOT API
+#
+@app.route("/visitClueGeneric", methods=['POST'])
+# Expected JSON
+# {"clue_name" : xxxx, str}
+# Returns JSON
+# {"status" : "OK"/"ERROR XX" }
+# ERROR CODES: 1 = missing fields, 2 = clue doesn't exist, 3 = already marked as visited
+def visitGeneric():
+ content = request.get_json()
+ if not ('clue_name' in content):
+ return jsonify({'status' : "ERROR 1"})
+
+ result = db.visitClue(content['clue_name'])
+ if result != 0:
+ return jsonify({'status' : f"ERROR {result}"})
+ return jsonify({'status' : "OK"})
#
-# WEB PAGES + DASHBOARD API
+# WEB / DASHBOARD API
#
# send updated bike/clue/home info
# POST = request above
@app.route("/getLatestInfo", methods=['POST'])
def getLatestInfo():
- db.moveBike2Test()
+ # run first update
+ if db.startup == False:
+ db.startup = True
+ db.updateRoutes()
content = request.get_json()
last_timestamp = content['info_age']
data = {'timestamp' : db.getTime(),
@@ -106,8 +206,10 @@ def getLatestInfo():
if r != False:
data['routes_changed'] = True
data['routes'] = r
+ data['calculating_routes'] = db.currently_updating
data['bikes'] = db.getBikesJSON()
data['status'] = "OK"
+
return jsonify(data)
@@ -126,6 +228,6 @@ if __name__ == "__main__":
app.secret_key = 'hf8f3sd0zmqpmhss7dr3'
# local test
- app.run(host="127.0.0.1", port=5001, debug=True)
+ #app.run(host="127.0.0.1", port=5001, debug=True)
# production
- #app.run(host="96.126.106.128", port=5001, debug=True)
+ app.run(host="96.126.106.128", port=5001, debug=True)