File size: 12,205 Bytes
0b91a54 | 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 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Live Irrigation Status | Plant Disease Detector</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<!-- Google Fonts - Outfit -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&display=swap" rel="stylesheet">
<!-- Bootstrap Icons -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<style>
/* ===== Color System ===== */
:root {
--deep-green: #1a5d3a;
--accent-green: #198754;
--darker-accent: #143d2e;
--bg-color: #f8f9fa;
--surface: #ffffff;
--text-dark: #212529;
--text-muted: #6c757d;
--border-color: #dee2e6;
}
/* ===== Typography ===== */
body {
font-family: 'Outfit', sans-serif;
background-color: var(--bg-color);
color: var(--text-dark);
font-weight: 400;
}
h1, h2, h3, h4, h5, h6 {
font-weight: 600;
}
/* ===== Header ===== */
.page-header {
background-color: var(--deep-green);
color: white;
padding: 2rem 0;
margin-bottom: 2rem;
}
.page-header h1 {
font-weight: 700;
font-size: 2rem;
margin: 0;
}
/* ===== Diagnostic Timeline (Results Page Exclusive) ===== */
.diagnostic-timeline {
display: flex;
justify-content: center;
align-items: center;
gap: 1.5rem;
margin: 2rem 0;
position: relative;
}
.timeline-step {
display: flex;
flex-direction: column;
align-items: center;
gap: 0.5rem;
position: relative;
z-index: 2;
}
.timeline-icon {
width: 50px;
height: 50px;
border-radius: 50%;
background-color: var(--accent-green);
color: white;
display: flex;
align-items: center;
justify-content: center;
font-size: 1.5rem;
box-shadow: 0 4px 12px rgba(25, 135, 84, 0.3);
}
.timeline-label {
font-weight: 500;
font-size: 0.85rem;
color: var(--text-dark);
}
.timeline-connector {
flex: 1;
height: 2px;
background-color: var(--accent-green);
margin: 0 -0.5rem;
position: relative;
top: -15px;
}
/* ===== Cards ===== */
.card {
background: var(--surface);
border-radius: 20px;
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.08);
border: none;
margin-bottom: 1.5rem;
}
.card-header {
background-color: var(--deep-green);
color: white;
font-weight: 600;
font-size: 1.25rem;
padding: 1rem 1.5rem;
border-radius: 20px 20px 0 0;
text-align: center;
}
.card-body {
padding: 2rem;
}
/* ===== Status Cards ===== */
.status-card {
text-align: center;
}
.status-label {
font-size: 1rem;
color: var(--text-muted);
font-weight: 500;
margin-bottom: 0.5rem;
}
.status-text {
font-size: 1.75rem;
font-weight: 600;
padding: 0.75rem 1.5rem;
border-radius: 12px;
display: inline-block;
transition: all 0.3s ease;
}
.status-text.on {
color: var(--accent-green);
background-color: #e9f5e9;
border: 2px solid var(--accent-green);
}
.status-text.off {
color: #dc3545;
background-color: #f8d7da;
border: 2px solid #dc3545;
}
/* ===== Chart Container ===== */
.chart-container {
width: 100%;
height: 400px;
}
/* ===== Responsive ===== */
@media (max-width: 768px) {
.page-header h1 {
font-size: 1.5rem;
}
.diagnostic-timeline {
gap: 1rem;
}
.timeline-connector {
display: none;
}
.card-body {
padding: 1.5rem;
}
}
</style>
</head>
<body>
<!-- Page Header -->
<div class="page-header">
<div class="container">
<h1><i class="bi bi-droplet-fill"></i> Live Irrigation Status</h1>
</div>
</div>
<div class="container">
<!-- Diagnostic Timeline (Results Page Exclusive) -->
<div class="diagnostic-timeline">
<div class="timeline-step">
<div class="timeline-icon">
<i class="bi bi-search"></i>
</div>
<div class="timeline-label">Monitor</div>
</div>
<div class="timeline-connector"></div>
<div class="timeline-step">
<div class="timeline-icon">
<i class="bi bi-graph-up"></i>
</div>
<div class="timeline-label">Analyze</div>
</div>
<div class="timeline-connector"></div>
<div class="timeline-step">
<div class="timeline-icon">
<i class="bi bi-gear-fill"></i>
</div>
<div class="timeline-label">Control</div>
</div>
</div>
<!-- Main Content Card -->
<div class="card">
<div class="card-header">Real-Time Irrigation Dashboard</div>
<div class="card-body">
<div class="row text-center mb-4">
<div class="col-md-6">
<div class="status-label">Current Pump Status</div>
<div id="pumpStatus" class="status-text off">Loading...</div>
</div>
<div class="col-md-6 mt-3 mt-md-0">
<div class="status-label">Time Elapsed</div>
<div id="time-counter" class="status-text" style="color: #5a2d0c; background-color: #f0e6e0; border-color: #5a2d0c;">0 seconds</div>
</div>
</div>
<div class="row">
<div class="col-lg-6 mb-4">
<div class="card h-100">
<div class="card-body">
<div id="gauge" class="chart-container"></div>
</div>
</div>
</div>
<div class="col-lg-6 mb-4">
<div class="card h-100">
<div class="card-body">
<div id="graph1" class="chart-container"></div>
</div>
</div>
</div>
<div class="col-lg-6 mb-4">
<div class="card h-100">
<div class="card-body">
<div id="graph2" class="chart-container"></div>
</div>
</div>
</div>
<div class="col-lg-6 mb-4">
<div class="card h-100">
<div class="card-body">
<div id="graph3" class="chart-container"></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
let alertSound; // Will be initialized after user interaction
function initializeAudio() {
if (!alertSound) {
alertSound = new Audio('{{ url_for("static", filename="alarn_tune.mp3") }}');
console.log("Audio initialized.");
}
}
document.body.addEventListener('click', initializeAudio, { once: true });
function fetchPumpStatus() {
fetch('/update_pump_status')
.then(response => response.json())
.then(data => {
const statusElement = document.getElementById('pumpStatus');
const newStatus = data.pump_status;
const oldStatus = statusElement.innerText;
statusElement.innerText = newStatus;
statusElement.className = 'status-text ' + (newStatus === 'On' ? 'on' : 'off');
if (newStatus === 'Off' && oldStatus === 'On' && alertSound) {
alertSound.play().catch(e => console.error("Audio play failed:", e));
}
});
}
function fetchGraphData() {
fetch('/update_graph')
.then(response => response.json())
.then(data => {
if (data.length === 0) return;
const time = data.map((_, i) => i * 2); // Assuming 2 second intervals
const soilMoisture = data.map(entry => entry[0]);
const pumpStatus = data.map(entry => entry[1]);
const currentSoilMoisture = soilMoisture[soilMoisture.length - 1];
// Responsive layout for all plots
const responsiveLayout = { margin: { t: 40, b: 50, l: 50, r: 20 }, autosize: true };
Plotly.react('gauge', getGaugeData(currentSoilMoisture), { ...responsiveLayout, title: 'Soil Moisture' });
Plotly.react('graph1', getPumpStatusData(time, pumpStatus), { ...responsiveLayout, title: 'Pump Status vs. Time', yaxis: { tickvals: [-1, 1], ticktext: ['Off', 'On'], range: [-1.5, 1.5] }});
Plotly.react('graph2', getSoilMoistureData(time, soilMoisture), { ...responsiveLayout, title: 'Soil Moisture vs. Time' });
Plotly.react('graph3', getMoistureVsStatusData(soilMoisture, pumpStatus), { ...responsiveLayout, title: 'Pump Status vs. Soil Moisture', yaxis: { tickvals: [-1, 1], ticktext: ['Off', 'On'], range: [-1.5, 1.5] }});
});
}
// --- Chart Data Functions ---
const getGaugeData = value => [{ type: "indicator", mode: "gauge+number", value: value, gauge: { axis: { range: [0, 100] }, steps: [{ range: [0, 30], color: "#ea4335" },{ range: [30, 60], color: "#fbbc05" },{ range: [60, 100], color: "#34a853" }]}}];
const getPumpStatusData = (x, y) => [{ x, y, mode: 'lines+markers', type: 'scatter', line: { color: '#4285f4' } }];
const getSoilMoistureData = (x, y) => [{ x, y, mode: 'lines+markers', type: 'scatter', line: { color: '#34a853' } }];
const getMoistureVsStatusData = (x, y) => [{ x, y, mode: 'lines', type: 'scatter', line: { color: '#ea4335' } }];
let timeCounter = 0;
setInterval(() => { document.getElementById('time-counter').innerText = `${++timeCounter} seconds`; }, 1000);
setInterval(fetchPumpStatus, 2000);
setInterval(fetchGraphData, 2000);
</script>
</body>
</html> |