diff options
Diffstat (limited to 'dashboard_website/dashboard.py')
| -rw-r--r-- | dashboard_website/dashboard.py | 89 |
1 files changed, 59 insertions, 30 deletions
diff --git a/dashboard_website/dashboard.py b/dashboard_website/dashboard.py index 8ec53e0..77832aa 100644 --- a/dashboard_website/dashboard.py +++ b/dashboard_website/dashboard.py @@ -19,25 +19,17 @@ app = Flask(__name__) # responds with your next route @app.route("/enableTeam", methods=['POST']) # Expected JSON -# {"team_name" : "XXXX", str -# "longitude" : xx.xxxxxx, float //current team location -# "latitude" : xx.xxxxxx, float } +# {"team_index" : 1,2,3,4; int } # Returns JSON # {"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(): content = request.get_json() - if not ('team_name' in content and 'longitude' in content and 'latitude' in content): + if not ('team_index' 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}) + db.setBikeEnabled(content['team_index'], True) return jsonify({'status' : "OK"}) @@ -45,26 +37,24 @@ def enableTeam(): # responds with your next route @app.route("/disableTeam", methods=['POST']) # Expected JSON -# {"team_name" : "XXXX", str } +# {"team_index" : 1,2,3,4; int } # Returns JSON # {"status" : "OK"/"ERROR XX", str } # ERROR CODES: 1 = missing fields, 4 = team does not exist, def disableTeam(): content = request.get_json() - if not ('team_name' in content): + if not ('team_index' in content): status = "ERROR 1" return jsonify({'status' : status}) - if db.deleteBike(content['team_name']) == 4: - status = "ERROR 4" - return jsonify({'status' : status}) + db.setBikeEnabled(content['team_index'], False) return jsonify({'status' : "OK"}) # requests a route to the best clue given the team's current coordinates @app.route("/requestRoute", methods=['POST']) # Expected JSON -# {"team_name" : "XXXX", str +# {"team_index" : 1,2,3,4; int # "longitude" : xx.xxxxxx, float //current team location # "latitude" : xx.xxxxxx, float } # Returns JSON @@ -78,19 +68,19 @@ def disableTeam(): def requestRoute(): content = request.get_json() # verify request - if not ('team_name' in content and 'longitude' in content and 'latitude' in content): + if not ('team_index' 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: + if db.pingBike(content['team_index'], 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']) + bike, clue = db.getBikeCluePair(content['team_index']) if clue == None: return jsonify({'status' : "ERROR 5"}) @@ -111,7 +101,7 @@ def requestRoute(): # periodically called to update team location in the management dashboard @app.route("/updateTeamLocation", methods=['POST']) # Expected JSON -# {"team_name" : "XXXX", str +# {"team_index" : 1,2,3,4; int # "longitude" : xx.xxxxxx, float # "latitude" : xx.xxxxxx, float } # Returns JSON @@ -120,7 +110,7 @@ def requestRoute(): def updateTeamLocation(): status = "OK" content = request.get_json() - if not ('team_name' in content and 'longitude' in content and 'latitude' in content): + if not ('team_index' in content and 'longitude' in content and 'latitude' in content): status = "ERROR 1" return jsonify({'status' : status}) @@ -128,16 +118,30 @@ def updateTeamLocation(): status = "ERROR 2" return jsonify({'status' : status}) - if db.pingBike(content['team_name'], content['latitude'], content['longitude']) == 4: + if db.pingBike(content['team_index'], content['latitude'], content['longitude']) == 4: status = "ERROR 4" return jsonify({'status' : status}) return jsonify({'status' : "OK"}) +# from website +# {"team_name"} +@app.route("/updateTeamDeadline", methods=['POST']) +def updateTeamDeadline(): + content = request.get_json() + if not ('team_index' in content and 'new_deadline' in content): + status = "ERROR 1" + return jsonify({'status' : status}) + db.setBikeDeadline(content['team_index'], content['new_deadline']) + return jsonify({'status' : "OK"}) + + + + # mark clue as visited from app @app.route("/visitClueTeam", methods=['POST']) # Expected JSON -# {"team_name" : xxxx, str +# {"team_index" : 1,2,3,4; int # "clue_name" : xxxx, str # "longitude" : xx.xxxxxx, float # "latitude" : xx.xxxxxx, float } @@ -146,17 +150,17 @@ def updateTeamLocation(): # 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): + if not ('team_index' 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: + if db.pingBike(content['team_index'], content['latitude'], content['longitude']) == 4: return jsonify({'status' : "ERROR 4"}) - result = db.visitClueTeam(content['team_name'], content['clue_name']) + result = db.visitClueTeam(content['team_index'], content['clue_name']) if result != 0: return jsonify({'status' : f"ERROR {result}"}) return jsonify({'status' : "OK"}) @@ -212,13 +216,29 @@ def requireClue(): def enableClueToggle(): content = request.get_json() if not ('clue_name' in content): - return jsonify({'status' : "ERROR 1"}) + return jsonify({'status' : "ERROR: NO CLUE PROVIDED"}) result = db.toggleEnableClue(content['clue_name']) if result != 0: return jsonify({'status' : f"ERROR {result}"}) return jsonify({'status' : "OK"}) +@app.route("/setClueTeam", methods=['POST']) +# Expected JSON +# {"clue_name" : xxxx, str, +# "bike_team" : 0-4, int} +# Returns JSON +# {"status" : "OK"/"ERROR XX" } +def setClueTeam(): + content = request.get_json() + print("setting clue team", content) + if not ('clue_name' in content and 'bike_team' in content): + return jsonify({'status' : "ERROR: NO CLUE AND/OR TEAM PROVIDED"}) + result = db.assignClueToTeam(content['clue_name'], content['bike_team']) + if result != 0: + return jsonify({'status' : "ERROR: CLUE NOT FOUND"}) + return jsonify({'status' : "OK"}) + # # WEB / DASHBOARD API # @@ -236,7 +256,8 @@ def getLatestInfo(): data = {'timestamp' : db.getTime(), 'clues_changed' : False, 'home_changed' : False, - 'routes_changed' : False} + 'routes_changed' : False, + 'route_update_staged' : db.is_route_update_required() } cl = db.getCluesJSON(last_timestamp) if cl != False: data['clues_changed'] = True @@ -262,7 +283,7 @@ def addClueWeb(): print("adding clue:", content) if not ('clue_name' in content and 'longitude' in content and 'latitude' in content and 'clue_info' in content): return jsonify({'status' : "ERROR: INVALID CLUE JSON FORMAT"}) - res = db.addClue(content['clue_name'], content['clue_info'], content['latitude'], content['longitude']) + res = db.addClue(content['clue_name'], content['clue_info'], content['longitude'], content['latitude']) if res == 0: return jsonify({'status' : "OK",}) elif res == -1: @@ -300,6 +321,14 @@ def siteControls(): if db.load("clean.csv") != 0: return jsonify({"status" : "ERROR"}) return jsonify({"status" : "OK"}) + elif cmd == "setHome": + if db.setHomeBase(request.form.get('latitude'), request.form.get('longitude')) != 0: + return jsonify({"status" : "ERROR"}) + return jsonify({"status" : "OK"}) + elif cmd == "generateRoutes": + if db.updateRoutes() != 0: + return jsonify({"status" : "ERROR"}) + return jsonify({"status" : "OK"}) return render_template("controls.html") |
