Update app.py
Browse files
app.py
CHANGED
@@ -310,12 +310,7 @@ def plot_ph_week():
|
|
310 |
try:
|
311 |
# Получаем номер недели из параметров запроса
|
312 |
week_number = request.args.get('week', default=1, type=int)
|
313 |
-
|
314 |
-
# Ограничиваем диапазон недели от 1 до 30
|
315 |
-
if week_number < 1:
|
316 |
-
week_number = 1
|
317 |
-
elif week_number > 30:
|
318 |
-
week_number = 30
|
319 |
|
320 |
# Подключаемся к базе данных
|
321 |
conn = sqlite3.connect('system_data.db')
|
@@ -326,16 +321,21 @@ def plot_ph_week():
|
|
326 |
table_exists = cursor.fetchone()
|
327 |
|
328 |
if not table_exists:
|
|
|
329 |
return render_template('plot_ph_week.html', data=None, week_number=week_number, table_exists=False)
|
330 |
|
331 |
# Запрашиваем данные за выбранную неделю
|
332 |
-
cursor.execute('''
|
333 |
-
|
|
|
|
|
|
|
|
|
334 |
rows = cursor.fetchall()
|
335 |
|
336 |
-
# Закрываем соединение с базой
|
337 |
conn.close()
|
338 |
|
|
|
339 |
if not rows:
|
340 |
return render_template('plot_ph_week.html', data=None, week_number=week_number, table_exists=True)
|
341 |
|
@@ -343,22 +343,25 @@ def plot_ph_week():
|
|
343 |
data = {
|
344 |
'week': week_number,
|
345 |
'dates': [row[0] for row in rows],
|
346 |
-
'
|
347 |
-
'
|
348 |
-
'
|
349 |
-
'
|
350 |
-
'
|
351 |
-
'
|
352 |
-
'
|
353 |
-
'
|
354 |
-
'
|
355 |
-
'
|
356 |
}
|
357 |
|
|
|
358 |
return render_template('plot_ph_week.html', data=data, week_number=week_number, table_exists=True)
|
359 |
|
360 |
except Exception as e:
|
361 |
-
|
|
|
|
|
362 |
|
363 |
|
364 |
|
|
|
310 |
try:
|
311 |
# Получаем номер недели из параметров запроса
|
312 |
week_number = request.args.get('week', default=1, type=int)
|
313 |
+
week_number = max(1, min(30, week_number)) # Ограничиваем диапазон 1-30
|
|
|
|
|
|
|
|
|
|
|
314 |
|
315 |
# Подключаемся к базе данных
|
316 |
conn = sqlite3.connect('system_data.db')
|
|
|
321 |
table_exists = cursor.fetchone()
|
322 |
|
323 |
if not table_exists:
|
324 |
+
conn.close()
|
325 |
return render_template('plot_ph_week.html', data=None, week_number=week_number, table_exists=False)
|
326 |
|
327 |
# Запрашиваем данные за выбранную неделю
|
328 |
+
cursor.execute('''
|
329 |
+
SELECT date_time, dey, ph, ec, tS, tA, hDm, sVen, onA, onB, onC
|
330 |
+
FROM system_data
|
331 |
+
WHERE wek = ?
|
332 |
+
ORDER BY date_time
|
333 |
+
''', (str(week_number),)) # Приводим week_number к строке, так как wek имеет тип TEXT
|
334 |
rows = cursor.fetchall()
|
335 |
|
|
|
336 |
conn.close()
|
337 |
|
338 |
+
# Если данных нет
|
339 |
if not rows:
|
340 |
return render_template('plot_ph_week.html', data=None, week_number=week_number, table_exists=True)
|
341 |
|
|
|
343 |
data = {
|
344 |
'week': week_number,
|
345 |
'dates': [row[0] for row in rows],
|
346 |
+
'days_of_week': [int(row[1]) if row[1] else 0 for row in rows], # Преобразуем dey в int
|
347 |
+
'ph': [float(row[2]) if row[2] else 0.0 for row in rows], # pH
|
348 |
+
'ec': [float(row[3]) if row[3] else 0.0 for row in rows], # EC
|
349 |
+
'tS': [float(row[4]) if row[4] else 0.0 for row in rows], # Температура раствора
|
350 |
+
'tA': [float(row[5]) if row[5] else 0.0 for row in rows], # Температура воздуха
|
351 |
+
'hDm': [float(row[6]) if row[6] else 0.0 for row in rows], # Влажность воздуха
|
352 |
+
'sVen': [float(row[7]) if row[7] else 0.0 for row in rows], # Обороты вентилятора
|
353 |
+
'onA': [float(row[8]) if row[8] else 0.0 for row in rows], # Насос A
|
354 |
+
'onB': [float(row[9]) if row[9] else 0.0 for row in rows], # Насос B
|
355 |
+
'onC': [float(row[10]) if row[10] else 0.0 for row in rows] # Насос C
|
356 |
}
|
357 |
|
358 |
+
# Отправляем данные в HTML-шаблон
|
359 |
return render_template('plot_ph_week.html', data=data, week_number=week_number, table_exists=True)
|
360 |
|
361 |
except Exception as e:
|
362 |
+
# Логируем ошибку в консоль для отладки
|
363 |
+
print(f"Ошибка: {str(e)}")
|
364 |
+
return render_template('plot_ph_week.html', data=None, week_number=week_number, table_exists=True, message=f"Ошибка: {str(e)}")
|
365 |
|
366 |
|
367 |
|