File size: 22,703 Bytes
58f870a
 
 
 
 
8ed8eba
58f870a
f9febf6
5e8ef40
1b0cf30
1969012
58f870a
aa0b2be
58f870a
aa0b2be
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58f870a
 
 
291e8c2
aa0b2be
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
677a61e
aa0b2be
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6c01ee1
e82b3e3
360653d
7ad0fec
0bfef08
ae91945
e82b3e3
243c01e
d7d25f5
d73ec54
075a36e
e82b3e3
ecb2b71
708363a
 
 
6c01ee1
 
f71c7e3
5105005
708363a
 
6c01ee1
8ed38d0
ecc66d1
08d6aa7
 
e9bce03
 
 
 
 
 
 
ecc66d1
33380ec
41fd7da
3086c75
9411a9f
33380ec
b373233
e9bce03
 
743bb60
e9bce03
 
 
 
41fd7da
 
 
3086c75
41fd7da
33380ec
ca93fd5
e9bce03
 
ca93fd5
e9bce03
 
 
 
41fd7da
 
 
3086c75
41fd7da
33380ec
ca93fd5
e9bce03
 
ca93fd5
e9bce03
 
 
 
41fd7da
 
e9bce03
e3bf126
312bdd7
 
72fe1ce
 
 
 
e3bf126
 
06f0d9c
e3bf126
4d5bdb1
2a770b0
4d5bdb1
 
dfed617
4d5bdb1
e3bf126
 
6d3e04f
e3bf126
 
 
06f0d9c
e3bf126
4d5bdb1
2a770b0
4d5bdb1
 
dfed617
4d5bdb1
e3bf126
 
6d3e04f
e3bf126
 
 
06f0d9c
e3bf126
4d5bdb1
2a770b0
4d5bdb1
 
dfed617
4d5bdb1
e3bf126
 
6d3e04f
e3bf126
 
 
d64bbc2
d9b6018
958053a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a9befbb
ff2d834
5886fbf
 
 
c1b8d4f
c1c7904
c7f339c
c1c7904
68c2b9e
c1c7904
68c2b9e
6f27fe0
 
 
 
 
c1c7904
 
 
c1b8d4f
 
a5667b2
c1b8d4f
 
 
690c04e
 
 
5f66878
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5886fbf
 
67f19c9
 
 
88efff7
67f19c9
5886fbf
0292fb1
 
 
17c95c0
67f19c9
 
4bd381a
5886fbf
0292fb1
67f19c9
0292fb1
1a43e11
81f024f
0292fb1
81f024f
 
 
0292fb1
 
 
d7d25f5
b184ba5
 
 
 
 
 
 
d7d25f5
b184ba5
 
 
 
 
 
 
84cc569
b184ba5
 
 
 
 
 
 
81f024f
 
 
 
d7d25f5
 
84cc569
 
 
 
 
 
d7d25f5
 
 
 
84cc569
 
 
 
 
 
d7d25f5
 
d73ec54
 
 
 
 
 
 
 
 
 
d7d25f5
075a36e
 
 
 
 
 
 
d7d25f5
 
 
 
 
 
143c662
c1c7904
d9986da
c1c7904
 
 
d9986da
 
53697c7
 
 
d9986da
 
 
 
 
 
430caeb
1f6d338
c1c7904
04e544a
d9986da
c7f339c
143c662
c1c7904
143c662
d9986da
 
04e544a
c1c7904
d9986da
 
 
04e544a
 
 
 
c1c7904
04e544a
c1c7904
a51e39d
 
4239fba
c1c7904
04e544a
 
 
 
 
c1c7904
284989f
8cb8cfc
a51e39d
 
35489aa
c1c7904
04e544a
430caeb
 
 
 
 
284989f
430caeb
 
284989f
6786391
430caeb
 
 
 
 
 
 
284989f
430caeb
 
284989f
35489aa
430caeb
 
 
 
 
 
 
284989f
430caeb
 
284989f
35489aa
430caeb
 
04e544a
 
 
 
c1c7904
284989f
8cb8cfc
a51e39d
 
35489aa
c1c7904
04e544a
 
 
 
 
c1c7904
284989f
8cb8cfc
a51e39d
 
35489aa
c1c7904
04e544a
 
 
 
 
c1c7904
04e544a
8cb8cfc
a51e39d
 
4239fba
c1c7904
04e544a
 
 
 
 
c1c7904
284989f
8cb8cfc
a51e39d
 
35489aa
c1c7904
04e544a
d9986da
 
