summaryrefslogtreecommitdiff
path: root/dashboard_website/dashboard.py
blob: 9ccad9f9d631d5ba66f49692637707b75050f89c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#
# hosts dashboard webpage on flask 
# dashboard.py contains web interface to clue DB + router
#  

from flask import Flask, flash, request, redirect, render_template, send_from_directory, jsonify
import db, router

app = Flask(__name__)

#
# BIKE APP API
#
# called by making a post request to hh.acetyl.net/<commandname> with expected JSON attached

# enable eligibility to receive routes. can be disabled either in app or on dashboard, so before a trip must be re-enabled.
# 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 }
# 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
def enableTeam():
    pass

# 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 }
# 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
def disableTeam():
    pass

# requests a route to the best clue given the team's current coordinates
@app.route("/requestRoute", methods=['POST'])
# Expected JSON
# {"team_name" : "XXXX", str
#  "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, 5 = could not find route, 10 = other/network error
def requestRoute():
    pass

# periodically called to update team location in the management dashboard
@app.route("/updateTeamLocation", methods=['POST'])
# Expected JSON
# {"team_name" : "XXXX", str
#  "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
def updateTeamLocation():
    content = request.get_json()
    db.pingBike(content['team_name'], content['latitude'], content['longitude'])
    return jsonify({'team_name' : content['team_name'], 'status' : "OK"})

#
# WEB PAGES + DASHBOARD API
#

# send updated bike/clue/home info
# POST = request above
@app.route("/getLatestInfo", methods=['POST'])
def getLatestInfo():
    db.moveBike2Test()
    content = request.get_json()
    last_timestamp = content['info_age']
    data = {'timestamp' : db.getTime(),
            'clues_changed' : False,
            'home_changed' : False}
    cl = db.getCluesJSON(last_timestamp)
    if cl != False:
        data['clues_changed'] = True
        data['clues'] = cl
    h = db.getHomeBaseJSON(last_timestamp)
    if h != False:
        data['home_changed'] = True
        data['homebase'] = h
    data['bikes'] = db.getBikesJSON()
    data['status'] = "OK"

    return jsonify(data)


# main page
# GET = get main page
@app.route("/", methods=['GET'])
def siteIndex():
    #clues = db.getClues(); bikes = db.getBikes()
    return render_template("index.html")#, clues=clues, bikes=bikes)



if __name__ == "__main__":
    app.config['SESSION_TYPE'] = 'filesystem'
    app.secret_key = 'hf8f3sd0zmqpmhss7dr3'

    # local test
    app.run(host="127.0.0.1", port=5001, debug=True)
    # production
    #app.run(host="96.126.106.128", port=5001, debug=True)