-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
155 lines (121 loc) · 4.03 KB
/
Copy pathmain.py
File metadata and controls
155 lines (121 loc) · 4.03 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
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# -*- coding: utf-8 -*-
from flask import Flask
from flask import render_template
from flask import request
from flask import Response
import numpy as np
import io
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure
import matplotlib.pyplot as plt
import back
app = Flask(__name__)
app.secret_key = 'some_secret'
@app.route('/')
@app.route('/index')
def index():
return render_template('index.html', title='Home', nav_item="Главная")
@app.context_processor
def utility_processor():
def is_active(item_name, current_name):
return "active" if item_name == current_name else ""
return dict(is_active=is_active)
@app.route('/map')
def map():
return render_template('map.html', title='Map', nav_item="Карта")
@app.route('/analytics')
def analytics():
return render_template('analytics.html', title='Analytics', nav_item="Аналитика", listPoints=back.get_points())
@app.route('/whatitis')
def what_it_is():
return render_template('whatitis.html')
@app.route('/hwwt')
def hwwt():
return render_template('hwwt.html')
@app.route('/faq')
def faq():
return render_template('FAQ.html')
@app.route('/specVal')
def special_value():
ID = request.args.get('ID')
return render_template('specVal.html', listPointsValue=back.get_measurements_by_id(str(ID)), date=back.get_date())
@app.route('/graphics')
def graphics():
ID = request.args.get('ID')
return render_template('graphics.html', ID=ID)
@app.route('/plot.png')
def plot_png():
ID = request.args.get('ID')
fig = create_figure(ID)
output = io.BytesIO()
FigureCanvas(fig).print_png(output)
return Response(output.getvalue(), mimetype='image/png')
def create_figure(ID):
listPointsValue = back.get_measurements_by_id(str(ID))[0]
fig = Figure()
axis = fig.add_subplot(1, 1, 1)
xs = []
yh = []
yt = []
ya = []
for pv in listPointsValue:
xs.append(pv[0])
yh.append(pv[1][0])
yt.append(pv[1][1])
ya.append(pv[1][2])
axis.plot(xs, yh, "-b", label="Влажность")
axis.plot(xs, yt, "-r", label="Температура")
axis.plot(xs, ya, "-g", label="Кислотность")
plt.xticks(xs, " ")
axis.legend(loc="upper left")
return fig
@app.route('/glob_graphic')
def glob_graphic():
return render_template('glob_graphic.html')
@app.route('/plot_mid.png')
def plot_mid_png():
fig = create_mid_figure()
output = io.BytesIO()
FigureCanvas(fig).print_png(output)
return Response(output.getvalue(), mimetype='image/png')
def create_mid_figure():
listPointsValue = back.get_mid_value()
fig = Figure()
axis = fig.add_subplot(1, 1, 1)
xs = []
yh = []
yt = []
ya = []
for i in range(30):
xs.append(listPointsValue[1][i])
yh.append(listPointsValue[0][i][0])
yt.append(listPointsValue[0][i][1])
ya.append(listPointsValue[0][i][2])
axis.plot(xs, yh, "-b", label="Влажность")
axis.plot(xs, yt, "-r", label="Температура")
axis.plot(xs, ya, "-g", label="Кислотность")
plt.xticks(xs, " ")
axis.legend(loc="upper left")
return fig
@app.route('/field.png')
def field_png():
fig = create_field_figure()
output = io.BytesIO()
FigureCanvas(fig).print_png(output)
return Response(output.getvalue(), mimetype='image/png')
def create_field_figure():
BBox = (38.473225, 38.490792, 54.785954, 54.795505)
tud = back.get_tud()
longitudes = tud[0]
latitudes = tud[1]
fig, ax = plt.subplots(figsize=(12, 6))
field_img = plt.imread('./static/field.png')
ax.scatter(longitudes, latitudes, zorder=1, marker='^', alpha=1, c='r', s=50)
# ax.set_title('Plotting Spatial Data on Riyadh Map')
ax.set_xlim(BBox[0], BBox[1])
ax.set_ylim(BBox[2], BBox[3])
cur_axes = plt.gca()
cur_axes.axes.get_xaxis().set_visible(False)
cur_axes.axes.get_yaxis().set_visible(False)
ax.imshow(field_img, zorder=0, extent=BBox, aspect='equal')
return fig