Spaces:
Sleeping
Sleeping
| <html lang="ru"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <link rel="icon" type="image/ico" href="https://huggingface.co/spaces/igs-img/stor/resolve/main/list.ico"> | |
| <title>Графики pH и EC</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.plot.ly/plotly-2.32.0.min.js"></script> | |
| <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script> | |
| <style> | |
| body { | |
| display: flex; | |
| flex-direction: column; | |
| align-items: center; | |
| margin: 0; | |
| padding: 0; | |
| } | |
| .container { | |
| width: 100%; | |
| max-width: 100%; | |
| } | |
| /* Шапка */ | |
| .header { | |
| width: 100%; | |
| padding: 0px 0; /* Убраны отступы справа и слева */ | |
| display: flex; | |
| justify-content: space-between; | |
| align-items: center; | |
| background-color: #f8f9fa; | |
| border-bottom: 1px solid #ddd; | |
| } | |
| /* Кнопки и лейбл в шапке */ | |
| .header .buttons, | |
| .header .label { | |
| margin: 0; /* Полностью убраны отступы */ | |
| } | |
| /* Контейнер графика */ | |
| .graph-container { | |
| width: 100%; | |
| margin-bottom: 30px; | |
| } | |
| /* График */ | |
| .graph { | |
| width: 100%; | |
| height: 500px; | |
| max-width: 100%; | |
| } | |
| /* Сообщение "нет данных" */ | |
| .no-data-message { | |
| font-size: 18px; | |
| color: red; | |
| text-align: center; | |
| margin-top: 20px; | |
| } | |
| /* Кнопки переключения недель */ | |
| .week-buttons { | |
| display: flex; | |
| justify-content: center; | |
| margin: 20px 0; | |
| } | |
| /* Адаптивность для телефонов (до 768px) */ | |
| @media (max-width: 768px) { | |
| .header { | |
| flex-direction: column; /* Кнопки и лейбл станут в колонку */ | |
| align-items: center; | |
| } | |
| .graph-container { | |
| margin-bottom: 45px; /* Увеличен отступ между графиками */ | |
| } | |
| .graph { | |
| height: 330px; /* Увеличена высота графика */ | |
| } | |
| } | |
| /* Адаптивность для маленьких телефонов (до 480px) */ | |
| @media (max-width: 480px) { | |
| .graph-container { | |
| margin-bottom: 50px; /* Ещё больше отступ между графиками */ | |
| } | |
| .graph { | |
| height: 280px; /* Ещё немного увеличил высоту */ | |
| } | |
| } | |
| #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 ; | |
| } | |
| </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 w-100"> | |
| <div class="container"> | |
| <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-outline-success" type="button">Онлайн</button> | |
| <button id="st_set" class="btn btn-outline-success" type="button">Настройки</button> | |
| <button id="st_plot" class="btn btn-success" type="button">Графики</button> | |
| <button id="st_table" class="btn btn-outline-success" type="button">Таблица</button> | |
| </form> | |
| </div> | |
| </nav> | |
| <div class="container text-center mt-3"> | |
| <h1>Графики за <span id="week_number">{{ week_number }}</span>-ю неделю</h1> | |
| </div> | |
| <!-- Кнопки переключения недель --> | |
| <div class="week-buttons"> | |
| <button id="prev_week" class="btn btn-success mr-2" onclick="navigateWeek(-1)">Предыдущая неделя</button> | |
| <button id="next_week" class="btn btn-success" onclick="navigateWeek(1)">Следующая неделя</button> | |
| </div> | |
| {% if data %} | |
| <div class="container"> | |
| <div class="graph-container"><div class="graph" id="ph_chart"></div></div> | |
| <div class="graph-container"><div class="graph" id="ec_chart"></div></div> | |
| <div class="graph-container"><div class="graph" id="pump_chart"></div></div> | |
| <div class="graph-container"><div class="graph" id="ts_chart"></div></div> | |
| <div class="graph-container"><div class="graph" id="ta_chart"></div></div> | |
| <div class="graph-container"><div class="graph" id="hdm_chart"></div></div> | |
| <div class="graph-container"><div class="graph" id="sven_chart"></div></div> | |
| </div> | |
| <script> | |
| const data = {{ data | tojson }}; | |
| function createChart(id, yData, title, yLabel, color, parameterName, unit) { | |
| Plotly.newPlot(id, [{ | |
| x: data.dates, | |
| y: yData, | |
| type: "scatter", | |
| mode: "lines+markers", | |
| line: { color: color }, | |
| hovertemplate: data.days_of_week.map((day, index) => | |
| `Неделя: ${data.week}<br>День: ${day}<br>Время системы: ${data.sus[index]}<br>${parameterName}: %{y} ${unit}<br>Дата: ${data.dates[index]}<extra></extra>` | |
| ) | |
| }], { | |
| title: title, | |
| xaxis: { title: "", showticklabels: false }, | |
| yaxis: { title: yLabel, titlefont: { size: 14 } }, | |
| hovermode: "closest", | |
| showlegend: false | |
| }); | |
| } | |
| // Создание графиков с правильными подсказками | |
| createChart("ph_chart", data.ph, `График pH за ${data.week}-ю неделю`, "Уровень pH", "blue", "pH", ""); | |
| createChart("ec_chart", data.ec, `График EC за ${data.week}-ю неделю`, "Уровень EC", "blue", "EC", "мкСм/см"); | |
| createChart("ts_chart", data.tS, `Температура раствора за ${data.week}-ю неделю`, "Температура (°C)", "purple", "Температура раствора", "°C"); | |
| createChart("ta_chart", data.tA, `Температура воздуха за ${data.week}-ю неделю`, "Температура (°C)", "purple", "Температура воздуха", "°C"); | |
| createChart("hdm_chart", data.hDm, `Влажность воздуха за ${data.week}-ю неделю`, "Влажность (%)", "purple", "Влажность воздуха", "%"); | |
| createChart("sven_chart", data.sVen, `Обороты вентилятора за ${data.week}-ю неделю`, "Обороты (%)", "purple", "Обороты вентилятора", "%"); | |
| // График насосов | |
| Plotly.newPlot("pump_chart", [ | |
| { | |
| x: data.dates, | |
| y: data.onA, | |
| type: "scatter", | |
| mode: "lines+markers", | |
| line: { color: "green" }, | |
| hovertemplate: data.days_of_week.map((day, index) => | |
| `Неделя: ${data.week}<br>День: ${day}<br>Время системы: ${data.sus[index]}<br>Насос A: %{y} сек.<br>Дата: ${data.dates[index]}<extra></extra>` | |
| ) | |
| }, | |
| { | |
| x: data.dates, | |
| y: data.onB, | |
| type: "scatter", | |
| mode: "lines+markers", | |
| line: { color: "brown" }, | |
| hovertemplate: data.days_of_week.map((day, index) => | |
| `Неделя: ${data.week}<br>День: ${day}<br>Время системы: ${data.sus[index]}<br>Насос B: %{y} сек.<br>Дата: ${data.dates[index]}<extra></extra>` | |
| ) | |
| }, | |
| { | |
| x: data.dates, | |
| y: data.onC, | |
| type: "scatter", | |
| mode: "lines+markers", | |
| line: { color: "orange" }, | |
| hovertemplate: data.days_of_week.map((day, index) => | |
| `Неделя: ${data.week}<br>День: ${day}<br>Время системы: ${data.sus[index]}<br>Насос C: %{y} сек.<br>Дата: ${data.dates[index]}<extra></extra>` | |
| ) | |
| } | |
| ], { | |
| title: `Интервал дозирования насосов для ${data.week}-ой недели`, | |
| xaxis: { title: "", showticklabels: false }, | |
| yaxis: { title: "Время ВКЛ(сек.)" }, | |
| hovermode: "closest", | |
| showlegend: false | |
| }); | |
| </script> | |
| {% else %} | |
| <div class="no-data-message"> | |
| {{ message if message else 'Данных за эту неделю нет в базе данных.' }} | |
| </div> | |
| {% endif %} | |
| <script> | |
| let weekNumber = {{ week_number }}; | |
| function navigateWeek(change) { | |
| const newWeek = weekNumber + change; | |
| if (newWeek >= 1 && newWeek <= 30) { | |
| window.location.href = `/plot_week?week=${newWeek}`; | |
| } | |
| } | |
| </script> | |
| <script> | |
| document.getElementById("st_onl").addEventListener("click", function() { | |
| var baseUrl = window.location.origin; | |
| var targetUrl = baseUrl + "/online"; | |
| window.location.href = targetUrl; | |
| }); | |
| </script> | |
| <script> | |
| document.getElementById("st_set").addEventListener("click", function() { | |
| var baseUrl = window.location.origin; | |
| var targetUrl = baseUrl + "/settings"; | |
| window.location.href = targetUrl; | |
| }); | |
| </script> | |
| <script> | |
| document.getElementById("st_plot").addEventListener("click", function() { | |
| var baseUrl = window.location.origin; | |
| var targetUrl = baseUrl + "/plot_week"; | |
| 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> | |
| </body> | |
| </html> |