-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreview.html
More file actions
604 lines (556 loc) · 32.1 KB
/
Copy pathpreview.html
File metadata and controls
604 lines (556 loc) · 32.1 KB
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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SmartWater – Urban Water Management Platform (Interactive Preview)</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap" rel="stylesheet">
<style>
body { font-family: 'Inter', sans-serif; }
.nav-item.active { background-color: #2563eb; color: white; }
.pulse-dot { animation: pulse 1.5s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }
</style>
</head>
<body class="bg-slate-50 text-slate-800 flex h-screen overflow-hidden">
<!-- Sidebar -->
<aside class="w-64 bg-slate-900 text-white flex flex-col justify-between flex-shrink-0 z-20">
<div>
<!-- Brand -->
<div class="flex items-center gap-3 px-6 py-5 border-b border-slate-800 bg-slate-950">
<div class="bg-blue-600 rounded-xl p-2.5 shadow-lg shadow-blue-500/30">
<svg class="w-6 h-6 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19.428 15.428a2 2 0 00-1.022-.547l-2.387-.477a6 6 0 00-3.86.517l-.318.158a6 6 0 01-3.86.517L6.05 15.21a2 2 0 00-1.806.547M8 4h8l-1 1v5.172a2 2 0 00.586 1.414l5 5c1.26 1.26.367 3.414-1.415 3.414H4.828c-1.782 0-2.674-2.154-1.414-3.414l5-5A2 2 0 009 10.172V5L8 4z"></path></svg>
</div>
<div>
<h1 class="font-extrabold text-base tracking-tight leading-tight">SmartWater</h1>
<p class="text-xs text-slate-400 font-medium">Pune Municipality GIS</p>
</div>
</div>
<!-- Navigation links -->
<nav class="p-3 space-y-1">
<button onclick="switchTab('dashboard')" id="nav-dashboard" class="nav-item active w-full flex items-center gap-3 px-4 py-2.5 rounded-xl text-sm font-medium transition-all text-slate-300 hover:bg-slate-800">
<span>📊</span> Dashboard
</button>
<button onclick="switchTab('map')" id="nav-map" class="nav-item w-full flex items-center gap-3 px-4 py-2.5 rounded-xl text-sm font-medium transition-all text-slate-300 hover:bg-slate-800">
<span>🗺️</span> Water Network Map
</button>
<button onclick="switchTab('sensors')" id="nav-sensors" class="nav-item w-full flex items-center gap-3 px-4 py-2.5 rounded-xl text-sm font-medium transition-all text-slate-300 hover:bg-slate-800">
<span>📡</span> Live Telemetry Sensors
</button>
<button onclick="switchTab('complaints')" id="nav-complaints" class="nav-item w-full flex items-center gap-3 px-4 py-2.5 rounded-xl text-sm font-medium transition-all text-slate-300 hover:bg-slate-800">
<span>⚠️</span> Citizen Complaints (<span id="badge-complaints">10</span>)
</button>
<button onclick="switchTab('waterloss')" id="nav-waterloss" class="nav-item w-full flex items-center gap-3 px-4 py-2.5 rounded-xl text-sm font-medium transition-all text-slate-300 hover:bg-slate-800">
<span>💧</span> Water Loss Audit
</button>
</nav>
</div>
<!-- User Profile Footer -->
<div class="p-4 border-t border-slate-800 bg-slate-950/50 flex items-center justify-between">
<div class="flex items-center gap-3">
<div class="w-9 h-9 rounded-full bg-blue-600 font-bold text-sm flex items-center justify-center">R</div>
<div>
<div class="text-sm font-semibold leading-tight">Rajesh Kumar</div>
<div class="text-xs text-blue-400 font-medium">Chief Water Engineer</div>
</div>
</div>
<span class="text-xs bg-emerald-500/20 text-emerald-400 border border-emerald-500/30 px-2 py-0.5 rounded-full font-bold">ONLINE</span>
</div>
</aside>
<!-- Main Content Area -->
<div class="flex-1 flex flex-col overflow-hidden">
<!-- Top Navigation -->
<header class="bg-white border-b border-slate-200 px-6 py-3 flex items-center justify-between shadow-sm z-10">
<div class="flex items-center gap-3">
<span class="text-xs font-semibold uppercase tracking-wider text-slate-400">Urban Water Grid</span>
<span class="text-slate-300">/</span>
<h2 id="page-title" class="text-base font-bold text-slate-800">City Overview Dashboard</h2>
</div>
<div class="flex items-center gap-3">
<!-- Live Simulation Button -->
<button id="btn-demo" onclick="toggleLiveDemo()" class="flex items-center gap-2 px-3.5 py-1.5 bg-gradient-to-r from-blue-600 to-indigo-600 text-white rounded-lg text-xs font-bold shadow hover:opacity-95 transition-all">
<span id="demo-indicator" class="w-2 h-2 rounded-full bg-emerald-400 pulse-dot"></span>
<span id="demo-label">Live Telemetry: ON</span>
</button>
<div class="text-xs font-medium text-slate-500 bg-slate-100 px-3 py-1.5 rounded-lg border border-slate-200">
📍 Pune Municipal Area
</div>
</div>
</header>
<!-- Content Tabs Container -->
<main class="flex-1 overflow-y-auto p-6 space-y-6">
<!-- ================= TAB 1: DASHBOARD ================= -->
<section id="tab-dashboard" class="space-y-6">
<!-- Metrics Row -->
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4">
<div class="bg-white p-5 rounded-2xl border border-slate-200/80 shadow-sm flex items-center justify-between">
<div>
<p class="text-xs font-semibold text-slate-400 uppercase tracking-wider">Total Water Supplied</p>
<h3 id="stat-supplied" class="text-2xl font-extrabold text-slate-900 mt-1">520.0K L</h3>
<p class="text-xs text-emerald-600 font-medium mt-1">↑ Normal distribution</p>
</div>
<div class="p-3 bg-blue-50 text-blue-600 rounded-xl text-2xl">🚰</div>
</div>
<div class="bg-white p-5 rounded-2xl border border-slate-200/80 shadow-sm flex items-center justify-between">
<div>
<p class="text-xs font-semibold text-slate-400 uppercase tracking-wider">Total Billed Consumption</p>
<h3 id="stat-consumed" class="text-2xl font-extrabold text-slate-900 mt-1">426.0K L</h3>
<p class="text-xs text-slate-400 font-medium mt-1">Metered across 5 zones</p>
</div>
<div class="p-3 bg-teal-50 text-teal-600 rounded-xl text-2xl">📊</div>
</div>
<div class="bg-white p-5 rounded-2xl border border-slate-200/80 shadow-sm flex items-center justify-between">
<div>
<p class="text-xs font-semibold text-slate-400 uppercase tracking-wider">System Water Loss</p>
<h3 id="stat-loss" class="text-2xl font-extrabold text-amber-600 mt-1">94.0K L (18.1%)</h3>
<p class="text-xs text-amber-600 font-semibold mt-1">⚠️ Moderate Loss (Action required)</p>
</div>
<div class="p-3 bg-amber-50 text-amber-600 rounded-xl text-2xl">💧</div>
</div>
<div class="bg-white p-5 rounded-2xl border border-slate-200/80 shadow-sm flex items-center justify-between">
<div>
<p class="text-xs font-semibold text-slate-400 uppercase tracking-wider">Active Alerts</p>
<h3 class="text-2xl font-extrabold text-rose-600 mt-1">3 Incidents</h3>
<p class="text-xs text-rose-500 font-medium mt-1">1 Critical in Hadapsar (Zone C)</p>
</div>
<div class="p-3 bg-rose-50 text-rose-600 rounded-xl text-2xl">🚨</div>
</div>
</div>
<!-- Charts Row -->
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
<div class="bg-white p-6 rounded-2xl border border-slate-200/80 shadow-sm">
<div class="flex items-center justify-between mb-4">
<h3 class="font-bold text-slate-800">Weekly Supply vs Consumption (Liters)</h3>
<span class="text-xs text-slate-400">Past 7 Days</span>
</div>
<div class="h-64">
<canvas id="chartWeekly"></canvas>
</div>
</div>
<div class="bg-white p-6 rounded-2xl border border-slate-200/80 shadow-sm">
<div class="flex items-center justify-between mb-4">
<h3 class="font-bold text-slate-800">Zone-Wise Distribution & Loss %</h3>
<span class="text-xs text-slate-400">Today</span>
</div>
<div class="h-64">
<canvas id="chartZoneLoss"></canvas>
</div>
</div>
</div>
<!-- Zone Table -->
<div class="bg-white rounded-2xl border border-slate-200/80 shadow-sm overflow-hidden">
<div class="px-6 py-4 border-b border-slate-100 flex items-center justify-between">
<h3 class="font-bold text-slate-800">Zone-Wise Water Audit Summary</h3>
<button onclick="switchTab('map')" class="text-xs text-blue-600 font-semibold hover:underline">View on GIS Map →</button>
</div>
<table class="w-full text-sm text-left">
<thead class="bg-slate-50 text-slate-500 text-xs font-semibold uppercase">
<tr>
<th class="px-6 py-3">Zone Name</th>
<th class="px-6 py-3">Population</th>
<th class="px-6 py-3">Supplied</th>
<th class="px-6 py-3">Consumed</th>
<th class="px-6 py-3">Loss (L)</th>
<th class="px-6 py-3">Loss Status</th>
</tr>
</thead>
<tbody class="divide-y divide-slate-100">
<tr class="hover:bg-slate-50/80">
<td class="px-6 py-3.5 font-semibold text-slate-900">Zone A – Shivajinagar</td>
<td class="px-6 py-3.5 text-slate-600">85,000</td>
<td class="px-6 py-3.5 text-slate-600">100,000 L</td>
<td class="px-6 py-3.5 text-slate-600">83,000 L</td>
<td class="px-6 py-3.5 text-slate-600">17,000 L</td>
<td class="px-6 py-3.5"><span class="px-2.5 py-1 text-xs font-bold rounded-full bg-amber-100 text-amber-700">17.0% MEDIUM</span></td>
</tr>
<tr class="hover:bg-slate-50/80">
<td class="px-6 py-3.5 font-semibold text-slate-900">Zone B – Kothrud</td>
<td class="px-6 py-3.5 text-slate-600">120,000</td>
<td class="px-6 py-3.5 text-slate-600">138,000 L</td>
<td class="px-6 py-3.5 text-slate-600">112,000 L</td>
<td class="px-6 py-3.5 text-slate-600">26,000 L</td>
<td class="px-6 py-3.5"><span class="px-2.5 py-1 text-xs font-bold rounded-full bg-amber-100 text-amber-700">18.8% MEDIUM</span></td>
</tr>
<tr class="hover:bg-slate-50/80 bg-rose-50/30">
<td class="px-6 py-3.5 font-semibold text-slate-900">Zone C – Hadapsar</td>
<td class="px-6 py-3.5 text-slate-600">95,000</td>
<td class="px-6 py-3.5 text-slate-600">110,000 L</td>
<td class="px-6 py-3.5 text-slate-600">85,000 L</td>
<td class="px-6 py-3.5 text-rose-600 font-bold">25,000 L</td>
<td class="px-6 py-3.5"><span class="px-2.5 py-1 text-xs font-bold rounded-full bg-rose-100 text-rose-700">22.7% HIGH LOSS</span></td>
</tr>
<tr class="hover:bg-slate-50/80">
<td class="px-6 py-3.5 font-semibold text-slate-900">Zone D – Pimpri</td>
<td class="px-6 py-3.5 text-slate-600">110,000</td>
<td class="px-6 py-3.5 text-slate-600">120,000 L</td>
<td class="px-6 py-3.5 text-slate-600">101,000 L</td>
<td class="px-6 py-3.5 text-slate-600">19,000 L</td>
<td class="px-6 py-3.5"><span class="px-2.5 py-1 text-xs font-bold rounded-full bg-amber-100 text-amber-700">15.8% MEDIUM</span></td>
</tr>
<tr class="hover:bg-slate-50/80">
<td class="px-6 py-3.5 font-semibold text-slate-900">Zone E – Aundh</td>
<td class="px-6 py-3.5 text-slate-600">70,000</td>
<td class="px-6 py-3.5 text-slate-600">80,000 L</td>
<td class="px-6 py-3.5 text-slate-600">67,000 L</td>
<td class="px-6 py-3.5 text-slate-600">13,000 L</td>
<td class="px-6 py-3.5"><span class="px-2.5 py-1 text-xs font-bold rounded-full bg-emerald-100 text-emerald-700">16.2% MEDIUM</span></td>
</tr>
</tbody>
</table>
</div>
</section>
<!-- ================= TAB 2: GIS MAP ================= -->
<section id="tab-map" class="hidden space-y-4">
<div class="bg-white p-4 rounded-2xl border border-slate-200 shadow-sm flex flex-wrap items-center justify-between gap-3">
<div>
<h3 class="font-bold text-slate-900">Pune Urban Water Network (GIS)</h3>
<p class="text-xs text-slate-500">Includes 5 elevated storage tanks, 3 pump stations, transmission pipelines, telemetry sensors & citizen complaints</p>
</div>
<div class="flex items-center gap-3 text-xs">
<span class="flex items-center gap-1.5"><span class="w-3 h-3 rounded-full bg-blue-600"></span> Tanks</span>
<span class="flex items-center gap-1.5"><span class="w-3 h-3 rounded-full bg-purple-600"></span> Pump Stations</span>
<span class="flex items-center gap-1.5"><span class="w-3 h-3 rounded-full bg-cyan-600"></span> Sensors</span>
<span class="flex items-center gap-1.5"><span class="w-3 h-3 rounded-full bg-rose-600"></span> Burst Leaks</span>
</div>
</div>
<div class="bg-white rounded-2xl border border-slate-200 overflow-hidden shadow-sm h-[560px] relative">
<div id="gis-map" class="w-full h-full"></div>
</div>
</section>
<!-- ================= TAB 3: SENSORS ================= -->
<section id="tab-sensors" class="hidden space-y-6">
<div class="bg-amber-50 border border-amber-200 rounded-2xl p-4 flex items-center justify-between">
<div class="flex items-center gap-3">
<span class="text-2xl">📡</span>
<div>
<h4 class="font-bold text-amber-900 text-sm">Simulated Live Telemetry Stream</h4>
<p class="text-xs text-amber-700">Readings fluctuate every 3 seconds to simulate IoT pressure transducers & ultrasonic flow meters.</p>
</div>
</div>
<span class="px-3 py-1 bg-amber-200 text-amber-800 text-xs font-bold rounded-full">ACTIVE DEMO</span>
</div>
<div id="sensor-grid" class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4">
<!-- Sensors injected by JS -->
</div>
</section>
<!-- ================= TAB 4: COMPLAINTS ================= -->
<section id="tab-complaints" class="hidden space-y-6">
<div class="flex items-center justify-between">
<div>
<h3 class="text-lg font-bold text-slate-900">Citizen Complaints Redressal</h3>
<p class="text-xs text-slate-500">Live feed of citizen reports, location coordinates, and technician task dispatches</p>
</div>
<button onclick="openNewComplaintModal()" class="px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-xl text-xs font-bold shadow transition-all flex items-center gap-2">
<span>➕</span> Log New Complaint
</button>
</div>
<div class="bg-white rounded-2xl border border-slate-200 shadow-sm overflow-hidden">
<table class="w-full text-sm text-left">
<thead class="bg-slate-50 text-slate-500 text-xs font-semibold uppercase">
<tr>
<th class="px-6 py-3">ID</th>
<th class="px-6 py-3">Problem Type</th>
<th class="px-6 py-3">Citizen Name</th>
<th class="px-6 py-3">Zone</th>
<th class="px-6 py-3">Priority</th>
<th class="px-6 py-3">Status</th>
<th class="px-6 py-3">Action</th>
</tr>
</thead>
<tbody id="complaints-tbody" class="divide-y divide-slate-100">
<!-- Injected by JS -->
</tbody>
</table>
</div>
</section>
<!-- ================= TAB 5: WATER LOSS AUDIT ================= -->
<section id="tab-waterloss" class="hidden space-y-6">
<div class="bg-white p-6 rounded-2xl border border-slate-200 shadow-sm">
<h3 class="font-bold text-slate-900 mb-2">Municipal Water Balance Formula</h3>
<p class="text-sm text-slate-600 mb-4">Water Loss (Unaccounted for Water) is calculated continuously as: <code class="bg-slate-100 text-blue-600 px-2 py-1 rounded font-mono font-bold">Loss = Total Bulk Supply (L) − Total Billed Consumption (L)</code></p>
<div class="grid grid-cols-1 md:grid-cols-3 gap-4 text-xs font-semibold">
<div class="p-4 rounded-xl bg-emerald-50 text-emerald-800 border border-emerald-200">
<span class="text-base font-bold">🟢 LOW LOSS (< 10%)</span>
<p class="font-normal mt-1 text-slate-600">Standard acceptable distribution loss due to measurement margins.</p>
</div>
<div class="p-4 rounded-xl bg-amber-50 text-amber-800 border border-amber-200">
<span class="text-base font-bold">🟡 MEDIUM LOSS (10% – 20%)</span>
<p class="font-normal mt-1 text-slate-600">Requires acoustic pipe inspection and pressure regulation balancing.</p>
</div>
<div class="p-4 rounded-xl bg-rose-50 text-rose-800 border border-rose-200">
<span class="text-base font-bold">🔴 HIGH LOSS (> 20%)</span>
<p class="font-normal mt-1 text-slate-600">Major pipe rupture, illegal siphoning, or tank overflow. Immediate maintenance dispatched.</p>
</div>
</div>
</div>
</section>
</main>
</div>
<!-- Complaint Modal -->
<div id="modal-complaint" class="fixed inset-0 bg-black/50 backdrop-blur-sm z-50 hidden items-center justify-center p-4">
<div class="bg-white rounded-2xl max-w-md w-full p-6 shadow-2xl space-y-4">
<div class="flex items-center justify-between border-b pb-3">
<h3 class="font-bold text-slate-900">Report Water Leakage / Outage</h3>
<button onclick="closeNewComplaintModal()" class="text-slate-400 hover:text-slate-600 font-bold text-lg">×</button>
</div>
<form onsubmit="handleCreateComplaint(event)" class="space-y-3 text-sm">
<div>
<label class="block font-semibold text-slate-700 mb-1">Issue Category</label>
<select id="modal-type" class="w-full border border-slate-300 rounded-lg p-2">
<option value="Pipeline Leakage">Pipeline Burst / Leakage</option>
<option value="Road Leakage">Road Surface Flooding</option>
<option value="Tank Overflow">Tank Overflowing</option>
<option value="Low Pressure">Low Supply Pressure</option>
</select>
</div>
<div>
<label class="block font-semibold text-slate-700 mb-1">Citizen Name</label>
<input id="modal-name" required class="w-full border border-slate-300 rounded-lg p-2" placeholder="e.g. Anand Shinde" />
</div>
<div>
<label class="block font-semibold text-slate-700 mb-1">Zone</label>
<select id="modal-zone" class="w-full border border-slate-300 rounded-lg p-2">
<option value="Zone C – Hadapsar">Zone C – Hadapsar</option>
<option value="Zone A – Shivajinagar">Zone A – Shivajinagar</option>
<option value="Zone B – Kothrud">Zone B – Kothrud</option>
<option value="Zone D – Pimpri">Zone D – Pimpri</option>
<option value="Zone E – Aundh">Zone E – Aundh</option>
</select>
</div>
<div>
<label class="block font-semibold text-slate-700 mb-1">Description</label>
<textarea id="modal-desc" required rows="2" class="w-full border border-slate-300 rounded-lg p-2" placeholder="Exact street address, building, or landmark..."></textarea>
</div>
<div class="flex gap-2 pt-2">
<button type="button" onclick="closeNewComplaintModal()" class="flex-1 py-2 bg-slate-100 hover:bg-slate-200 rounded-lg font-semibold">Cancel</button>
<button type="submit" class="flex-1 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-lg font-semibold">Submit</button>
</div>
</form>
</div>
</div>
<script>
// State
let isLiveDemo = true;
let demoInterval = null;
let leafletMap = null;
const sensorData = [
{ id: 'FA-101', type: 'Flow Sensor', zone: 'Zone A', val: 780, unit: 'L/min', status: 'normal', lat: 18.5295, lng: 73.8460 },
{ id: 'PA-201', type: 'Pressure Sensor', zone: 'Zone A', val: 2.8, unit: 'bar', status: 'normal', lat: 18.5320, lng: 73.8490 },
{ id: 'FB-102', type: 'Flow Sensor', zone: 'Zone B', val: 860, unit: 'L/min', status: 'normal', lat: 18.5060, lng: 73.8090 },
{ id: 'TB-301', type: 'Tank Level', zone: 'Zone B', val: 74, unit: '%', status: 'normal', lat: 18.5085, lng: 73.8065 },
{ id: 'FC-103', type: 'Flow Sensor', zone: 'Zone C', val: 420, unit: 'L/min', status: 'warning', lat: 18.5005, lng: 73.9270 },
{ id: 'PC-202', type: 'Pressure Sensor', zone: 'Zone C', val: 1.2, unit: 'bar', status: 'warning', lat: 18.5030, lng: 73.9255 },
{ id: 'MC-401', type: 'Water Meter', zone: 'Zone C', val: 680, unit: 'L/h', status: 'normal', lat: 18.5020, lng: 73.9280 },
{ id: 'FD-104', type: 'Flow Sensor', zone: 'Zone D', val: 790, unit: 'L/min', status: 'normal', lat: 18.6285, lng: 73.8010 },
{ id: 'PD-203', type: 'Pressure Sensor', zone: 'Zone D', val: 0.0, unit: 'bar', status: 'offline', lat: 18.6310, lng: 73.7985 },
{ id: 'TE-302', type: 'Tank Level', zone: 'Zone E', val: 88, unit: '%', status: 'normal', lat: 18.5570, lng: 73.8095 },
];
let complaintsData = [
{ id: 'CMP-101', type: 'Pipeline Leakage', name: 'Priya Mehta', zone: 'Zone C – Hadapsar', priority: 'CRITICAL', status: 'In Progress' },
{ id: 'CMP-102', type: 'Low Pressure', name: 'Amit Desai', zone: 'Zone A – Shivajinagar', priority: 'MEDIUM', status: 'Assigned' },
{ id: 'CMP-103', type: 'Road Leakage', name: 'Sunil Jadhav', zone: 'Zone B – Kothrud', priority: 'HIGH', status: 'Reported' },
{ id: 'CMP-104', type: 'Tank Overflow', name: 'Meera Kulkarni', zone: 'Zone E – Aundh', priority: 'HIGH', status: 'Resolved' },
{ id: 'CMP-105', type: 'Broken Valve', name: 'Rohan Joshi', zone: 'Zone D – Pimpri', priority: 'LOW', status: 'Reported' },
];
function switchTab(tabId) {
document.querySelectorAll('main > section').forEach(el => el.classList.add('hidden'));
document.querySelectorAll('.nav-item').forEach(el => el.classList.remove('active'));
document.getElementById('tab-' + tabId).classList.remove('hidden');
document.getElementById('nav-' + tabId).classList.add('active');
const titles = {
dashboard: 'City Overview Dashboard',
map: 'Interactive GIS Water Network Map',
sensors: 'Real-Time Sensor Telemetry Grid',
complaints: 'Citizen Grievance Management',
waterloss: 'Non-Revenue Water (NRW) Audit'
};
document.getElementById('page-title').textContent = titles[tabId] || 'SmartWater';
if (tabId === 'map') {
setTimeout(initMap, 100);
}
}
function renderSensors() {
const grid = document.getElementById('sensor-grid');
grid.innerHTML = '';
sensorData.forEach(s => {
const borderCol = s.status === 'normal' ? 'border-emerald-500' : s.status === 'warning' ? 'border-amber-500' : 'border-slate-300';
const badgeCol = s.status === 'normal' ? 'bg-emerald-100 text-emerald-800' : s.status === 'warning' ? 'bg-amber-100 text-amber-800' : 'bg-slate-100 text-slate-600';
grid.innerHTML += `
<div class="bg-white p-5 rounded-2xl border-l-4 ${borderCol} border-y border-r border-slate-200/80 shadow-sm">
<div class="flex items-center justify-between mb-2">
<span class="font-mono text-xs font-bold text-slate-500">${s.id}</span>
<span class="text-xs px-2 py-0.5 rounded-full font-bold uppercase ${badgeCol}">${s.status}</span>
</div>
<p class="text-xs text-slate-400 font-medium">${s.type}</p>
<div class="my-2">
<span class="text-3xl font-extrabold text-slate-900">${s.status === 'offline' ? '–' : s.val.toFixed(s.unit === 'bar' ? 1 : 0)}</span>
<span class="text-sm font-semibold text-slate-400 ml-1">${s.unit}</span>
</div>
<div class="text-xs text-slate-500 mt-3 pt-2 border-t border-slate-100 flex items-center justify-between">
<span>📍 ${s.zone}</span>
<span class="text-emerald-600 font-bold">● Active</span>
</div>
</div>
`;
});
}
function renderComplaints() {
const tbody = document.getElementById('complaints-tbody');
tbody.innerHTML = '';
complaintsData.forEach(c => {
const prioCol = c.priority === 'CRITICAL' ? 'bg-rose-100 text-rose-700' : c.priority === 'HIGH' ? 'bg-amber-100 text-amber-700' : 'bg-blue-100 text-blue-700';
const statusCol = c.status === 'Resolved' ? 'bg-emerald-100 text-emerald-800' : c.status === 'In Progress' ? 'bg-blue-100 text-blue-800' : 'bg-slate-100 text-slate-700';
tbody.innerHTML += `
<tr class="hover:bg-slate-50/80">
<td class="px-6 py-3.5 font-mono text-xs text-slate-500">${c.id}</td>
<td class="px-6 py-3.5 font-semibold text-slate-900">${c.type}</td>
<td class="px-6 py-3.5 text-slate-600">${c.name}</td>
<td class="px-6 py-3.5 text-slate-600">${c.zone}</td>
<td class="px-6 py-3.5"><span class="px-2 py-0.5 rounded text-xs font-bold ${prioCol}">${c.priority}</span></td>
<td class="px-6 py-3.5"><span class="px-2 py-0.5 rounded-full text-xs font-bold ${statusCol}">${c.status}</span></td>
<td class="px-6 py-3.5">
<button onclick="alert('Task dispatched to field maintenance team for ${c.id}')" class="text-xs bg-slate-100 hover:bg-blue-600 hover:text-white px-2.5 py-1 rounded-lg font-semibold transition-all">Dispatch</button>
</td>
</tr>
`;
});
document.getElementById('badge-complaints').textContent = complaintsData.length;
}
function initCharts() {
// Weekly Chart
new Chart(document.getElementById('chartWeekly'), {
type: 'line',
data: {
labels: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
datasets: [
{ label: 'Supplied (kL)', data: [510, 525, 505, 530, 515, 540, 520], borderColor: '#2563eb', backgroundColor: 'rgba(37, 99, 235, 0.1)', fill: true, tension: 0.3 },
{ label: 'Consumed (kL)', data: [420, 430, 415, 435, 422, 445, 426], borderColor: '#0d9488', backgroundColor: 'transparent', borderDash: [4, 4], tension: 0.3 }
]
},
options: { responsive: true, maintainAspectRatio: false, plugins: { legend: { position: 'top' } } }
});
// Zone Loss Chart
new Chart(document.getElementById('chartZoneLoss'), {
type: 'bar',
data: {
labels: ['Shivajinagar', 'Kothrud', 'Hadapsar', 'Pimpri', 'Aundh'],
datasets: [
{ label: 'Supplied (kL)', data: [100, 138, 110, 120, 80], backgroundColor: '#3b82f6' },
{ label: 'Consumed (kL)', data: [83, 112, 85, 101, 67], backgroundColor: '#14b8a6' },
{ label: 'Loss (kL)', data: [17, 26, 25, 19, 13], backgroundColor: '#f59e0b' }
]
},
options: { responsive: true, maintainAspectRatio: false }
});
}
function initMap() {
if (leafletMap) {
leafletMap.invalidateSize();
return;
}
leafletMap = L.map('gis-map').setView([18.5204, 73.8567], 12);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap'
}).addTo(leafletMap);
// Add Pune Zones & Infrastructure
const assets = [
{ name: 'Shivajinagar Reservoir (500kL)', lat: 18.5308, lng: 73.8475, type: 'tank' },
{ name: 'Kothrud Elevated Tank (600kL)', lat: 18.5074, lng: 73.8077, type: 'tank' },
{ name: 'Hadapsar Water Works', lat: 18.5018, lng: 73.9260, type: 'pump' },
{ name: 'Pimpri Transmission Sub-Station', lat: 18.6298, lng: 73.7997, type: 'pump' },
{ name: 'Aundh Storage Facility', lat: 18.5581, lng: 73.8082, type: 'tank' },
];
assets.forEach(a => {
L.circleMarker([a.lat, a.lng], {
radius: 9,
fillColor: a.type === 'tank' ? '#2563eb' : '#9333ea',
color: '#ffffff',
weight: 2,
fillOpacity: 0.9
}).addTo(leafletMap).bindPopup(`<b>${a.name}</b><br>Type: ${a.type.toUpperCase()}`);
});
// Add Sensors
sensorData.forEach(s => {
L.circleMarker([s.lat, s.lng], {
radius: 7,
fillColor: s.status === 'warning' ? '#f59e0b' : '#06b6d4',
color: '#ffffff',
weight: 2,
fillOpacity: 0.9
}).addTo(leafletMap).bindPopup(`<b>Sensor ${s.id} (${s.type})</b><br>Zone: ${s.zone}<br>Reading: <b>${s.val} ${s.unit}</b>`);
});
// Add Pipeline Transmission Line
L.polyline([
[18.5308, 73.8475],
[18.5074, 73.8077],
[18.5581, 73.8082],
[18.6298, 73.7997]
], { color: '#3b82f6', weight: 4, opacity: 0.7 }).addTo(leafletMap).bindPopup('Primary 600mm DI Transmission Main');
L.polyline([
[18.5308, 73.8475],
[18.5018, 73.9260]
], { color: '#ef4444', weight: 4, dashArray: '6, 6', opacity: 0.8 }).addTo(leafletMap).bindPopup('⚠️ Hadapsar Line (High Leakage Identified: 22.7%)');
}
function toggleLiveDemo() {
isLiveDemo = !isLiveDemo;
const indicator = document.getElementById('demo-indicator');
const label = document.getElementById('demo-label');
if (isLiveDemo) {
indicator.className = 'w-2 h-2 rounded-full bg-emerald-400 pulse-dot';
label.textContent = 'Live Telemetry: ON';
startDemoSimulation();
} else {
indicator.className = 'w-2 h-2 rounded-full bg-slate-400';
label.textContent = 'Live Telemetry: PAUSED';
clearInterval(demoInterval);
}
}
function startDemoSimulation() {
clearInterval(demoInterval);
demoInterval = setInterval(() => {
sensorData.forEach(s => {
if (s.status !== 'offline') {
const delta = (Math.random() - 0.5) * (s.unit === 'bar' ? 0.1 : 15);
s.val = Math.max(0.5, s.val + delta);
}
});
renderSensors();
}, 3000);
}
function openNewComplaintModal() {
document.getElementById('modal-complaint').classList.remove('hidden');
document.getElementById('modal-complaint').classList.add('flex');
}
function closeNewComplaintModal() {
document.getElementById('modal-complaint').classList.add('hidden');
document.getElementById('modal-complaint').classList.remove('flex');
}
function handleCreateComplaint(e) {
e.preventDefault();
const newCmp = {
id: 'CMP-' + (100 + complaintsData.length + 1),
type: document.getElementById('modal-type').value,
name: document.getElementById('modal-name').value,
zone: document.getElementById('modal-zone').value,
priority: 'HIGH',
status: 'Reported'
};
complaintsData.unshift(newCmp);
renderComplaints();
closeNewComplaintModal();
alert('✅ Issue submitted! Municipal field dispatch has been alerted.');
}
// Init on load
window.addEventListener('DOMContentLoaded', () => {
renderSensors();
renderComplaints();
initCharts();
startDemoSimulation();
});
</script>
</body>
</html>