-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathflask_app.py
More file actions
97 lines (71 loc) · 3.26 KB
/
Copy pathflask_app.py
File metadata and controls
97 lines (71 loc) · 3.26 KB
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
from flask import Flask, escape, request, render_template, jsonify
import numpy as np
import json
import os
import matplotlib
import simulation
matplotlib.use('Agg')
import matplotlib.pyplot as plt
app = Flask(__name__, static_url_path='', static_folder='static')
raw_data=[]
@app.route('/')
def main():
return render_template("main.html")
@app.route('/symulacja')
def symulacja():
return render_template("symulacja.html")
@app.route('/iss_go', methods=['GET', 'POST'])
def iss_go():
global raw_data
if request.method == 'POST':
content_dict = json.loads(request.data)
print(content_dict)
if content_dict['start_level'] != "":
raw_data = simulation.launch_simulation(float(content_dict['start_level']),
float(content_dict['min_level']),
float(content_dict['max_level']),
float(content_dict['area']),
int(content_dict['start_temp']),
int(content_dict['target_temp']),
# int(content_dict['max_temp_error']),
int(content_dict['max_heater_power']),
int(content_dict['input_temp']),
float(content_dict['max_input']),
float(content_dict['max_output']),
# float(content_dict['start_in_valve_status']),
# float(content_dict['start_out_valve_status']),
int(content_dict['sim_time']),
content_dict['controller'],
content_dict["pid_params"])
response = {"code": 0, "message": "img prepared"}
else:
response = {"code": 1, "message": "bad_value"}
return jsonify(response)
@app.route('/get_plot', methods=['GET', 'POST'])
def get_plot():
content_dict = json.loads(request.data)
data = raw_data[str(content_dict[0]["values_to_plot"])]
len_of_data = len(data)
t = np.arange(0, len_of_data, 1)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
#print(content_dict)
for plot in content_dict:
print("ok")
data = raw_data[str(plot["values_to_plot"])]
plot_color= str(plot["color_for_plot"])
ax.plot(t, data, color=plot_color)
plt.xlabel('time')
plt.ylabel("value")
plt.xticks(np.arange(0, len_of_data + 1, len_of_data / 20))
plt.grid(True)
try:
os.remove("static/plot.png")
except:
print("an exception occurred: file does not exist")
fig.set_size_inches(14, 4)
fig.savefig('static/plot.png')
response = {"code": 0, "message": "img prepared"}
return jsonify(response)
if __name__ == '__main__':
app.run(debug=True)