-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscoregrade7.php
470 lines (452 loc) · 22 KB
/
scoregrade7.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
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
<?php
session_start();
//check if user is logged in
if(!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true){
header("location: login.php");
exit;
}
require_once "config.php";
$filtervalues = "opener";
$value = "mid-term";
$filter = "end-term";
// data for graph
$sql_avg ="SELECT term1.exam_type, AVG(maths) 'Maths', AVG(english) 'English', AVG(swahili) 'Swahili', AVG(science) 'Science', AVG(social) 'Social', AVG(religious) 'Religious', AVG(total) 'Total' FROM term1 INNER JOIN students ON students.id = term1.id WHERE students.grade=7 AND term1.exam_type = 'opener'
UNION
SELECT term1.exam_type, AVG(maths) 'Maths', AVG(english) 'English', AVG(swahili) 'Swahili', AVG(science) 'Science', AVG(social) 'Social', AVG(religious) 'Religious', AVG(total) 'Total' FROM term1 INNER JOIN students ON students.id = term1.id WHERE students.grade=7 AND term1.exam_type = 'mid-term'
UNION
SELECT term1.exam_type, AVG(maths) 'Maths', AVG(english) 'English', AVG(swahili) 'Swahili', AVG(science) 'Science', AVG(social) 'Social', AVG(religious) 'Religious', AVG(total) 'Total' FROM term1 INNER JOIN students ON students.id = term1.id WHERE students.grade=7 AND term1.exam_type = 'end-term'";
$gradedata = array();
$row = [];
$output = $link->query($sql_avg);
while ($res = mysqli_fetch_assoc($output)) {
$gradedata[] = $res;
}
//write to json file
$fp = fopen('grade7data.json', 'w');
fwrite($fp, json_encode($gradedata));
fclose($fp);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Grade 7 Performance Report</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="myStyle.css">
<link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet" type="text/css">
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<script src="https://use.fontawesome.com/releases/v6.1.0/js/all.js" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>
<script src="https://html2canvas.hertzen.com/dist/html2canvas.min.js"></script>
</head>
<body>
<div class="container-fluid text-center">
<h2 >Performance Report for Grade 7</h2>
</div>
<br>
<div class="container" id="score">
<h3><center>SPIMA Performance Report</center></h3>
<h3><center>Year 2022</center></h3>
<div class="row text-center">
<div class="col-sm" style="border: 1px solid black;"><h3>Grade 7</h3></div>
</div> <hr>
<table class="table table-bordered table-hover">
<thead class="thead-dark">
<tr><th colspan="3">Term 1 2022 Subject performance</th></tr>
</thead>
<thead class="thead-light" style="letter-spacing: 0.01px;">
<tr>
<th scope="col">Exam Period</th>
<th scope="col">Maths</th>
<th scope="col">English</th>
<th scope="col">Swahili</th>
<th scope="col">Science</th>
<th scope="col">Social Studies</th>
<th scope="col">Religious Education</th>
<th scope="col">Total Score</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="col">Opener</th>
<th scope="col">
<?php
$result = $link->query("SELECT AVG(maths) FROM term1 INNER JOIN students ON students.id = term1.id WHERE term1.exam_type ='$filtervalues' AND students.grade=7");
//display data on web page
while($row = mysqli_fetch_array($result)){
echo $row['AVG(maths)'];
}
?>
</th>
<th scope="col">
<?php
$result = $link->query("SELECT AVG(english) FROM term1 INNER JOIN students ON students.id = term1.id WHERE term1.exam_type ='$filtervalues' AND students.grade=7");
//display data on web page
while($row = mysqli_fetch_array($result)){
echo $row['AVG(english)'];
}
?>
</th>
<th scope="col">
<?php
$result = $link->query("SELECT AVG(swahili) FROM term1 INNER JOIN students ON students.id = term1.id WHERE term1.exam_type ='$filtervalues' AND students.grade=7");
//display data on web page
while($row = mysqli_fetch_array($result)){
echo $row['AVG(swahili)'];
}
?>
</th>
<th scope="col">
<?php
$result = $link->query("SELECT AVG(science) FROM term1 INNER JOIN students ON students.id = term1.id WHERE term1.exam_type ='$filtervalues' AND students.grade=7");
//display data on web page
while($row = mysqli_fetch_array($result)){
echo $row['AVG(science)'];
}
?>
</th>
<th scope="col">
<?php
$result = $link->query("SELECT AVG(social) FROM term1 INNER JOIN students ON students.id = term1.id WHERE term1.exam_type ='$filtervalues' AND students.grade=7");
//display data on web page
while($row = mysqli_fetch_array($result)){
echo $row['AVG(social)'];
}
?>
</th>
<th scope="col">
<?php
$result = $link->query("SELECT AVG(religious) FROM term1 INNER JOIN students ON students.id = term1.id WHERE term1.exam_type ='$filtervalues' AND students.grade=7");
//display data on web page
while($row = mysqli_fetch_array($result)){
echo $row['AVG(religious)'];
}
?>
</th>
<th scope="col">
<?php
$result = $link->query("SELECT AVG(total) FROM term1 INNER JOIN students ON students.id = term1.id WHERE term1.exam_type ='$filtervalues' AND students.grade=7");
//display data on web page
while($row = mysqli_fetch_array($result)){
echo $row['AVG(total)'];
}
?>
</th>
</tr>
<tr>
<th scope="col">Mid Term</th>
<th scope="col">
<?php
$result = $link->query("SELECT AVG(maths) FROM term1 INNER JOIN students ON students.id = term1.id WHERE term1.exam_type ='$value' AND students.grade=7");
//display data on web page
while($row = mysqli_fetch_array($result)){
echo $row['AVG(maths)'];
}
?>
</th>
<th scope="col">
<?php
$result = $link->query("SELECT AVG(english) FROM term1 INNER JOIN students ON students.id = term1.id WHERE term1.exam_type ='$value' AND students.grade=7");
//display data on web page
while($row = mysqli_fetch_array($result)){
echo $row['AVG(english)'];
}
?>
</th>
<th scope="col">
<?php
$result = $link->query("SELECT AVG(swahili) FROM term1 INNER JOIN students ON students.id = term1.id WHERE term1.exam_type ='$value' AND students.grade=7");
//display data on web page
while($row = mysqli_fetch_array($result)){
echo $row['AVG(swahili)'];
}
?>
</th>
<th scope="col">
<?php
$result = $link->query("SELECT AVG(science) FROM term1 INNER JOIN students ON students.id = term1.id WHERE term1.exam_type ='$value' AND students.grade=7");
//display data on web page
while($row = mysqli_fetch_array($result)){
echo $row['AVG(science)'];
}
?>
</th>
<th scope="col">
<?php
$result = $link->query("SELECT AVG(social) FROM term1 INNER JOIN students ON students.id = term1.id WHERE term1.exam_type ='$value' AND students.grade=7");
//display data on web page
while($row = mysqli_fetch_array($result)){
echo $row['AVG(social)'];
}
?>
</th>
<th scope="col">
<?php
$result = $link->query("SELECT AVG(religious) FROM term1 INNER JOIN students ON students.id = term1.id WHERE term1.exam_type ='$value' AND students.grade=7");
//display data on web page
while($row = mysqli_fetch_array($result)){
echo $row['AVG(religious)'];
}
?>
</th>
<th scope="col">
<?php
$result = $link->query("SELECT AVG(total) FROM term1 INNER JOIN students ON students.id = term1.id WHERE term1.exam_type ='$value' AND students.grade=7");
//display data on web page
while($row = mysqli_fetch_array($result)){
echo $row['AVG(total)'];
}
?>
</th>
</tr>
<tr>
<th scope="col">End Term</th>
<th scope="col">
<?php
$result = $link->query("SELECT AVG(maths) FROM term1 INNER JOIN students ON students.id = term1.id WHERE term1.exam_type ='$filter' AND students.grade=7");
//display data on web page
while($row = mysqli_fetch_array($result)){
echo $row['AVG(maths)'];
}
?>
</th>
<th scope="col">
<?php
$result = $link->query("SELECT AVG(english) FROM term1 INNER JOIN students ON students.id = term1.id WHERE term1.exam_type ='$filter' AND students.grade=7");
//display data on web page
while($row = mysqli_fetch_array($result)){
echo $row['AVG(english)'];
}
?>
</th>
<th scope="col">
<?php
$result = $link->query("SELECT AVG(swahili) FROM term1 INNER JOIN students ON students.id = term1.id WHERE term1.exam_type ='$filter' AND students.grade=7");
//display data on web page
while($row = mysqli_fetch_array($result)){
echo $row['AVG(swahili)'];
}
?>
</th>
<th scope="col">
<?php
$result = $link->query("SELECT AVG(science) FROM term1 INNER JOIN students ON students.id = term1.id WHERE term1.exam_type ='$filter' AND students.grade=7");
//display data on web page
while($row = mysqli_fetch_array($result)){
echo $row['AVG(science)'];
}
?>
</th>
<th scope="col">
<?php
$result = $link->query("SELECT AVG(social) FROM term1 INNER JOIN students ON students.id = term1.id WHERE term1.exam_type ='$filter' AND students.grade=7");
//display data on web page
while($row = mysqli_fetch_array($result)){
echo $row['AVG(social)'];
}
?>
</th>
<th scope="col">
<?php
$result = $link->query("SELECT AVG(religious) FROM term1 INNER JOIN students ON students.id = term1.id WHERE term1.exam_type ='$filter' AND students.grade=7");
//display data on web page
while($row = mysqli_fetch_array($result)){
echo $row['AVG(religious)'];
}
?>
</th>
<th scope="col">
<?php
$result = $link->query("SELECT AVG(total) FROM term1 INNER JOIN students ON students.id = term1.id WHERE term1.exam_type ='$filter' AND students.grade=7");
//display data on web page
while($row = mysqli_fetch_array($result)){
echo $row['AVG(total)'];
}
?>
</th>
</tr>
</tbody>
</table>
<hr>
<div class="container" id="chart-container" style="width: 80%;">
<canvas id="mycanvas"></canvas> <hr>
<canvas id="mycanvas2"></canvas>
</div>
</div>
<div class="container text-center">
<button id="download" class="btn btn-success">Export to PDF</button>
<hr>
</div>
</body>
<script src="//code.jquery.com/jquery-1.9.1.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/Chart.js/2.4.0/Chart.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$.ajax({
url: "grade7data.json",
method: "GET",
success: function(gradedata) {
console.log(gradedata);
var exam = [];
var maths = [];
var english = [];
var swahili = [];
var science = [];
var social = [];
var religious = [];
var total = [];
for(var i in gradedata) {
exam.push(gradedata[i].exam_type +" exam");
maths.push(gradedata[i].Maths);
english.push(gradedata[i].English);
swahili.push(gradedata[i].Swahili);
science.push(gradedata[i].Science);
social.push(gradedata[i].Social);
religious.push(gradedata[i].Religious);
total.push(gradedata[i].Total);
}
var ctx = document.getElementById("mycanvas").getContext('2d');
// draw background
var backgroundColor = 'white';
Chart.plugins.register({
beforeDraw: function(c) {
var ctx = c.chart.ctx;
ctx.fillStyle = backgroundColor;
ctx.fillRect(0, 0, c.chart.width, c.chart.height);
}
});
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: exam ,
datasets: [
{
label: "Total Score",
backgroundColor:['#1D8348', '#0E6655', '#21618C'] ,
data: total,
}
]
},
options: {
responsive: true,
legend: {
display: true,
position: 'bottom',
labels: {
fontColor: '#71748d',
fontFamily: 'Circular Std Book',
fontSize: 14,
}
},
title: {
display: true,
text: "Average Class Score Performance Term1"
},
scales: {
yAxes: [{
ticks: {
stepSize: 50,
max: 500,
beginAtZero: true,}
}]
}
}
});
var ctx2 = document.getElementById("mycanvas2").getContext('2d');
var myBarChart = new Chart(ctx2, {
type: 'bar',
data: {
labels: exam ,
datasets: [
{
label: "Maths",
backgroundColor: "purple",
data: maths,
},
{
label: "English",
backgroundColor: "blue",
data: english,
},
{
label: "Swahili",
backgroundColor: "yellow",
data: swahili,
},
{
label: "Science",
backgroundColor: "orange",
data: science,
},
{
label: "Social",
backgroundColor: "green",
data: social,
},
{
label: "Religious",
backgroundColor: "brown",
data: religious,
}
]
},
options: {
responsive: true,
legend: {
display: true,
position: 'bottom',
labels: {
fontColor: '#71748d',
fontFamily: 'Circular Std Book',
fontSize: 14,
}
},
title: {
display: true,
text: "Average Class Subject Score Performance Term1"
},
scales: {
yAxes: [{
ticks: {
stepSize: 10,
max: 100,
beginAtZero: true,}
}]
}
}
});
},
error: function(gradedata) {
var jsDataPlaceholder = <?= json_encode($gradedata); ?>;
console.log(jsDataPlaceholder);
}
});
});
</script>
<script>
var doc = new jspdf.jsPDF({orientation:'p', unit:'pt', format: 'a4'});
margin = 30; // narrow margin - 12.7 mm
let srcwidth = document.getElementById('score').scrollWidth;
let scale = (595.28 - margin * 2) / srcwidth; // a4 pageSize 595.28
function downloadPDFWithjsPDF() {
doc.html(document.querySelector('#score'), {
html2canvas: {
scale: scale, // default is window.devicePixelRatio,
letterRendering:true
},
callback: function (doc) {
doc.save('Grade 7 Score Report.pdf');
},
x: margin,
y: margin,
});
}
document.querySelector('#download').addEventListener('click', downloadPDFWithjsPDF);
</script>
</html>