c1c7904
d9986da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2600717
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d9986da
 
2600717
 
 
d9986da
a51e39d
d9986da
 
 
 
 
 
 
430caeb
53697c7
 
 
d9986da
 
 
 
53697c7
 
 
d9986da
 
 
 
04e544a
 
a51e39d
 
 
 
 
430caeb
53697c7
 
 
d9986da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7b017ad
c1c7904
7b017ad
c1c7904
 
 
 
 
 
53697c7
 
 
c1c7904
 
 
 
 
7b017ad
 
c1c7904
 
 
5a733c1
c1c7904
 
5a733c1
d9986da
0292fb1
 
291e8c2
58f870a
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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width" />
        <link rel="icon" type="image/ico" href="https://huggingface.co/spaces/igs-img/stor/resolve/main/list.ico">
		<title>My static Space</title>
		<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<script src="https://cdn.plot.ly/plotly-2.32.0.min.js"></script>

<style>

#protection-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5); /* Полупрозрачный чёрный */
    z-index: 5; /* На передний план */
    display: block; /* Включено по умолчанию */
    pointer-events: auto; /* Блокирует клики */
}
/* Поднимаем SweetAlert2 выше */
.swal2-container {
    z-index: 10 !important;
} 
</style>

      
	</head>
<body>
<div id="protection-overlay"></div> <!-- Полупрозрачный фон -->
<script>
document.addEventListener("DOMContentLoaded", function () {
    const overlay = document.getElementById("protection-overlay");
    let pageKey = localStorage.getItem("page_key");
    // Функция проверки ключа
    function checkApiKey(apiKey) {
        fetch(`/page_key?api_sys=${apiKey}`)
            .then(response => response.json())
            .then(data => {
                if (data.status === "ok") {
                    overlay.style.display = "none"; // ✅ Убираем защиту
                } else {
                    requestNewKey("Неверный код. Введите заново!");
                }
            })
            .catch(() => requestNewKey("Ошибка сервера. Попробуйте снова."));
    }
    // Функция запроса нового ключа
    function requestNewKey(message = "Введите код доступа:") {
        Swal.fire({
            title: "Внимание!",
            text: message,
            input: "text",
            inputAttributes: { autocapitalize: "off" },
            showCancelButton: false,
            confirmButtonText: "Отправить",
            confirmButtonColor: "#4CAF50",
            allowOutsideClick: false
        }).then((result) => {
            if (result.isConfirmed && result.value) {
                localStorage.setItem("page_key", result.value); // 🔥 Сохраняем ключ
                checkApiKey(result.value); // 🔥 Проверяем ключ
            } else {
                requestNewKey("Введите корректный код!"); // Повторяем ввод
            }
        });
    }
    // Если ключ есть → Проверяем его, иначе запрашиваем новый
    if (pageKey) {
        checkApiKey(pageKey);
    } else {
        requestNewKey();
    }
});
</script>


<nav class="navbar navbar-light bg-light">
  <a class="navbar-brand" href="/online">
    <img src="https://huggingface.co/spaces/igs-img/stor/resolve/main/list.png" width="30" height="30" class="d-inline-block align-top" alt="">
    MackorLab
  </a>
  <form class="form-inline">
    <button  id="st_onl" class="btn btn-success" type="button" >Онлайн</button>
    <button   id="st_set" class="btn btn-outline-success" type="button" >Настройки</button>
    <button id="st_plot" class="btn btn-outline-success" type="button">Графики</button>
    <button id="st_table" class="btn btn-outline-success" type="button">Таблица</button>
  </form>
</nav>


  
<div class="container mt-3">

   <div class="container text-center"> 
    <h1>Онлайн данные системы</h1>
   </div> <br>










  



<div class="card-deck">
  <div class="card">
    
    <div class="card-body">
      <div class="container text-center">
      <h5 class="card-title">Время </h5>
          </div>
        <div class="container text-center">
      <h2><span id="v_hid"></span> : <span id="v_min"></span></h2>
        </div>  
    </div>
    <div class="card-footer">
      
    </div>
  </div>
  <div class="card">
    
    <div class="card-body">
      <div class="container text-center">
      <h5 class="card-title">Неделя </h5>
         </div>
        <div class="container text-center">
      <h2><span id="wek"></span></h2>
       </div>   
    </div>
    <div class="card-footer">
      
    </div>
  </div>
  <div class="card">
    
    <div class="card-body">
      <div class="container text-center">
      <h5 class="card-title">День </h5>
         </div>
        <div class="container text-center">
      <h2><span id="dey"></span></h2>
       </div>   
    </div>
    <div class="card-footer">
     
    </div>
  </div>
