flask_inference_api_g / online.html
DmitrMakeev's picture
Update online.html
6786391 verified
<!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>