-
Notifications
You must be signed in to change notification settings - Fork 0
/
lisa.php
436 lines (401 loc) · 19.8 KB
/
lisa.php
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
<?php include('top.php') ?>
<?php
// Set the default fiscal year
$fiscal_year_id = isset($_GET['fiscal_year_id']) ? $_GET['fiscal_year_id'] : 4;
// Define the file path based on the fiscal year
$file_path = __DIR__ . "/data/LISA_summary_fiscal_year_{$fiscal_year_id}.json";
// Check if the file exists
if (file_exists($file_path)) {
// Fetch the data from the local JSON file
$json_response = file_get_contents($file_path);
$data = json_decode($json_response, true);
} else {
die('Error: Data file not found.');
}
// Extract provinces and districts for filters
$provinces = [];
$districts = [];
$fiscal_years = [
1 => 'FY 2076/77',
2 => 'FY 2077/78',
3 => 'FY 2078/79',
4 => 'FY 2079/80'
]; // Example fiscal years
foreach ($data['response'] as $item) {
$provinces[$item['province']] = $item['province'];
$districts[$item['province']][$item['district']] = $item['district'];
}
?>
<body id="page-top">
<div id="wrapper">
<?php include('sidebar.php') ?>
<div id="content-wrapper" class="d-flex flex-column">
<!-- Main Content -->
<div class="content">
<!-- Begin Page Content -->
<div class="container-fluid">
<!-- selection filter row -->
<div class="row">
<form id="filterForm" class="row g-3">
<!-- Page Heading -->
<div class="col-xl-3 col-md-6 mb-4">
<h1 class="h3 mb-0 text-gray-800">Dashboard - <span id="selectedUnit"></span></h1>
</div>
<div class="col-xl-3 col-md-6 mb-4">
<label for="fiscal_year" class="form-label">Select Fiscal Year:</label>
<select id="fiscal_year" name="fiscal_year" class="form-select">
<?php foreach ($fiscal_years as $id => $fy): ?>
<option value="<?php echo $id; ?>" <?php if ($id == $fiscal_year_id) echo 'selected'; ?>><?php echo $fy; ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="col-xl-3 col-md-6 mb-4">
<label for="province" class="form-label">Select Province:</label>
<select id="province" name="province" class="form-select">
<option value="">All Provinces</option>
<?php foreach ($provinces as $province): ?>
<option value="<?php echo $province; ?>" <?php if ($province == 'लुम्बिनी प्रदेश') echo 'selected'; ?>><?php echo $province; ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="col-xl-3 col-md-6 mb-4">
<label for="district" class="form-label">Select District:</label>
<select id="district" name="district" class="form-select">
<option value="">All Districts</option>
</select>
</div>
</form>
</div>
<div class="row">
<!-- total lg -->
<div class="col-xl-3 col-md-6 mb-4">
<div class="card">
<div class="card-body row">
<div class="col mr-2">
<div class="text-xs font-weight-bold text-primary text-uppercase mb-1">Total LGs</div>
<div class="h5 mb-0 font-weight-bold text-gray-800" id="totalLGs">0</div>
</div>
<div class="col-auto">
<i class="fa fa-building fa-2x text-gray-300"></i>
</div>
</div>
</div>
</div>
<!-- Province Score -->
<div class="col-xl-3 col-md-6 mb-4">
<div class="card">
<div class="card-body row">
<div class="col mr-2">
<div class="text-xs font-weight-bold text-primary text-uppercase mb-1">Average Score (Province)</div>
<div class="h5 mb-0 font-weight-bold text-gray-800" id="avgScoreProvince">0</div>
</div>
<div class="col-auto">
<i class="fa fa-map fa-2x text-gray-300"></i>
</div>
</div>
</div>
</div>
<!-- District Score -->
<div class="col-xl-3 col-md-6 mb-4">
<div class="card">
<div class="card-body row">
<div class="col mr-2">
<div class="text-xs font-weight-bold text-primary text-uppercase mb-1">Average Score (District)</div>
<div class="h5 mb-0 font-weight-bold text-gray-800" id="avgScoreDistrict">0</div>
</div>
<div class="col-auto">
<i class="fa fa-globe fa-2x text-gray-300"></i>
</div>
</div>
</div>
</div>
<!-- Top Score -->
<div class="col-xl-3 col-md-6 mb-4">
<div class="card">
<div class="card-body row">
<div class="col mr-2">
<div class="text-xs font-weight-bold text-primary text-uppercase mb-1">LG Scoring Highest</div>
<div class="h5 mb-0 font-weight-bold text-gray-800" id="highestScoreLG">0</div>
</div>
<div class="col-auto">
<i class="fa fa-trophy fa-2x text-gray-300"></i>
</div>
</div>
</div>
</div>
</div>
<!-- Card row end here -->
<!-- CHART START -->
<div class="row">
<div class="col-xl-8 col-lg-7">
<div class="card shadow">
<div class="card-header">
<h6 class="m-0 font-weight-bold text-primary">Local Government Scores</h6>
</div>
<div class="card-body">
<div class="chart-area">
<canvas id="barChart"></canvas>
</div>
</div>
</div>
</div>
<div class="col-xl-4 col-lg-7">
<div class="card shadow">
<div class="card-header">
<h6 class="m-0 font-weight-bold text-primary">Category</h6>
</div>
<div class="card-body">
<div class="chart-area">
<canvas id="categoriesChart"></canvas>
</div>
</div>
</div>
</div>
</div>
<!-- chart row end here -->
<?php
$headers = [
'शासकीय प्रवन्ध', 'संगठन तथा प्रशासन', 'वार्षिक बजेट तथा योजना', 'वित्तीय एवम् आर्थिक',
'सेवा प्रवाह', 'न्यायिक कार्य सम्पादन', 'भौतिक पूर्वाधार', 'सामाजिक समावेशीकरण',
'वातावरण संरक्षण तथा विपद', 'सहकार्य र समन्वय'
];
?>
<!-- Table row -->
<div class="row" style="margin-top: 20px">
<div class="col-lg-12 mb-4">
<div class="card">
<div class="card-header">
<h6 class="m-0 font-weight-bold text-primary">Local Government Score</h6>
</div>
<div class="card-body">
<table class="table table-striped sortable">
<thead>
<tr>
<th>LG Name</th>
<?php foreach ($headers as $header): ?>
<th><?php echo $header; ?></th>
<?php endforeach; ?>
</tr>
</thead>
<tbody id="lgTableBody">
</tbody>
</table>
</div>
</div>
</div>
</div>
<!-- table row end here -->
</div>
<!-- fluid container end here -->
</div>
<!-- End of Main Content -->
</div>
<!-- End of Wrapper -->
</div>
</body>
</html>
<script>
// Fetch and display data on fiscal year change
document.getElementById('fiscal_year').addEventListener('change', function () {
var fiscalYear = this.value;
window.location.href = window.location.pathname + '?fiscal_year_id=' + fiscalYear;
});
document.addEventListener('DOMContentLoaded', function() {
const provinces = <?php echo json_encode($provinces); ?>;
const districts = <?php echo json_encode($districts); ?>;
const data = <?php echo json_encode($data['response']); ?>;
const totalLGsDisplay = document.getElementById('totalLGs');
const provinceSelect = document.getElementById('province');
const districtSelect = document.getElementById('district');
const averageScoreDisplayProvince = document.getElementById('avgScoreProvince');
const averageScoreDisplayDistrict = document.getElementById('avgScoreDistrict');
const highestScoreLGDisplay = document.getElementById('highestScoreLG');
const selectedUnitDisplay = document.getElementById('selectedUnit');
const categoriesChartCtx = document.getElementById('categoriesChart').getContext('2d');
const barChartCtx = document.getElementById('barChart').getContext('2d');
let categoriesChart, barChart;
provinceSelect.addEventListener('change', updateDistricts);
document.getElementById('filterForm').addEventListener('change', updateData);
function updateDistricts() {
const selectedProvince = provinceSelect.value;
districtSelect.innerHTML = '<option value="">All Districts</option>';
if (selectedProvince && districts[selectedProvince]) {
Object.keys(districts[selectedProvince]).forEach(district => {
const option = document.createElement('option');
option.value = district;
option.textContent = district;
districtSelect.appendChild(option);
});
}
}
function updateData() {
const selectedProvince = provinceSelect.value;
const selectedDistrict = districtSelect.value;
let filteredData = data;
// let selectedUnit = Nepal;
if (selectedProvince) {
filteredData = filteredData.filter(item => item.province === selectedProvince);
let provinceData = filteredData.filter(item => item.province === selectedProvince);
let totalScoreProvince = 0;
let validScoresCount = 0;
provinceData.forEach(item => {
if (!isNaN(item.score) && item.score !== null) {
totalScoreProvince += parseFloat(item.score);
validScoresCount++;
}
});
const averageScoreProvince = validScoresCount ? (totalScoreProvince / validScoresCount).toFixed(2) : '0.00';
averageScoreDisplayProvince.textContent = averageScoreProvince;
selectedUnitDisplay.textContent=selectedProvince;
}
if (selectedDistrict) {
filteredData = filteredData.filter(item => item.district === selectedDistrict);
// Calculate average score
let totalScoreDistrict = 0;
let validScoresCountDistrict = 0;
filteredData.forEach(item => {
if (!isNaN(item.score) && item.score !== null) {
totalScoreDistrict += parseFloat(item.score);
validScoresCountDistrict++;
}
});
const averageScoreDistrict = validScoresCountDistrict ? (totalScoreDistrict / validScoresCountDistrict).toFixed(2) : '0.00';
averageScoreDisplayDistrict.textContent = averageScoreDistrict;
selectedUnitDisplay.textContent=selectedDistrict;
}
// Calculate total LGs
const totalLGs = filteredData.length;
totalLGsDisplay.textContent = totalLGs;
// Calculate average score for province and district
let totalScore = 0;
let highestScore = 0;
let highestScoreLG = 'N/A';
filteredData.forEach(item => {
totalScore += item.score;
if (item.score > highestScore) {
highestScore = item.score;
highestScoreLG = `${item.name} (${item.score})`;
}
});
highestScoreLGDisplay.textContent = highestScoreLG;
// Cateogry full score
const categoryFullScores = {
1: 9,
2: 8,
3: 11,
4: 11,
5: 16,
6: 7,
7: 13,
8: 10,
9: 9,
10: 6
};
// Calculate the percentage of category score in relation with full score
function calculatePercentageScores(scores) {
const percentageScores = [];
for (let i = 0; i < 10; i++) {
// const key = i.toString();
const obtained = scores[i];
const full = categoryFullScores[i+1];
const percentage = (obtained / full) * 100;
percentageScores.push(percentage.toFixed(2));
}
return percentageScores;
}
// Initialize all variables to 0
const categorySums = {};
const categoryCounts = {};
for (let i = 1; i <= 10; i++) {
categorySums[i] = 0;
categoryCounts[i] = 0;
}
// Calculate sum of category scores and count the occurance
filteredData.forEach(item => {
for (let i = 1; i <= 10; i++) {
if (item.categories[i] !== undefined || item.categories[i]!=='N/A' || item.categories[i] !== null) {
categorySums[i] += item.categories[i];
categoryCounts[i]++;
}
}
});
// Calculate average category score
const averageCategoryScores = [];
for (let i = 1; i <= 10; i++) {
averageCategoryScores.push(categoryCounts[i] ? (categorySums[i] / categoryCounts[i]).toFixed(2) : 0);
}
// Render radar chart
if (categoriesChart) {
categoriesChart.destroy();
}
// Chart.register(ChartDataLabels);
categoriesChart = new Chart(categoriesChartCtx, {
type: 'radar',
data: {
labels: ['शासकीय प्रवन्ध', 'संगठन तथा प्रशासन', 'वार्षिक बजेट तथा योजना', 'वित्तीय एवम् आर्थिक', 'सेवा प्रवाह', 'न्यायिक कार्य सम्पादन', 'भौतिक पूर्वाधार', 'सामाजिक समावेशीकरण', 'वातावरण संरक्षण तथा विपद', 'सहकार्य र समन्वय'],
datasets: [{
label: 'Average Category Scores',
data: calculatePercentageScores(averageCategoryScores),
backgroundColor: 'rgba(54, 162, 235, 0.2)',
borderColor: 'rgba(54, 162, 235, 1)',
borderWidth: 1
}]
},
options: {
responsive: true, // Ensure the chart resizes with the screen
maintainAspectRatio: false, // Allow the chart to adjust its aspect ratio
scales: {
r: {
angleLines: {
display: true
},
suggestedMin: 0,
suggestedMax: 100
}
}
}
});
// Update table
lgTableBody.innerHTML = '';
filteredData.forEach(item => {
const row = document.createElement('tr');
const nameCell = document.createElement('td');
nameCell.textContent = item.name;
row.appendChild(nameCell);
for (let i = 1; i <= 10; i++) {
const cell = document.createElement('td');
cell.textContent = item.categories[i] !== undefined ? item.categories[i] : 'N/A';
row.appendChild(cell);
}
lgTableBody.appendChild(row);
});
// Render bar chart
const labels = filteredData.map(item => item.name);
const scores = filteredData.map(item => item.score);
if (barChart) {
barChart.destroy();
}
barChart = new Chart(barChartCtx, {
type: 'bar',
data: {
labels: labels,
datasets: [{
label: 'Scores of Local Governments',
data: scores,
}]
},
options: {
responsive: true, // Ensure the chart resizes with the screen
maintainAspectRatio: false, // Allow the chart to adjust its aspect ratio
scales: {
y: {
beginAtZero: true
}
}
}
});
}
// Initial data update
updateData();
});
</script>