</div> 
 <br>





  
 <div class="card-deck">
  <div class="card">
    
    <div class="card-body">
      <div class="container text-center">
      <h5 class="card-title">pH раствора</h5>
          </div>
        <div class="container text-center">
      <h2><span id="ph"></span></h2>
        </div>  
    </div>
    <div class="card-footer">
      
    </div>
  </div>
  <div class="card">
    
    <div class="card-body">
      <div class="container text-center">
      <h5 class="card-title">EC раствора</h5>
         </div>
        <div class="container text-center">
      <h2><span id="ec"></span></h2>
       </div>   
    </div>
    <div class="card-footer">
      
    </div>
  </div>
  <div class="card">
    
    <div class="card-body">
      <div class="container text-center">
      <h5 class="card-title">Т. раствора</h5>
         </div>
        <div class="container text-center">
      <h2><span id="tS"></span></h2>
       </div>   
    </div>
    <div class="card-footer">
     
    </div>
  </div>
</div> 

  <br>
  <div class="card-deck">
  <div class="card">
    
    <div class="card-body">
      <div class="container text-center">
      <h5 class="card-title">Т. воздуха</h5>
          </div>
        <div class="container text-center">
      <h2><span id="tA"></span></h2>
        </div>  
    </div>
    <div class="card-footer">
      
    </div>
  </div>
  <div class="card">
    
    <div class="card-body">
      <div class="container text-center">
      <h5 class="card-title">Вл. воздуха</h5>
         </div>
        <div class="container text-center">
      <h2><span id="hDm"></span></h2>
       </div>   
    </div>
    <div class="card-footer">
      
    </div>
  </div>
  <div class="card">
    
    <div class="card-body">
      <div class="container text-center">
      <h5 class="card-title">Об. вентилятора</h5>
         </div>
        <div class="container text-center">
      <h2><span id="sVen"></span></h2>
       </div>   
    </div>
    <div class="card-footer">
     
    </div>
  </div>
</div>  

  
  <br>


<div class="container text-center">
  <div class="d-flex justify-content-between align-items-center mb-3">
    
    <div>
      <label for="periodSelect"><h5>Графики за предыдущий период:</h5></label>
      <select id="periodSelect" class="form-select" style="width: auto; display: inline-block;">
        <option value="60">10 минут</option>
        <option value="120">20 минут</option>
        <option value="180">30 минут</option>
        <option value="240">40 минут</option>
        <option value="300">50 минут</option>
        <option value="360">1 час</option>
      </select>
    </div>
  </div>
  <div id="parametersChart" style="width: 100%; height: 400px;"></div>
</div>



  



<div class="card-deck">
  <div class="card">
    
    <div class="card-body">
      <div class="container text-center">
      <h5 class="card-title">Система: <span id="rFul"></span></h5>
      </div>  
    </div>
  </div>
  <div class="card">

    <div class="card-body">
      <div class="container text-center">
      <h5 class="card-title">Освещение: <span id="rLi"></span></h5>
       </div>
    </div>
  </div>
  <div class="card">

    <div class="card-body">
      <div class="container text-center">
      <h5 class="card-title">Под.воды: <span id="rWat"></span></h5>
      </div>
    </div>
  </div>
</div>



  
  <br>

<div class="card-deck">
  <div class="card">
    
    <div class="card-body">
      <div class="container text-center">
      <h5 class="card-title">Под. раствора: <span id="rRas"></span></h5>
      </div>  
    </div>
  </div>
  <div class="card">

    <div class="card-body">
      <div class="container text-center">
      <h5 class="card-title">Доз. pH: <span id="rPH"></span></h5>
       </div>
    </div>
  </div>
  <div class="card">

    <div class="card-body">
      <div class="container text-center">
      <h5 class="card-title">Доз. EC: <span id="rEC"></span></h5>
      </div>
    </div>
  </div>
</div>



  
  <br>


<div class="card-deck">
  <div class="card">
    
    <div class="card-body">
      <div class="container text-center">
      <h5 class="card-title">Слив: <span id="rSl"></span></h5>
      </div>  
    </div>
  </div>
  <div class="card">

    <div class="card-body">
      <div class="container text-center">
      <h5 class="card-title">Ур. раствора: <span id="rLe"></span></h5>
       </div>
    </div>
  </div>
  <div class="card">

    <div class="card-body">
      <div class="container text-center">
      <h5 class="card-title">Дат. затопления: <span id="alW"></span></h5>
      </div>
    </div>
  </div>
