Update online.html
Browse files- online.html +62 -34
online.html
CHANGED
@@ -261,7 +261,18 @@ document.addEventListener("DOMContentLoaded", function () {
|
|
261 |
|
262 |
|
263 |
<div class="container text-center">
|
264 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
265 |
<div id="parametersChart" style="width: 100%; height: 400px;"></div>
|
266 |
</div>
|
267 |
|
@@ -466,11 +477,11 @@ document.getElementById("but_sliv").addEventListener("click", function() {
|
|
466 |
|
467 |
|
468 |
<script>
|
469 |
-
// Объект для хранения истории данных
|
470 |
let dataHistory = {
|
471 |
-
labels: [],
|
472 |
-
dates: [],
|
473 |
-
times: [],
|
474 |
ph: [],
|
475 |
ec: [],
|
476 |
tS: [],
|
@@ -479,16 +490,19 @@ document.getElementById("but_sliv").addEventListener("click", function() {
|
|
479 |
sVen: []
|
480 |
};
|
481 |
|
|
|
|
|
|
|
482 |
// Инициализация графика Plotly
|
483 |
const layout = {
|
484 |
-
title: "",
|
485 |
xaxis: {
|
486 |
-
showticklabels: false
|
487 |
},
|
488 |
yaxis: { title: "Значения" },
|
489 |
showlegend: true,
|
490 |
height: 400,
|
491 |
-
hovermode: "closest"
|
492 |
};
|
493 |
|
494 |
const traces = [
|
@@ -496,81 +510,80 @@ document.getElementById("but_sliv").addEventListener("click", function() {
|
|
496 |
x: dataHistory.labels,
|
497 |
y: dataHistory.ph,
|
498 |
name: "pH",
|
499 |
-
mode: "lines+markers",
|
500 |
line: { color: "blue" },
|
501 |
-
marker: { size: 6 },
|
502 |
customdata: dataHistory.dates.map((date, i) => [date, dataHistory.times[i]]),
|
503 |
hovertemplate: "<b>pH: %{y}</b><br>Дата: %{customdata[0]}<br>Время: %{customdata[1]}<extra></extra>",
|
504 |
hoverlabel: { bgcolor: "blue", font: { color: "white" } },
|
505 |
-
visible: true
|
506 |
},
|
507 |
{
|
508 |
x: dataHistory.labels,
|
509 |
y: dataHistory.ec,
|
510 |
name: "EC",
|
511 |
-
mode: "lines+markers",
|
512 |
line: { color: "green" },
|
513 |
marker: { size: 6 },
|
514 |
customdata: dataHistory.dates.map((date, i) => [date, dataHistory.times[i]]),
|
515 |
hovertemplate: "<b>EC: %{y}</b><br>Дата: %{customdata[0]}<br>Время: %{customdata[1]}<extra></extra>",
|
516 |
hoverlabel: { bgcolor: "green", font: { color: "white" } },
|
517 |
-
visible: "legendonly"
|
518 |
},
|
519 |
{
|
520 |
x: dataHistory.labels,
|
521 |
y: dataHistory.tS,
|
522 |
name: "Т. раствора",
|
523 |
-
mode: "lines+markers",
|
524 |
line: { color: "red" },
|
525 |
marker: { size: 6 },
|
526 |
customdata: dataHistory.dates.map((date, i) => [date, dataHistory.times[i]]),
|
527 |
hovertemplate: "<b>Т. раствора: %{y}</b><br>Дата: %{customdata[0]}<br>Время: %{customdata[1]}<extra></extra>",
|
528 |
hoverlabel: { bgcolor: "red", font: { color: "white" } },
|
529 |
-
visible: "legendonly"
|
530 |
},
|
531 |
{
|
532 |
x: dataHistory.labels,
|
533 |
y: dataHistory.tA,
|
534 |
name: "Т. воздуха",
|
535 |
-
mode: "lines+markers",
|
536 |
line: { color: "orange" },
|
537 |
marker: { size: 6 },
|
538 |
customdata: dataHistory.dates.map((date, i) => [date, dataHistory.times[i]]),
|
539 |
hovertemplate: "<b>Т. воздуха: %{y}</b><br>Дата: %{customdata[0]}<br>Время: %{customdata[1]}<extra></extra>",
|
540 |
hoverlabel: { bgcolor: "orange", font: { color: "white" } },
|
541 |
-
visible: "legendonly"
|
542 |
},
|
543 |
{
|
544 |
x: dataHistory.labels,
|
545 |
y: dataHistory.hDm,
|
546 |
name: "Вл. воздуха",
|
547 |
-
mode: "lines+markers",
|
548 |
line: { color: "purple" },
|
549 |
marker: { size: 6 },
|
550 |
customdata: dataHistory.dates.map((date, i) => [date, dataHistory.times[i]]),
|
551 |
hovertemplate: "<b>Вл. воз��уха: %{y}</b><br>Дата: %{customdata[0]}<br>Время: %{customdata[1]}<extra></extra>",
|
552 |
hoverlabel: { bgcolor: "purple", font: { color: "white" } },
|
553 |
-
visible: "legendonly"
|
554 |
},
|
555 |
{
|
556 |
x: dataHistory.labels,
|
557 |
y: dataHistory.sVen,
|
558 |
name: "Об. вентилятора",
|
559 |
-
mode: "lines+markers",
|
560 |
line: { color: "brown" },
|
561 |
marker: { size: 6 },
|
562 |
customdata: dataHistory.dates.map((date, i) => [date, dataHistory.times[i]]),
|
563 |
hovertemplate: "<b>Об. вентилятора: %{y}</b><br>Дата: %{customdata[0]}<br>Время: %{customdata[1]}<extra></extra>",
|
564 |
hoverlabel: { bgcolor: "brown", font: { color: "white" } },
|
565 |
-
visible: "legendonly"
|
566 |
}
|
567 |
];
|
568 |
|
569 |
-
// Создаём график
|
570 |
Plotly.newPlot("parametersChart", traces, layout);
|
571 |
|
572 |
function updateValues(data) {
|
573 |
-
// Обновляем текстовые элементы
|
574 |
document.getElementById("dey").textContent = data.dey;
|
575 |
document.getElementById("wek").textContent = data.wek;
|
576 |
document.getElementById("v_hid").textContent = data.v_hid;
|
@@ -591,16 +604,15 @@ document.getElementById("but_sliv").addEventListener("click", function() {
|
|
591 |
document.getElementById("rLe").textContent = data.rLe;
|
592 |
document.getElementById("alW").textContent = data.alW;
|
593 |
|
594 |
-
// Обновляем историю данных и график
|
595 |
updateDataHistory(data);
|
596 |
updateChart();
|
597 |
}
|
598 |
|
599 |
function updateDataHistory(data) {
|
600 |
// Добавляем новые значения
|
601 |
-
dataHistory.labels.push(dataHistory.labels.length);
|
602 |
-
dataHistory.dates.push(data.date);
|
603 |
-
dataHistory.times.push(data.time);
|
604 |
dataHistory.ph.push(parseFloat(data.ph) || 0);
|
605 |
dataHistory.ec.push(parseFloat(data.ec) || 0);
|
606 |
dataHistory.tS.push(parseFloat(data.tS) || 0);
|
@@ -608,8 +620,8 @@ document.getElementById("but_sliv").addEventListener("click", function() {
|
|
608 |
dataHistory.hDm.push(parseFloat(data.hDm) || 0);
|
609 |
dataHistory.sVen.push(parseFloat(data.sVen) || 0);
|
610 |
|
611 |
-
//
|
612 |
-
if (dataHistory.labels.length >
|
613 |
dataHistory.labels.shift();
|
614 |
dataHistory.dates.shift();
|
615 |
dataHistory.times.shift();
|
@@ -623,7 +635,6 @@ document.getElementById("but_sliv").addEventListener("click", function() {
|
|
623 |
}
|
624 |
|
625 |
function updateChart() {
|
626 |
-
// Обновляем данные графика
|
627 |
const customdata = dataHistory.dates.map((date, i) => [date, dataHistory.times[i]]);
|
628 |
Plotly.update("parametersChart", {
|
629 |
x: [
|
@@ -666,17 +677,34 @@ document.getElementById("but_sliv").addEventListener("click", function() {
|
|
666 |
xhr.send();
|
667 |
}
|
668 |
|
669 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
670 |
window.onload = function() {
|
671 |
-
fetchValues();
|
672 |
-
setInterval(fetchValues, 10000);
|
673 |
};
|
674 |
</script>
|
675 |
|
676 |
|
677 |
|
678 |
|
679 |
-
|
680 |
|
681 |
</body>
|
682 |
</html>
|
|
|
261 |
|
262 |
|
263 |
<div class="container text-center">
|
264 |
+
<div class="d-flex justify-content-between align-items-center mb-3">
|
265 |
+
<h3>График параметров</h3>
|
266 |
+
<div>
|
267 |
+
<label for="periodSelect">Период: </label>
|
268 |
+
<select id="periodSelect" class="form-select" style="width: auto; display: inline-block;">
|
269 |
+
<option value="6">10 минут (60 точек)</option>
|
270 |
+
<option value="120">20 минут (120 точек)</option>
|
271 |
+
<option value="180">30 минут (180 точек)</option>
|
272 |
+
<option value="360">1 час (360 точек)</option>
|
273 |
+
</select>
|
274 |
+
</div>
|
275 |
+
</div>
|
276 |
<div id="parametersChart" style="width: 100%; height: 400px;"></div>
|
277 |
</div>
|
278 |
|
|
|
477 |
|
478 |
|
479 |
<script>
|
480 |
+
// Объект для хранения истории данных
|
481 |
let dataHistory = {
|
482 |
+
labels: [],
|
483 |
+
dates: [],
|
484 |
+
times: [],
|
485 |
ph: [],
|
486 |
ec: [],
|
487 |
tS: [],
|
|
|
490 |
sVen: []
|
491 |
};
|
492 |
|
493 |
+
// Максимальное количество точек (по умолчанию 60)
|
494 |
+
let maxPoints = 60;
|
495 |
+
|
496 |
// Инициализация графика Plotly
|
497 |
const layout = {
|
498 |
+
title: "График последних значений параметров",
|
499 |
xaxis: {
|
500 |
+
showticklabels: false
|
501 |
},
|
502 |
yaxis: { title: "Значения" },
|
503 |
showlegend: true,
|
504 |
height: 400,
|
505 |
+
hovermode: "closest"
|
506 |
};
|
507 |
|
508 |
const traces = [
|
|
|
510 |
x: dataHistory.labels,
|
511 |
y: dataHistory.ph,
|
512 |
name: "pH",
|
513 |
+
mode: "lines+markers",
|
514 |
line: { color: "blue" },
|
515 |
+
marker: { size: 6 },
|
516 |
customdata: dataHistory.dates.map((date, i) => [date, dataHistory.times[i]]),
|
517 |
hovertemplate: "<b>pH: %{y}</b><br>Дата: %{customdata[0]}<br>Время: %{customdata[1]}<extra></extra>",
|
518 |
hoverlabel: { bgcolor: "blue", font: { color: "white" } },
|
519 |
+
visible: true
|
520 |
},
|
521 |
{
|
522 |
x: dataHistory.labels,
|
523 |
y: dataHistory.ec,
|
524 |
name: "EC",
|
525 |
+
mode: "lines+markers",
|
526 |
line: { color: "green" },
|
527 |
marker: { size: 6 },
|
528 |
customdata: dataHistory.dates.map((date, i) => [date, dataHistory.times[i]]),
|
529 |
hovertemplate: "<b>EC: %{y}</b><br>Дата: %{customdata[0]}<br>Время: %{customdata[1]}<extra></extra>",
|
530 |
hoverlabel: { bgcolor: "green", font: { color: "white" } },
|
531 |
+
visible: "legendonly"
|
532 |
},
|
533 |
{
|
534 |
x: dataHistory.labels,
|
535 |
y: dataHistory.tS,
|
536 |
name: "Т. раствора",
|
537 |
+
mode: "lines+markers",
|
538 |
line: { color: "red" },
|
539 |
marker: { size: 6 },
|
540 |
customdata: dataHistory.dates.map((date, i) => [date, dataHistory.times[i]]),
|
541 |
hovertemplate: "<b>Т. раствора: %{y}</b><br>Дата: %{customdata[0]}<br>Время: %{customdata[1]}<extra></extra>",
|
542 |
hoverlabel: { bgcolor: "red", font: { color: "white" } },
|
543 |
+
visible: "legendonly"
|
544 |
},
|
545 |
{
|
546 |
x: dataHistory.labels,
|
547 |
y: dataHistory.tA,
|
548 |
name: "Т. воздуха",
|
549 |
+
mode: "lines+markers",
|
550 |
line: { color: "orange" },
|
551 |
marker: { size: 6 },
|
552 |
customdata: dataHistory.dates.map((date, i) => [date, dataHistory.times[i]]),
|
553 |
hovertemplate: "<b>Т. воздуха: %{y}</b><br>Дата: %{customdata[0]}<br>Время: %{customdata[1]}<extra></extra>",
|
554 |
hoverlabel: { bgcolor: "orange", font: { color: "white" } },
|
555 |
+
visible: "legendonly"
|
556 |
},
|
557 |
{
|
558 |
x: dataHistory.labels,
|
559 |
y: dataHistory.hDm,
|
560 |
name: "Вл. воздуха",
|
561 |
+
mode: "lines+markers",
|
562 |
line: { color: "purple" },
|
563 |
marker: { size: 6 },
|
564 |
customdata: dataHistory.dates.map((date, i) => [date, dataHistory.times[i]]),
|
565 |
hovertemplate: "<b>Вл. воз��уха: %{y}</b><br>Дата: %{customdata[0]}<br>Время: %{customdata[1]}<extra></extra>",
|
566 |
hoverlabel: { bgcolor: "purple", font: { color: "white" } },
|
567 |
+
visible: "legendonly"
|
568 |
},
|
569 |
{
|
570 |
x: dataHistory.labels,
|
571 |
y: dataHistory.sVen,
|
572 |
name: "Об. вентилятора",
|
573 |
+
mode: "lines+markers",
|
574 |
line: { color: "brown" },
|
575 |
marker: { size: 6 },
|
576 |
customdata: dataHistory.dates.map((date, i) => [date, dataHistory.times[i]]),
|
577 |
hovertemplate: "<b>Об. вентилятора: %{y}</b><br>Дата: %{customdata[0]}<br>Время: %{customdata[1]}<extra></extra>",
|
578 |
hoverlabel: { bgcolor: "brown", font: { color: "white" } },
|
579 |
+
visible: "legendonly"
|
580 |
}
|
581 |
];
|
582 |
|
583 |
+
// Создаём график
|
584 |
Plotly.newPlot("parametersChart", traces, layout);
|
585 |
|
586 |
function updateValues(data) {
|
|
|
587 |
document.getElementById("dey").textContent = data.dey;
|
588 |
document.getElementById("wek").textContent = data.wek;
|
589 |
document.getElementById("v_hid").textContent = data.v_hid;
|
|
|
604 |
document.getElementById("rLe").textContent = data.rLe;
|
605 |
document.getElementById("alW").textContent = data.alW;
|
606 |
|
|
|
607 |
updateDataHistory(data);
|
608 |
updateChart();
|
609 |
}
|
610 |
|
611 |
function updateDataHistory(data) {
|
612 |
// Добавляем новые значения
|
613 |
+
dataHistory.labels.push(dataHistory.labels.length);
|
614 |
+
dataHistory.dates.push(data.date);
|
615 |
+
dataHistory.times.push(data.time);
|
616 |
dataHistory.ph.push(parseFloat(data.ph) || 0);
|
617 |
dataHistory.ec.push(parseFloat(data.ec) || 0);
|
618 |
dataHistory.tS.push(parseFloat(data.tS) || 0);
|
|
|
620 |
dataHistory.hDm.push(parseFloat(data.hDm) || 0);
|
621 |
dataHistory.sVen.push(parseFloat(data.sVen) || 0);
|
622 |
|
623 |
+
// Обрезаем массив, если он превышает maxPoints
|
624 |
+
if (dataHistory.labels.length > maxPoints) {
|
625 |
dataHistory.labels.shift();
|
626 |
dataHistory.dates.shift();
|
627 |
dataHistory.times.shift();
|
|
|
635 |
}
|
636 |
|
637 |
function updateChart() {
|
|
|
638 |
const customdata = dataHistory.dates.map((date, i) => [date, dataHistory.times[i]]);
|
639 |
Plotly.update("parametersChart", {
|
640 |
x: [
|
|
|
677 |
xhr.send();
|
678 |
}
|
679 |
|
680 |
+
// Обработчик изменения периода в выпадающем списке
|
681 |
+
document.getElementById("periodSelect").addEventListener("change", function() {
|
682 |
+
maxPoints = parseInt(this.value); // Обновляем максимальное количество точек
|
683 |
+
// Обрезаем существующие данные до нового лимита
|
684 |
+
while (dataHistory.labels.length > maxPoints) {
|
685 |
+
dataHistory.labels.shift();
|
686 |
+
dataHistory.dates.shift();
|
687 |
+
dataHistory.times.shift();
|
688 |
+
dataHistory.ph.shift();
|
689 |
+
dataHistory.ec.shift();
|
690 |
+
dataHistory.tS.shift();
|
691 |
+
dataHistory.tA.shift();
|
692 |
+
dataHistory.hDm.shift();
|
693 |
+
dataHistory.sVen.shift();
|
694 |
+
}
|
695 |
+
updateChart(); // Перерисовываем график с новым количеством точек
|
696 |
+
});
|
697 |
+
|
698 |
+
// Первый запрос и периодическое обновление
|
699 |
window.onload = function() {
|
700 |
+
fetchValues();
|
701 |
+
setInterval(fetchValues, 10000);
|
702 |
};
|
703 |
</script>
|
704 |
|
705 |
|
706 |
|
707 |
|
|
|
708 |
|
709 |
</body>
|
710 |
</html>
|