-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
95 lines (69 loc) · 2.33 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
from flask import Flask, render_template, request, jsonify, Response, abort
import io
from src import data, config, sample
app = Flask(__name__)
# TODO: modify README
@app.route('/')
def index():
return render_template("index.html", **config.CONFIG['Wording'])
@app.route('/help')
def help():
# TODO: replace video and text
return render_template("help.html", **config.CONFIG['Wording'])
@app.route('/test')
def test():
return get_experiment(request.path)
@app.route('/experiment')
def experiment():
return get_experiment(request.path)
@app.route('/results.png')
def get_visualization():
# https://stackoverflow.com/questions/50728328
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
fig = data.visualize()
if not fig:
abort(404)
output = io.BytesIO()
FigureCanvas(fig).print_png(output)
return Response(output.getvalue(), mimetype='image/png')
@app.route('/literature.png')
def get_literature_plot():
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
fig = data.literature_replot()
output = io.BytesIO()
FigureCanvas(fig).print_png(output)
return Response(output.getvalue(), mimetype='image/png')
@app.route('/all_local_results.png')
def get_local_plot():
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
fig = data.plot_all_local_results()
output = io.BytesIO()
FigureCanvas(fig).print_png(output)
return Response(output.getvalue(), mimetype='image/png')
@app.route('/api/results', methods = ['POST'])
def results():
# TODO: add plot
exp_results = data.get_results()
if 'experiment' in request.get_data().decode():
data.record_to_file(exp_results)
return render_template(
"results.html", **config.CONFIG['Wording'],
show_results=data.format_results(exp_results)
)
@app.route('/api/sample', methods = ['POST'])
def get_sample():
data.update(request.get_data())
return jsonify(sample.get_sample())
@app.route('/api/config')
def get_config():
return jsonify(config.CONFIG)
def get_experiment(path):
data.clear()
sample.reset(path)
return render_template(
"experiment.html",
exp_title=config.CONFIG['Wording'][path[1:]],
**config.CONFIG['Wording']
)
if __name__ == '__main__':
app.run()