Update app.py
Browse files
app.py
CHANGED
@@ -312,10 +312,7 @@ def plot_ph_week():
|
|
312 |
week_number = request.args.get('week', default=1, type=int)
|
313 |
|
314 |
# Ограничиваем диапазон недели от 1 до 30
|
315 |
-
|
316 |
-
week_number = 1
|
317 |
-
elif week_number > 30:
|
318 |
-
week_number = 30
|
319 |
|
320 |
# Подключаемся к базе данных
|
321 |
conn = sqlite3.connect('system_data.db')
|
@@ -326,18 +323,15 @@ def plot_ph_week():
|
|
326 |
table_exists = cursor.fetchone()
|
327 |
|
328 |
if not table_exists:
|
329 |
-
# Если таблица не существует, возвращаем сообщение об этом, а не ошибку
|
330 |
return render_template('plot_ph_week.html', data=None, week_number=week_number, table_exists=False)
|
331 |
|
332 |
# Запрашиваем данные за выбранную неделю
|
333 |
-
cursor.execute('''SELECT date_time, ph, ec, dey, onA, onB, onC
|
334 |
FROM system_data WHERE wek = ? ORDER BY date_time''', (week_number,))
|
335 |
rows = cursor.fetchall()
|
336 |
|
337 |
-
# Закрываем соединение с базой
|
338 |
conn.close()
|
339 |
|
340 |
-
# Если данных нет, передаем информацию, что данных нет за эту неделю
|
341 |
if not rows:
|
342 |
return render_template('plot_ph_week.html', data=None, week_number=week_number, table_exists=True)
|
343 |
|
@@ -350,14 +344,16 @@ def plot_ph_week():
|
|
350 |
'onA': [float(row[4]) for row in rows],
|
351 |
'onB': [float(row[5]) for row in rows],
|
352 |
'onC': [float(row[6]) for row in rows],
|
|
|
|
|
|
|
|
|
353 |
'days_of_week': [int(row[3]) for row in rows]
|
354 |
}
|
355 |
|
356 |
-
# Отправляем данные в HTML-шаблон
|
357 |
return render_template('plot_ph_week.html', data=data, week_number=week_number, table_exists=True)
|
358 |
|
359 |
except Exception as e:
|
360 |
-
# В случае ошибки возвращаем сообщение
|
361 |
return jsonify({'status': 'error', 'message': str(e)}), 500
|
362 |
|
363 |
|
@@ -373,6 +369,7 @@ def plot_ph_week():
|
|
373 |
|
374 |
|
375 |
|
|
|
376 |
@app.route("/")
|
377 |
def index():
|
378 |
return flask.render_template('index.html')
|
|
|
312 |
week_number = request.args.get('week', default=1, type=int)
|
313 |
|
314 |
# Ограничиваем диапазон недели от 1 до 30
|
315 |
+
week_number = max(1, min(week_number, 30))
|
|
|
|
|
|
|
316 |
|
317 |
# Подключаемся к базе данных
|
318 |
conn = sqlite3.connect('system_data.db')
|
|
|
323 |
table_exists = cursor.fetchone()
|
324 |
|
325 |
if not table_exists:
|
|
|
326 |
return render_template('plot_ph_week.html', data=None, week_number=week_number, table_exists=False)
|
327 |
|
328 |
# Запрашиваем данные за выбранную неделю
|
329 |
+
cursor.execute('''SELECT date_time, ph, ec, dey, onA, onB, onC, tS, tA, hDm, sVen
|
330 |
FROM system_data WHERE wek = ? ORDER BY date_time''', (week_number,))
|
331 |
rows = cursor.fetchall()
|
332 |
|
|
|
333 |
conn.close()
|
334 |
|
|
|
335 |
if not rows:
|
336 |
return render_template('plot_ph_week.html', data=None, week_number=week_number, table_exists=True)
|
337 |
|
|
|
344 |
'onA': [float(row[4]) for row in rows],
|
345 |
'onB': [float(row[5]) for row in rows],
|
346 |
'onC': [float(row[6]) for row in rows],
|
347 |
+
'tS': [float(row[7]) for row in rows],
|
348 |
+
'tA': [float(row[8]) for row in rows],
|
349 |
+
'hDm': [float(row[9]) for row in rows],
|
350 |
+
'sVen': [float(row[10]) for row in rows],
|
351 |
'days_of_week': [int(row[3]) for row in rows]
|
352 |
}
|
353 |
|
|
|
354 |
return render_template('plot_ph_week.html', data=data, week_number=week_number, table_exists=True)
|
355 |
|
356 |
except Exception as e:
|
|
|
357 |
return jsonify({'status': 'error', 'message': str(e)}), 500
|
358 |
|
359 |
|
|
|
369 |
|
370 |
|
371 |
|
372 |
+
|
373 |
@app.route("/")
|
374 |
def index():
|
375 |
return flask.render_template('index.html')
|