DmitrMakeev commited on
Commit
6a82b1a
·
verified ·
1 Parent(s): 9a40b68

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -17
app.py CHANGED
@@ -324,10 +324,10 @@ def plot_ph():
324
  @app.route('/plot_ph_week', methods=['GET'])
325
  def plot_ph_week():
326
  try:
327
- # Получаем номер недели из параметра, если его нет - начинаем с 1
328
  week_number = request.args.get('week', default=1, type=int)
329
 
330
- # Проверяем, что номер недели в пределах 1-30
331
  if week_number < 1:
332
  week_number = 1
333
  elif week_number > 30:
@@ -352,12 +352,12 @@ def plot_ph_week():
352
  </html>
353
  '''
354
 
355
- # Выбираем данные за выбранную неделю
356
  cursor.execute('''
357
- SELECT date_time, ph, dey
358
  FROM system_data
359
  WHERE wek = ?
360
- ORDER BY date_time
361
  ''', (week_number,))
362
  rows = cursor.fetchall()
363
 
@@ -376,19 +376,23 @@ def plot_ph_week():
376
  </html>
377
  '''
378
 
379
- # Формируем данные для графика
380
- dates = [f"{row[0]} (d: {row[2]})" for row in rows]
381
- ph_values = [float(row[1]) for row in rows]
 
382
 
383
- # Создаём график
384
- plt.figure(figsize=(15, 6))
385
- plt.plot(dates, ph_values, marker='o', linestyle='-', color='b')
386
- plt.title(f'График pH за {week_number}-ю неделю')
387
- plt.xlabel('Дата и день недели')
 
 
 
 
388
  plt.ylabel('Значение pH')
389
- plt.xticks(rotation=90)
390
  plt.grid(True)
391
- plt.gcf().subplots_adjust(bottom=0.4)
392
 
393
  # Сохраняем график в буфер
394
  buffer = io.BytesIO()
@@ -402,7 +406,7 @@ def plot_ph_week():
402
  return f'''
403
  <html>
404
  <body>
405
- <h1>График pH за {week_number}-ю неделю</h1>
406
  <button onclick="window.location.href='/plot_ph_week?week={week_number - 1}'" {"disabled" if week_number == 1 else ""}>Предыдущая неделя</button>
407
  <button onclick="window.location.href='/plot_ph_week?week={week_number + 1}'" {"disabled" if week_number == 30 else ""}>Следующая неделя</button>
408
  <br><br>
@@ -431,7 +435,6 @@ def plot_ph_week():
431
 
432
 
433
 
434
-
435
  @app.route("/")
436
  def index():
437
  return flask.render_template('index.html')
 
324
  @app.route('/plot_ph_week', methods=['GET'])
325
  def plot_ph_week():
326
  try:
327
+ # Получаем номер недели из параметра (по умолчанию 1)
328
  week_number = request.args.get('week', default=1, type=int)
329
 
330
+ # Проверяем границы (1-30 недель)
331
  if week_number < 1:
332
  week_number = 1
333
  elif week_number > 30:
 
352
  </html>
353
  '''
354
 
355
+ # Выбираем все данные за указанную неделю
356
  cursor.execute('''
357
+ SELECT dey, ph
358
  FROM system_data
359
  WHERE wek = ?
360
+ ORDER BY dey
361
  ''', (week_number,))
362
  rows = cursor.fetchall()
363
 
 
376
  </html>
377
  '''
378
 
379
+ # Создаём словарь {день недели: список значений pH}
380
+ data_by_day = {i: [] for i in range(1, 8)}
381
+ for day, ph in rows:
382
+ data_by_day[day].append(float(ph))
383
 
384
+ # Создаём график (X: дни 1-7, Y: pH)
385
+ plt.figure(figsize=(10, 5))
386
+
387
+ # Наносим точки для каждого дня
388
+ for day in range(1, 8):
389
+ plt.scatter([day] * len(data_by_day[day]), data_by_day[day], label=f'День {day}')
390
+
391
+ plt.title(f'Значения pH за {week_number}-ю неделю')
392
+ plt.xlabel('День недели')
393
  plt.ylabel('Значение pH')
394
+ plt.xticks(range(1, 8)) # Подписи оси X (1-7)
395
  plt.grid(True)
 
396
 
397
  # Сохраняем график в буфер
398
  buffer = io.BytesIO()
 
406
  return f'''
407
  <html>
408
  <body>
409
+ <h1>Значения pH за {week_number}-ю неделю</h1>
410
  <button onclick="window.location.href='/plot_ph_week?week={week_number - 1}'" {"disabled" if week_number == 1 else ""}>Предыдущая неделя</button>
411
  <button onclick="window.location.href='/plot_ph_week?week={week_number + 1}'" {"disabled" if week_number == 30 else ""}>Следующая неделя</button>
412
  <br><br>
 
435
 
436
 
437
 
 
438
  @app.route("/")
439
  def index():
440
  return flask.render_template('index.html')