forked from digitalocean/sample-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
312 lines (251 loc) · 17.3 KB
/
server.py
File metadata and controls
312 lines (251 loc) · 17.3 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
import io
import time
import threading
import random
import remi.gui as gui
from remi import start, App
from matplotlib.figure import Figure
from matplotlib.backends.backend_agg import FigureCanvasAgg
import sys
from matplotlib import rc
import matplotlib.ticker
from matplotlib.font_manager import FontProperties
import mysql.connector as mysql
from mysql.connector import Error
import matplotlib.dates as md
import numpy as np
import pandas as pd
import datetime as dt
import time
from tkscrolledframe import ScrolledFrame
from tkcalendar import Calendar
from datetime import date
class MyApp(App):
def __init__(self, *args):
super(MyApp, self).__init__(*args)
#def idle(self):
# self.counter.set_text('Running Time: ' + str(self.count))
# self.progress.set_value(self.count%100)
def main(self):
mainContainer = gui.Container(width='100%', margin='0px auto', style={'display': 'block', 'overflow': 'hidden'})
welcomeContainer = gui.Container(width='100%', layout_orientation=gui.Container.LAYOUT_HORIZONTAL, margin='0px auto', style={'display': 'block', 'overflow': 'hidden'})
averagedContainer = gui.Container(width='100%', layout_orientation=gui.Container.LAYOUT_HORIZONTAL, margin='0px auto', style={'display': 'block', 'overflow': 'hidden'})
self.img = gui.Image("c:\\users\\hugo whelan\\desktop\\python\\MOS_Logo_HQ.jpg", height=100, margin='10px')
self.title_lbl = gui.Label('Douglas Park Bridges Monitoring System Data', width='100%', height=30, margin='10px')
self.welcome_lbl = gui.Label('Welcome to the Douglas Park Bridges Monitoring System Database. The page contains daily averaged data and diagnostic information. Full data overviews are shown at the bottom of the page.', width='100%', height=30, margin='10px')
welcomeContainer.append([self.img, self.title_lbl, self.welcome_lbl])
# Average data
self.lbl_avg = gui.Label('Averagd Data', width='100%', height=30, margin='10px')
self.avg_txt = gui.Label('The following section contains the daily averaged data. Please select the dates and sensor(s) you would like to access. All data is relative to time. If you want the unaveraged data, please scroll down to the second section.', width='100%', height=30, margin='10px')
self.start_date = gui.Date(width=200, height=20)
self.end_date = gui.Date(width=200, height=20)
self.check_s_nb_s2w = gui.CheckBoxLabel('S_NB_S2W', False, width=200, height=30)
self.check_s_nb_s2e = gui.CheckBoxLabel('S_NB_S2E', False, width=200, height=30)
self.check_s_nb_s1e = gui.CheckBoxLabel('S_NB_S1E', False, width=200, height=30)
self.check_s_nb_s1w = gui.CheckBoxLabel('S_NB_S1W', False, width=200, height=30)
self.check_t_nb_s2w = gui.CheckBoxLabel('T_NB_S2W', False, width=200, height=30)
self.check_t_nb_s2e = gui.CheckBoxLabel('T_NB_S2E', False, width=200, height=30)
self.check_t_nb_s1e = gui.CheckBoxLabel('T_NB_S1E', False, width=200, height=30)
self.check_t_nb_s1w = gui.CheckBoxLabel('T_NB_S1W', False, width=200, height=30)
self.check_tp_nb_s2w = gui.CheckBoxLabel('TP_NB_S2W', False, width=200, height=30)
self.check_tp_nb_s2e = gui.CheckBoxLabel('TP_NB_S2E', False, width=200, height=30)
self.check_tp_nb_s1e = gui.CheckBoxLabel('TP_NB_S1E', False, width=200, height=30)
self.check_tp_nb_s1w = gui.CheckBoxLabel('TP_NB_S1W', False, width=200, height=30)
self.check_s_sb_s2w = gui.CheckBoxLabel('S_SB_S2W', False, width=200, height=30)
self.check_s_sb_s2e = gui.CheckBoxLabel('S_SB_S2E', False, width=200, height=30)
self.check_s_sb_s1e = gui.CheckBoxLabel('S_SB_S1E', False, width=200, height=30)
self.check_s_sb_s1w = gui.CheckBoxLabel('S_SB_S1W', False, width=200, height=30)
self.check_t_sb_s2w = gui.CheckBoxLabel('T_SB_S2W', False, width=200, height=30)
self.check_t_sb_s2e = gui.CheckBoxLabel('T_SB_S2E', False, width=200, height=30)
self.check_t_sb_s1e = gui.CheckBoxLabel('T_SB_S1E', False, width=200, height=30)
self.check_t_sb_s1w = gui.CheckBoxLabel('T_SB_S1W', False, width=200, height=30)
self.check_tp_sb_s2w = gui.CheckBoxLabel('TP_SB_S2W', False, width=200, height=30)
self.check_tp_sb_s2e = gui.CheckBoxLabel('TP_SB_S2E', False, width=200, height=30)
self.check_tp_sb_s1e = gui.CheckBoxLabel('TP_SB_S1E', False, width=200, height=30)
self.check_tp_sb_s1w = gui.CheckBoxLabel('TP_SB_S1W', False, width=200, height=30)
avg_sensors = [self.check_s_nb_s2w, self.check_s_nb_s2e, self.check_s_nb_s1e,
self.check_s_nb_s1w, self.check_t_nb_s2w, self.check_t_nb_s2e, self.check_t_nb_s1e,
self.check_t_nb_s1w, self.check_tp_nb_s2w, self.check_tp_nb_s2e, self.check_tp_nb_s1e,
self.check_tp_nb_s1w, self.check_s_sb_s2w, self.check_s_sb_s2e, self.check_s_sb_s1e,
self.check_s_sb_s1w, self.check_t_sb_s2w, self.check_t_sb_s2e, self.check_t_sb_s1e,
self.check_t_sb_s1w, self.check_tp_sb_s2w, self.check_tp_sb_s2e, self.check_tp_sb_s1e,
self.check_tp_sb_s1w]
self.go_avg = gui.Button('Go', width=200, height=30, margin='10px')
self.go_avg.onclick.do(self.get_selected_avg)
averagedContainer.append([self.lbl_avg, self.avg_txt, self.start_date, self.end_date, avg_sensors, self.go_avg])
# Unaveraged data
unaveragedContainer = gui.Container(width='100%', layout_orientation=gui.Container.LAYOUT_HORIZONTAL, margin='0px auto', style={'display': 'block', 'overflow': 'hidden'})
self.lbl_unavg = gui.Label('Unaveraged Data', width='100%', height=30, margin='10px')
self.unavg_txt = gui.Label('The following section contains the daily unaveraged data. Please select the dates and sensors(s) you would like to access. All data is relative to time.', width='100%', height=30, margin='10px')
self.start_unavg = gui.Date(width=200, height=20)
self.end_unavg = gui.Date(width=200, height=20)
self.check_s_nb_s2w_unavg = gui.CheckBoxLabel('S_NB_S2W', False, width=200, height=30)
self.check_s_nb_s2e_unavg = gui.CheckBoxLabel('S_NB_S2E', False, width=200, height=30)
self.check_s_nb_s1e_unavg = gui.CheckBoxLabel('S_NB_S1E', False, width=200, height=30)
self.check_s_nb_s1w_unavg = gui.CheckBoxLabel('S_NB_S1W', False, width=200, height=30)
self.check_t_nb_s2w_unavg = gui.CheckBoxLabel('T_NB_S2W', False, width=200, height=30)
self.check_t_nb_s2e_unavg = gui.CheckBoxLabel('T_NB_S2E', False, width=200, height=30)
self.check_t_nb_s1e_unavg = gui.CheckBoxLabel('T_NB_S1E', False, width=200, height=30)
self.check_t_nb_s1w_unavg = gui.CheckBoxLabel('T_NB_S1W', False, width=200, height=30)
self.check_tp_nb_s2w_unavg = gui.CheckBoxLabel('TP_NB_S2W', False, width=200, height=30)
self.check_tp_nb_s2e_unavg = gui.CheckBoxLabel('TP_NB_S2E', False, width=200, height=30)
self.check_tp_nb_s1e_unavg = gui.CheckBoxLabel('TP_NB_S1E', False, width=200, height=30)
self.check_tp_nb_s1w_unavg = gui.CheckBoxLabel('TP_NB_S1W', False, width=200, height=30)
self.check_s_sb_s2w_unavg = gui.CheckBoxLabel('S_SB_S2W', False, width=200, height=30)
self.check_s_sb_s2e_unavg = gui.CheckBoxLabel('S_SB_S2E', False, width=200, height=30)
self.check_s_sb_s1e_unavg = gui.CheckBoxLabel('S_SB_S1E', False, width=200, height=30)
self.check_s_sb_s1w_unavg = gui.CheckBoxLabel('S_SB_S1W', False, width=200, height=30)
self.check_t_sb_s2w_unavg = gui.CheckBoxLabel('T_SB_S2W', False, width=200, height=30)
self.check_t_sb_s2e_unavg = gui.CheckBoxLabel('T_SB_S2E', False, width=200, height=30)
self.check_t_sb_s1e_unavg = gui.CheckBoxLabel('T_SB_S1E', False, width=200, height=30)
self.check_t_sb_s1w_unavg = gui.CheckBoxLabel('T_SB_S1W', False, width=200, height=30)
self.check_tp_sb_s2w_unavg = gui.CheckBoxLabel('TP_SB_S2W', False, width=200, height=30)
self.check_tp_sb_s2e_unavg = gui.CheckBoxLabel('TP_SB_S2E', False, width=200, height=30)
self.check_tp_sb_s1e_unavg = gui.CheckBoxLabel('TP_SB_S1E', False, width=200, height=30)
self.check_tp_sb_s1w_unavg = gui.CheckBoxLabel('TP_SB_S1W', False, width=200, height=30)
unavg_sensors = [self.check_s_nb_s2w_unavg, self.check_s_nb_s2e_unavg,
self.check_s_nb_s1e_unavg, self.check_s_nb_s1w_unavg, self.check_t_nb_s2w_unavg,
self.check_t_nb_s2e_unavg, self.check_t_nb_s1e_unavg, self.check_t_nb_s1w_unavg,
self.check_tp_nb_s2w_unavg, self.check_tp_nb_s2e_unavg, self.check_tp_nb_s1e_unavg,
self.check_tp_nb_s1w_unavg, self.check_s_sb_s2w_unavg, self.check_s_sb_s2e_unavg,
self.check_s_sb_s1e_unavg, self.check_s_sb_s1w_unavg, self.check_t_sb_s2w_unavg,
self.check_t_sb_s2e_unavg, self.check_t_sb_s1e_unavg, self.check_t_sb_s1w_unavg,
self.check_tp_sb_s2w_unavg, self.check_tp_sb_s2e_unavg, self.check_tp_sb_s1e_unavg,
self.check_tp_sb_s1w_unavg]
self.go_unavg = gui.Button('Go', width=200, height=30, margin='10px')
self.go_unavg.onclick.do(self.get_selected_unavg)
unaveragedContainer.append([self.lbl_unavg, self.unavg_txt, self.start_unavg, self.end_unavg, unavg_sensors, self.go_unavg])
# FBG health
fbgContainer = gui.Container(width='100%', layout_orientation=gui.Container.LAYOUT_HORIZONTAL, margin='0px auto', style={'display': 'block', 'overflow': 'hidden'})
self.lbl_fbg = gui.Label('FBG Health', width='100%', height=30, margin='10px')
self.fbg_txt = gui.Label('This section shows the FBG peak range and power level for the specified dates. This information is used to understand whether there is a risk of erroneous data from FBGs being too close to each other, and whether an FBG peak level is deteriorating over time. All data is relative to time.', width='100%', height=30, margin='10px')
self.start_fbg = gui.Date(width=200, height=20)
self.end_fbg = gui.Date(width=200, height=20)
self.check_s_nb_s2w = gui.CheckBoxLabel('S_NB_S2W', False, width=200, height=30)
self.check_s_nb_s2e = gui.CheckBoxLabel('S_NB_S2E', False, width=200, height=30)
self.check_s_nb_s1e = gui.CheckBoxLabel('S_NB_S1E', False, width=200, height=30)
self.check_s_nb_s1w = gui.CheckBoxLabel('S_NB_S1W', False, width=200, height=30)
self.check_t_nb_s2w = gui.CheckBoxLabel('T_NB_S2W', False, width=200, height=30)
self.check_t_nb_s2e = gui.CheckBoxLabel('T_NB_S2E', False, width=200, height=30)
self.check_t_nb_s1e = gui.CheckBoxLabel('T_NB_S1E', False, width=200, height=30)
self.check_t_nb_s1w = gui.CheckBoxLabel('T_NB_S1W', False, width=200, height=30)
self.check_tp_nb_s2w = gui.CheckBoxLabel('TP_NB_S2W', False, width=200, height=30)
self.check_tp_nb_s2e = gui.CheckBoxLabel('TP_NB_S2E', False, width=200, height=30)
self.check_tp_nb_s1e = gui.CheckBoxLabel('TP_NB_S1E', False, width=200, height=30)
self.check_tp_nb_s1w = gui.CheckBoxLabel('TP_NB_S1W', False, width=200, height=30)
self.check_s_sb_s2w = gui.CheckBoxLabel('S_SB_S2W', False, width=200, height=30)
self.check_s_sb_s2e = gui.CheckBoxLabel('S_SB_S2E', False, width=200, height=30)
self.check_s_sb_s1e = gui.CheckBoxLabel('S_SB_S1E', False, width=200, height=30)
self.check_s_sb_s1w = gui.CheckBoxLabel('S_SB_S1W', False, width=200, height=30)
self.check_t_sb_s2w = gui.CheckBoxLabel('T_SB_S2W', False, width=200, height=30)
self.check_t_sb_s2e = gui.CheckBoxLabel('T_SB_S2E', False, width=200, height=30)
self.check_t_sb_s1e = gui.CheckBoxLabel('T_SB_S1E', False, width=200, height=30)
self.check_t_sb_s1w = gui.CheckBoxLabel('T_SB_S1W', False, width=200, height=30)
self.check_tp_sb_s2w = gui.CheckBoxLabel('TP_SB_S2W', False, width=200, height=30)
self.check_tp_sb_s2e = gui.CheckBoxLabel('TP_SB_S2E', False, width=200, height=30)
self.check_tp_sb_s1e = gui.CheckBoxLabel('TP_SB_S1E', False, width=200, height=30)
self.check_tp_sb_s1w = gui.CheckBoxLabel('TP_SB_S1W', False, width=200, height=30)
fbg_sensors = [self.check_s_nb_s2w, self.check_s_nb_s2e, self.check_s_nb_s1e,
self.check_s_nb_s1w, self.check_t_nb_s2w, self.check_t_nb_s2e, self.check_t_nb_s1e,
self.check_t_nb_s1w, self.check_tp_nb_s2w, self.check_tp_nb_s2e, self.check_tp_nb_s1e,
self.check_tp_nb_s1w, self.check_s_sb_s2w, self.check_s_sb_s2e, self.check_s_sb_s1e,
self.check_s_sb_s1w, self.check_t_sb_s2w, self.check_t_sb_s2e, self.check_t_sb_s1e,
self.check_t_sb_s1w, self.check_tp_sb_s2w, self.check_tp_sb_s2e, self.check_tp_sb_s1e,
self.check_tp_sb_s1w]
self.go_avg = gui.Button('Go', width=200, height=30, margin='10px')
self.go_avg.onclick.do(self.get_selected_avg)
fbgContainer.append([self.lbl_fbg, self.fbg_txt, self.start_fbg, self.end_fbg, fbg_sensors, self.go_avg])
mainContainer.append([welcomeContainer, averagedContainer, unaveragedContainer, fbgContainer])
self.stop_flag = False
return mainContainer
def query(self, table, sensors):
conn = mysql.connect(host='localhost', database='douglas park bridges', username='root', password='zk89peTN')
cursor = conn.cursor()
select = ', '.join(sensors)
query = f"SELECT timestamp, {select} from {table}"
print(query)
cursor.execute(query)
records = cursor.fetchall()
timestamp = []
a = []
b = []
c = []
d = []
e = []
f = []
g = []
h = []
i = []
j = []
k = []
l = []
m = []
n = []
o = []
p = []
q = []
r = []
s = []
t = []
u = []
v = []
w = []
x = []
alphabet = [a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x]
for row in records:
timestamp.append(row[0])
i = 1
while i < len(row):
alphabet[i].append(row[i])
i += 1
filled = []
for lst in alphabet:
if len(lst) > 0:
filled.append(lst)
print(filled)
def get_selected_avg(self, something):
avg_sensors = [self.check_s_nb_s2w, self.check_s_nb_s2e, self.check_s_nb_s1e,
self.check_s_nb_s1w, self.check_t_nb_s2w, self.check_t_nb_s2e, self.check_t_nb_s1e,
self.check_t_nb_s1w, self.check_tp_nb_s2w, self.check_tp_nb_s2e, self.check_tp_nb_s1e,
self.check_tp_nb_s1w, self.check_s_sb_s2w, self.check_s_sb_s2e, self.check_s_sb_s1e,
self.check_s_sb_s1w, self.check_t_sb_s2w, self.check_t_sb_s2e, self.check_t_sb_s1e,
self.check_t_sb_s1w, self.check_tp_sb_s2w, self.check_tp_sb_s2e, self.check_tp_sb_s1e,
self.check_tp_sb_s1w]
sensors = ['s_nb_s2w', 's_nb_s2e', 's_nb_s1e', 's_nb_s1w', 't_nb_s2w',
't_nb_s2e', 't_nb_s1e', 't_nb_s1w', 'tp_nb_s2w', 'tp_nb_s2e',
'tp_nb_s1e', 'tp_nb_s1w', 's_nb_s2w', 's_nb_s2e', 's_nb_s1e',
's_nb_s1w', 't_nb_s2w','t_nb_s2e', 't_nb_s1e', 't_nb_s1w',
'tp_nb_s2w', 'tp_nb_s2e', 'tp_nb_s1e', 'tp_nb_s1w']
avg_selected = []
count = 0
for sensor in avg_sensors:
if sensor.get_value() == True:
avg_selected.append(sensors[count])
count += 1
self.query('averaged', avg_selected)
def get_selected_unavg(self, something):
unavg_sensors = [self.check_s_nb_s2w_unavg, self.check_s_nb_s2e_unavg,
self.check_s_nb_s1e_unavg, self.check_s_nb_s1w_unavg, self.check_t_nb_s2w_unavg,
self.check_t_nb_s2e_unavg, self.check_t_nb_s1e_unavg, self.check_t_nb_s1w_unavg,
self.check_tp_nb_s2w_unavg, self.check_tp_nb_s2e_unavg, self.check_tp_nb_s1e_unavg,
self.check_tp_nb_s1w_unavg, self.check_s_sb_s2w_unavg, self.check_s_sb_s2e_unavg,
self.check_s_sb_s1e_unavg, self.check_s_sb_s1w_unavg, self.check_t_sb_s2w_unavg,
self.check_t_sb_s2e_unavg, self.check_t_sb_s1e_unavg, self.check_t_sb_s1w_unavg,
self.check_tp_sb_s2w_unavg, self.check_tp_sb_s2e_unavg, self.check_tp_sb_s1e_unavg,
self.check_tp_sb_s1w_unavg]
sensors = ['s_nb_s2w', 's_nb_s2e', 's_nb_s1e', 's_nb_s1w', 't_nb_s2w',
't_nb_s2e', 't_nb_s1e', 't_nb_s1w', 'tp_nb_s2w', 'tp_nb_s2e',
'tp_nb_s1e', 'tp_nb_s1w', 's_nb_s2w', 's_nb_s2e', 's_nb_s1e',
's_nb_s1w', 't_nb_s2w','t_nb_s2e', 't_nb_s1e', 't_nb_s1w',
'tp_nb_s2w', 'tp_nb_s2e', 'tp_nb_s1e', 'tp_nb_s1w']
unavg_selected = []
count = 0
for sensor in unavg_sensors:
if sensor.get_value() == True:
unavg_selected.append(sensors[count])
count += 1
self.query('unaveraged', unavg_selected)
def on_close(self):
super(MyApp, self).on_close()
if __name__ == '__main__':
start(MyApp, debug=True, address='0.0.0.0', port=8081, start_browser=True, multiple_instance=True)