</div>

 <br>




<div class="card text-center">

  <div class="card-body">
      <div class="container text-center">
        <span><button id="but_start" type="button" class="btn btn-success btn-lg">Старт</button></span>
        <span><button id="but_stop" type="button" class="btn btn-danger btn-lg">Стоп</button></span>
        <span><button id="but_res" type="button" class="btn btn-info btn-lg">Рестарт</button></span>
        <span><button id="but_sliv" type="button" class="btn btn-secondary btn-lg">Зам. раствора</button></span>        
      </div> 
  </div>
  <div class="card-footer text-muted"> </div>
</div>
<br><br><br><br><br><br>
  
</div>


<script>
document.getElementById("but_start").addEventListener("click", function() {
    var xhr = new XMLHttpRequest();
    xhr.open("GET", "/but_start", true);
    xhr.send();
});
</script>

<script>
document.getElementById("but_stop").addEventListener("click", function() {
    var xhr = new XMLHttpRequest();
    xhr.open("GET", "/but_stop", true);
    xhr.send();
});
</script>

<script>
document.getElementById("but_res").addEventListener("click", function() {
    var xhr = new XMLHttpRequest();
    xhr.open("GET", "/but_res", true);
    xhr.send();
});
</script>

<script>
document.getElementById("but_sliv").addEventListener("click", function() {
    var xhr = new XMLHttpRequest();
    xhr.open("GET", "/but_sliv", true);
    xhr.send();
});
</script>

  


<script>
    document.getElementById("st_onl").addEventListener("click", function() {
        // Получаем основной URL без пути и параметров
        var baseUrl = window.location.origin;
        // Добавляем необходимый путь к основному URL
        var targetUrl = baseUrl + "/online";
        // Переходим по сформированному URL
        window.location.href = targetUrl;
    });
</script>
<script>
    document.getElementById("st_set").addEventListener("click", function() {
        // Получаем основной URL без пути и параметров
        var baseUrl = window.location.origin;
        // Добавляем необходимый путь к основному URL
        var targetUrl = baseUrl + "/settings";
        // Переходим по сформированному URL
        window.location.href = targetUrl;
    });
</script>
<script>
    document.getElementById("st_plot").addEventListener("click", function() {
        // Получаем основной URL без пути и параметров
        var baseUrl = window.location.origin;
        // Добавляем необходимый путь к основному URL
        var targetUrl = baseUrl + "/plot_week";
        // Переходим по сформированному URL
        window.location.href = targetUrl;
    });
</script>

<script>
    document.getElementById("st_table").addEventListener("click", function() {
        var baseUrl = window.location.origin;
        var targetUrl = baseUrl + "/table";
        window.location.href = targetUrl;
    });
</script>






