File size: 9,047 Bytes
dfaa01c
 
 
f38fe6b
 
 
dfaa01c
f38fe6b
 
dfaa01c
f38fe6b
5a8a266
3326d90
 
 
 
 
 
 
 
7656369
5a822a6
3326d90
 
 
 
5380887
3326d90
 
 
 
 
 
 
 
 
5380887
3326d90
5a8a266
3326d90
 
 
 
5a8a266
3326d90
 
 
5a8a266
3326d90
5a8a266
3326d90
 
 
 
 
 
 
 
 
 
 
 
5a8a266
 
 
5380887
5a8a266
 
e05bbb9
5380887
e05bbb9
5a8a266
5380887
5a8a266
 
 
 
e05bbb9
5380887
e05bbb9
5a8a266
5380887
5a8a266
 
 
dfaa01c
 
f38fe6b
 
 
 
 
 
 
 
 
3198e17
 
 
f38fe6b
 
efb1a44
ee71bfe
f38fe6b
2e718cc
f38fe6b
2e718cc
f38fe6b
 
 
 
 
dfaa01c
f38fe6b
 
ee71bfe
 
 
 
 
 
 
f38fe6b
aa4fd06
f38fe6b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57d4827
f38fe6b
0dada52
f38fe6b
0dada52
f38fe6b
5380887
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dfaa01c
f38fe6b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f38e889
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6cdfbe7
 
 
 
 
 
 
dfaa01c
f38fe6b
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
<!DOCTYPE html>
<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-latest.min.js"></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: 5px 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;
    }
}
</style>
</head>
<body>

<!-- Навигационная панель -->
<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 mr-2" 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) {
            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>${yLabel}: %{y}<br>Дата: ${data.dates[index]}`
                )
            }], {
                title: title,
                xaxis: { title: "", showticklabels: false },
                yaxis: { title: yLabel, titlefont: { size: 14 } },
                hovermode: "closest",
                showlegend: false
            });
        }
        function updateCharts() {
            $.get("/plot_week?week=" + {{ week_number }}, function(data) {
                // Обновление графиков с новыми данными
                createChart("ph_chart", data.ph, `График pH за ${data.week}-ю неделю`, "Уровень pH", "blue");
                createChart("ec_chart", data.ec, `График EC за ${data.week}-ю неделю`, "Уровень EC", "blue");
                createChart("ts_chart", data.tS, `Температура раствора за ${data.week}-ю неделю`, "Температура (°C)", "purple");
                createChart("ta_chart", data.tA, `Температура воздуха за ${data.week}-ю неделю`, "Температура (°C)", "purple");
                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>Насос A: %{y} сек.<br>Дата: ${data.dates[index]}`
                        )
                    },
                    {
                        x: data.dates,
                        y: data.onB,
                        type: "scatter",
                        mode: "lines+markers",
                        line: { color: "brown" },
                        hovertemplate: data.days_of_week.map((day, index) =>
                            `День: ${day}<br>Насос B: %{y} сек.<br>Дата: ${data.dates[index]}`
                        )
                    },
                    {
                        x: data.dates,
                        y: data.onC,
                        type: "scatter",
                        mode: "lines+markers",
                        line: { color: "orange" },
                        hovertemplate: data.days_of_week.map((day, index) =>
                            `День: ${day}<br>Насос C: %{y} сек.<br>Дата: ${data.dates[index]}`
                        )
                    }
                ], {
                    title: `Интервал дозирования насосов для ${data.week}-ой недели`,
                    xaxis: { title: "", showticklabels: false },
                    yaxis: { title: "Время ВКЛ(сек.)" },
                    hovermode: "closest",
                    showlegend: false
                });
            });
        }
        
        setInterval(updateCharts, 10000); // Обновление графиков каждые 10 секунд
    </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>
</body>
</html>