-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
129 lines (92 loc) · 2.84 KB
/
app.py
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
127
128
129
from flask import Flask, render_template, request, jsonify, after_this_request
from threading import Thread
import glob
import os
from decoder import settings
import decoder
import algconsecutivematches
import plot
app = Flask(__name__)
@app.route("/")
def main():
# Pass the settings data into the template main.html and return it to the user
return render_template('cariddecoder_main.html', **settings)
@app.route("/record/on")
def recordOn():
global settings
settings["record"] = True
print(settings["record"])
return "OK"
@app.route("/record/off")
def recordOff():
global settings
settings["record"] = False
print(settings["record"])
return "OK"
@app.route("/carid/<carId>")
def setCarId(carId):
global settings
settings["carId"] = carId
print(settings["carId"])
return "OK"
@app.route("/chip/<chip>")
def setChip(chip):
global settings
settings["chip"] = chip
print(settings["chip"])
return "OK"
@app.route("/firmware/<firmware>")
def setFirmware(firmware):
global settings
settings["firmware"] = firmware
print(settings["firmware"])
return "OK"
@app.route("/tests")
def tests():
print("run tests")
return render_template('test1.html', **model)
# python graph generation is DEPRECATED
@app.route("/plot/latest")
def showGraph():
plotPngs = glob.glob('static/plot-*.png') #doesn't check specifically for images in the static folder
latestPlot = '/' + max(plotPngs, key=os.path.getctime)
print("=== " + latestPlot + " ===")
model = {
"ploturl" : latestPlot
}
# TODO: add "Refresh" button to plot.html
# TODO: show the generated date time on the page (get it from the png filename)
return render_template('/plot.html', **model)
# used?
@app.route("/plot/refresh")
def newPlot():
plot.generate()
# TODO: redirect to /plot/latest would be better
return showGraph()
@app.route("/plot/d3")
def d3Plot():
model = {
"somedata" : ""
}
return render_template('/d3.html', **model)
# to be DEPRECATED
@app.route("/data/all")
def allData():
d = plot.getAllData()
return jsonify(d)
@app.route("/data/cacheall")
def cacheAllData():
# (for now) do all this in plot.py (rename it later)
cachedFilename = plot.getCachedFilename(longAgo, farFuture)
return cachedFilename
# Flask
@app.before_first_request
def do_something_only_once():
pass
if __name__ == "__main__":
thread = Thread(target = decoder.saveData, args = ())
thread.start()
print("main thread READY!")
# run Flask webserver
# debug=False prevents code firing twice (problematic for the saveData thread)
app.run(host='0.0.0.0', port=8081, debug=False)