<script>
  // Объект для хранения истории данных
  let dataHistory = {
    labels: [],
    dates: [],
    times: [],
    ph: [],
    ec: [],
    ec_A_eep: [],
    ec_B_eep: [],
    ec_C_eep: [],
    tS: [],
    tA: [],
    hDm: [],
    sVen: []
  };

  // Максимальное количество точек (по умолчанию 60)
  let maxPoints = 60;

  // Инициализация графика Plotly
  const layout = {
    title: "",
    xaxis: {
      showticklabels: false
    },
    yaxis: { title: "Значения" },
    showlegend: true,
    height: 400,
    hovermode: "closest"
  };

  const traces = [
    {
      x: dataHistory.labels,
      y: dataHistory.ph,
      name: "pH",
      mode: "lines+markers",
      line: { color: "blue" },
      marker: { size: 6 },
      customdata: dataHistory.dates.map((date, i) => [date, dataHistory.times[i]]),
      hovertemplate: "<b>pH: %{y}</b><br>Дата: %{customdata[0]}<br>Время: %{customdata[1]}<extra></extra>",
      hoverlabel: { bgcolor: "blue", font: { color: "white" } },
      visible: true
    },
    {
      x: dataHistory.labels,
      y: dataHistory.ec,
      name: "EC",
      mode: "lines+markers",
      line: { color: "blue" },
      marker: { size: 6 },
      customdata: dataHistory.dates.map((date, i) => [date, dataHistory.times[i]]),
      hovertemplate: "<b>EC: %{y}</b><br>Дата: %{customdata[0]}<br>Время: %{customdata[1]}<extra></extra>",
      hoverlabel: { bgcolor: "blue", font: { color: "white" } },
      visible: "legendonly"
    },
    {
      x: dataHistory.labels,
      y: dataHistory.ec_A_eep,
      name: "Насос A",
      mode: "lines+markers",
      line: { color: "green" },
      marker: { size: 6 },
      customdata: dataHistory.dates.map((date, i) => [date, dataHistory.times[i]]),
      hovertemplate: "<b>Насос A: %{y} сек.</b><br>Дата: %{customdata[0]}<br>Время: %{customdata[1]}<extra></extra>",
      hoverlabel: { bgcolor: "green", font: { color: "white" } },
      visible: "legendonly"
    },
    {
      x: dataHistory.labels,
      y: dataHistory.ec_B_eep,
      name: "Насос B",
      mode: "lines+markers",
      line: { color: "brown" },
      marker: { size: 6 },
      customdata: dataHistory.dates.map((date, i) => [date, dataHistory.times[i]]),
      hovertemplate: "<b>Насос B: %{y} сек.</b><br>Дата: %{customdata[0]}<br>Время: %{customdata[1]}<extra></extra>",
      hoverlabel: { bgcolor: "brown", font: { color: "white" } },
      visible: "legendonly"
    },
    {
      x: dataHistory.labels,
      y: dataHistory.ec_C_eep,
      name: "Насос C",
      mode: "lines+markers",
      line: { color: "orange" },
      marker: { size: 6 },
      customdata: dataHistory.dates.map((date, i) => [date, dataHistory.times[i]]),
      hovertemplate: "<b>Насос C: %{y} сек.</b><br>Дата: %{customdata[0]}<br>Время: %{customdata[1]}<extra></extra>",
      hoverlabel: { bgcolor: "orange", font: { color: "white" } },
      visible: "legendonly"
    },
    {
      x: dataHistory.labels,
      y: dataHistory.tS,
      name: "Т. раствора",
      mode: "lines+markers",
      line: { color: "purple" },
      marker: { size: 6 },
      customdata: dataHistory.dates.map((date, i) => [date, dataHistory.times[i]]),
      hovertemplate: "<b>Т. раствора: %{y}</b><br>Дата: %{customdata[0]}<br>Время: %{customdata[1]}<extra></extra>",
      hoverlabel: { bgcolor: "purple", font: { color: "white" } },
      visible: "legendonly"
    },
    {
      x: dataHistory.labels,
      y: dataHistory.tA,
      name: "Т. воздуха",
      mode: "lines+markers",
      line: { color: "purple" },
      marker: { size: 6 },
      customdata: dataHistory.dates.map((date, i) => [date, dataHistory.times[i]]),
      hovertemplate: "<b>Т. воздуха: %{y}</b><br>Дата: %{customdata[0]}<br>Время: %{customdata[1]}<extra></extra>",
      hoverlabel: { bgcolor: "purple", font: { color: "white" } },
      visible: "legendonly"
    },
    {
      x: dataHistory.labels,
      y: dataHistory.hDm,
      name: "Вл. воздуха",
      mode: "lines+markers",
      line: { color: "purple" },
      marker: { size: 6 },
      customdata: dataHistory.dates.map((date, i) => [date, dataHistory.times[i]]),
      hovertemplate: "<b>Вл. воздуха: %{y}</b><br>Дата: %{customdata[0]}<br>Время: %{customdata[1]}<extra></extra>",
      hoverlabel: { bgcolor: "purple", font: { color: "white" } },
      visible: "legendonly"
    },
    {
      x: dataHistory.labels,
      y: dataHistory.sVen,
      name: "Об. вентилятора",
      mode: "lines+markers",
      line: { color: "purple" },
      marker: { size: 6 },
      customdata: dataHistory.dates.map((date, i) => [date, dataHistory.times[i]]),
      hovertemplate: "<b>Об. вентилятора: %{y}</b><br>Дата: %{customdata[0]}<br>Время: %{customdata[1]}<extra></extra>",
      hoverlabel: { bgcolor: "purple", font: { color: "white" } },
      visible: "legendonly"
    }
  ];

  // Создаём график
  Plotly.newPlot("parametersChart", traces, layout);

  function updateValues(data) {
    document.getElementById("dey").textContent = data.dey;
    document.getElementById("wek").textContent = data.wek;
    document.getElementById("v_hid").textContent = data.v_hid;
    document.getElementById("v_min").textContent = data.v_min;
    document.getElementById("ph").textContent = data.ph;
    document.getElementById("ec").textContent = data.ec;
    document.getElementById("tS").textContent = data.tS;
    document.getElementById("tA").textContent = data.tA;
    document.getElementById("hDm").textContent = data.hDm;
    document.getElementById("sVen").textContent = data.sVen;
    document.getElementById("rFul").textContent = data.rFul;
    document.getElementById("rLi").textContent = data.rLi;
    document.getElementById("rWat").textContent = data.rWat;
    document.getElementById("rRas").textContent = data.rRas;
    document.getElementById("rPH").textContent = data.rPH;
    document.getElementById("rEC").textContent = data.rEC;
    document.getElementById("rSl").textContent = data.rSl;
    document.getElementById("rLe").textContent = data.rLe;
    document.getElementById("alW").textContent = data.alW;

    updateDataHistory(data);
    updateChart();
  }

  function updateDataHistory(data) {
  dataHistory.labels.push(dataHistory.labels.length);
  dataHistory.dates.push(data.date);
  dataHistory.times.push(data.time);
  dataHistory.ph.push(parseFloat(data.ph));
  dataHistory.ec.push(parseFloat(data.ec));
  dataHistory.ec_A_eep.push(parseFloat(data.ec_A_eep));
  dataHistory.ec_B_eep.push(parseFloat(data.ec_B_eep));
  dataHistory.ec_C_eep.push(parseFloat(data.ec_C_eep)); // Без || 0
  dataHistory.tS.push(parseFloat(data.tS));
  dataHistory.tA.push(parseFloat(data.tA));
  dataHistory.hDm.push(parseFloat(data.hDm));
  dataHistory.sVen.push(parseFloat(data.sVen));

  while (dataHistory.labels.length > maxPoints) {
    dataHistory.labels.shift();
    dataHistory.dates.shift();
    dataHistory.times.shift();
    dataHistory.ph.shift();
    dataHistory.ec.shift();
    dataHistory.ec_A_eep.shift();
    dataHistory.ec_B_eep.shift();
    dataHistory.ec_C_eep.shift();
    dataHistory.tS.shift();
    dataHistory.tA.shift();
    dataHistory.hDm.shift();
    dataHistory.sVen.shift();
  }

  dataHistory.labels = Array.from({ length: dataHistory.labels.length }, (_, i) => i);
}

  function updateChart() {
    const customdata = dataHistory.dates.map((date, i) => [date, dataHistory.times[i]]);
    Plotly.update("parametersChart", {
      x: [
        dataHistory.labels,
        dataHistory.labels,
        dataHistory.labels,
        dataHistory.labels,
        dataHistory.labels,
        dataHistory.labels,
        dataHistory.labels,
        dataHistory.labels,
        dataHistory.labels
      ],
      y: [
        dataHistory.ph,
        dataHistory.ec,
        dataHistory.ec_A_eep,
        dataHistory.ec_B_eep,
        dataHistory.ec_C_eep,
        dataHistory.tS,
        dataHistory.tA,
        dataHistory.hDm,
        dataHistory.sVen
      ],
      customdata: [
        customdata,
        customdata,
        customdata,
        customdata,
        customdata,
        customdata,
        customdata,
        customdata,
        customdata
      ]
    });
  }

  function fetchValues() {
    var xhr = new XMLHttpRequest();
    xhr.open("GET", "/online_api", true);
    xhr.setRequestHeader("Content-Type", "application/json");
    xhr.onreadystatechange = function () {
      if (xhr.readyState === 4 && xhr.status === 200) {
        var response = JSON.parse(xhr.responseText);
        updateValues(response);
      }
    };
    xhr.send();
  }

  // Обработчик изменения периода
  document.getElementById("periodSelect").addEventListener("change", function() {
    maxPoints = parseInt(this.value);
    while (dataHistory.labels.length > maxPoints) {
      dataHistory.labels.shift();
      dataHistory.dates.shift();
      dataHistory.times.shift();
      dataHistory.ph.shift();
      dataHistory.ec.shift();
      dataHistory.ec_A_eep.shift();
      dataHistory.ec_B_eep.shift();
      dataHistory.ec_C_eep.shift();
      dataHistory.tS.shift();
      dataHistory.tA.shift();
      dataHistory.hDm.shift();
      dataHistory.sVen.shift();
    }
    dataHistory.labels = Array.from({ length: dataHistory.labels.length }, (_, i) => i);
    updateChart();
  });

  // Первый запрос и периодическое обновление
  window.onload = function() {
    fetchValues();
    setInterval(fetchValues, 10000);
  };
</script>

  
</body>
</html>