-
Notifications
You must be signed in to change notification settings - Fork 0
/
statistics.php
375 lines (354 loc) · 13.8 KB
/
statistics.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
<?php
include 'db_connection.php';
$isLoading = true;
$currentQuarter = 1;
if (isset($_GET["year"])) {
$currentYear = $_GET["year"];
if (isset($_POST['quarter'])) {
$currentQuarter = $_POST['quarter'];
}
$sql = "SELECT record_id, qualitative_data_1.weather_condition, qualitative_data_2.humidity,
qualitative_data_3.wind, qualitative_data_4.visibility, qualitative_data_5.fog,
temprature_celsius, humidity_percent, air_pressure, precipitation_percent,
quantitative_data.visibility AS visibility_km, cloud_cover_percent, record_date FROM
quantitative_data INNER JOIN qualitative_data_1 ON
quantitative_data.weather_condition_id = qualitative_data_1.weather_condition_id
INNER JOIN qualitative_data_2 ON quantitative_data.humidity_id = qualitative_data_2.humidity_id
INNER JOIN qualitative_data_3 ON quantitative_data.wind_id = qualitative_data_3.wind_id
INNER JOIN qualitative_data_4 ON quantitative_data.visibility_id = qualitative_data_4.visibility_id
INNER JOIN qualitative_data_5 ON quantitative_data.fog_id = qualitative_data_5.fog_id
WHERE YEAR(record_date) = ? AND QUARTER(record_date) = ?
ORDER BY record_date";
$stmt = $conn->prepare($sql);
if ($stmt) {
$stmt->bind_param("ii", $currentYear, $currentQuarter);
$stmt->execute();
}
$result = $stmt->get_result();
$isLoading = false;
$conn->close();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Titillium+Web&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<link rel="shortcut icon" href="assets/logo.png" type="image/x-icon">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css">
<link rel="stylesheet" href="css/main.css">
<link rel="stylesheet" href="css/statistics.css">
<title>MySKYL | Statistics</title>
</head>
<body>
<header>
<nav class="navbar navbar-expand-md navbar-light">
<a class="navbar-brand" href="index.php?year=2018"><img src="assets/logo.png" alt="logo" class="logo"></a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<img src="assets/navbar-toggler.png" alt="navbar-toggler" class="navbar-toggler-icon">
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="index.php?year=2018">HOME</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="statistics.php?year=2018">STATISTICS</a>
</li>
<li class="nav-item">
<a class="nav-link" href="add_data.php">ADD DATA</a>
</li>
</ul>
</div>
</nav>
</header>
<main class="container-fluid">
<?php
if (!$isLoading) {
echo '<section class="row justify-content-center' . (!$isLoading ? ' animate__animated animate__bounceInDown' : '') . '">
<div class="header col-12">
<h3>ANALYSIS OF THE WEATHER RECORDS</h3>
<p>“A change in the weather is sufficient to recreate the world and ourselves” - Marcel Proust
</p>
</div>
</section>
<section class="row justify-content-center mb-4">
<div class="col-lg-7 col-md-9">
<div class="row">
<div class="col-sm-4 btn-col">
<a class="category-btn ' . ($_GET["year"] == 2018 ? "active" : "") . '"
href="statistics.php?year=2018">2018</a>
</div>
<div class="col-sm-4 btn-col">
<a class="category-btn ' . ($_GET["year"] == 2019 ? "active" : "") . '"
href="statistics.php?year=2019">2019</a>
</div>
<div class="col-sm-4 btn-col">
<a class="category-btn ' . ($_GET["year"] == 2020 ? "active" : "") . '"
href="statistics.php?year=2020">2020</a>
</div>
</div>
</div>
</section>';
echo "<section class='row justify-content-center mb-4'>
<div class='col-lg-4 col-sm-6 col-9'>
<span class='data-per-header'>DISPLAY DATA FOR</span>
<form action='' method='POST'>
<select name='quarter' class='custom-select'>
<option " . ($currentQuarter == 1 ? 'selected' : '') . " value='1'>First quarter</option>
<option " . ($currentQuarter == 2 ? 'selected' : '') . " value='2'>Second quarter</option>
<option " . ($currentQuarter == 3 ? 'selected' : '') . " value='3'>Third quarter</option>
<option " . ($currentQuarter == 4 ? 'selected' : '') . " value='4'>Fourth quarter</option>
</select>
<button class='custom-btn' name='show' type='submit'>Show</button>
</form>
</div>
</section>
<section>
<div class='row'>
<div class='col-lg-6'>
<canvas class='temperature-chart'></canvas>
</div>
<div class='col-lg-6'>
<canvas class='humidity-chart'></canvas>
</div>
</div>
<div class='row mt-4 row animate__delay-1s'>
<div class='col-lg-6'>
<canvas class='airpressure-chart'></canvas>
</div>
<div class='col-lg-6'>
<canvas class='precipitation-chart'></canvas>
</div>
</div>
</section>";
} else {
echo '<section class="loader-wrapper">
<div class="loader"></div>
</section>';
}
?>
</main>
<script>
document.addEventListener("DOMContentLoaded", function() {
if (window.location.href.indexOf("year") === -1) {
const aTag = document.createElement("a");
aTag.href = "statistics.php?year=2018";
document.body.appendChild(aTag);
aTag.click();
aTag.remove();
}
});
</script>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js">
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js">
</script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js">
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.min.js"></script>
<script>
const labels = [<?php while ($row = $result->fetch_assoc()) {echo '"' . date_format(date_create($row["record_date"]), "j M") . '",';}?>];
<?php mysqli_data_seek($result, 0);?>
const temp_data = [<?php while ($row = $result->fetch_assoc()) {echo '"' . $row["temprature_celsius"] . '",';}?>];
<?php mysqli_data_seek($result, 0);?>
const humidity_data = [<?php while ($row = $result->fetch_assoc()) {echo '"' . $row["humidity_percent"] . '",';}?>];
<?php mysqli_data_seek($result, 0);?>
const airpressure_data = [<?php while ($row = $result->fetch_assoc()) {echo '"' . $row["air_pressure"] . '",';}?>];
<?php mysqli_data_seek($result, 0);?>
const precipitation_data = [<?php while ($row = $result->fetch_assoc()) {echo '"' . $row["precipitation_percent"] . '",';}?>];
const temp_ctx = document.querySelector('.temperature-chart');
const tempChart = new Chart(temp_ctx, {
type: 'line',
data: {
labels: [...labels],
datasets: [{
label: 'Change in temperature',
data: [...temp_data],
borderColor: '#50759F',
backgroundColor: "#e5e5e5",
borderWidth: 2,
}]
},
options: {
legend: {
labels: {
fontColor: "white",
fontSize: 18,
fontStyle: "bold",
fontFamily: 'Titillium Web',
boxWidth: 0
},
onClick: (e) => e.stopPropagation()
},
scales: {
yAxes: [{
ticks: {
beginAtZero: true,
fontColor: "white",
stepSize: 15
},
labelString: "Temperature",
gridLines: {
drawOnChartArea: false
}
}],
xAxes: [{
ticks: {
fontColor: "white"
},
gridLines: {
drawOnChartArea: false
}
}]
}
}
});
const humidity_ctx = document.querySelector('.humidity-chart');
const humidityChart = new Chart(humidity_ctx, {
type: 'line',
data: {
labels: [...labels],
datasets: [{
label: 'Evolution of humidity percentage',
data: [...humidity_data],
borderColor: '#50759F',
backgroundColor: "#e5e5e5",
borderWidth: 2,
}]
},
options: {
legend: {
labels: {
fontColor: "white",
fontSize: 18,
fontStyle: "bold",
fontFamily: 'Titillium Web',
boxWidth: 0
},
onClick: (e) => e.stopPropagation()
},
scales: {
yAxes: [{
ticks: {
beginAtZero: true,
fontColor: "white",
stepSize: 15
},
labelString: "Temperature",
gridLines: {
drawOnChartArea: false
}
}],
xAxes: [{
ticks: {
fontColor: "white"
},
gridLines: {
drawOnChartArea: false
}
}]
}
}
});
const airpressure_ctx = document.querySelector('.airpressure-chart');
const airpressureChart = new Chart(airpressure_ctx, {
type: 'line',
data: {
labels: [...labels],
datasets: [{
label: 'Variation of air pressure',
data: [...airpressure_data],
borderColor: '#50759F',
backgroundColor: "#e5e5e5",
borderWidth: 2,
}]
},
options: {
legend: {
labels: {
fontColor: "white",
fontSize: 18,
fontStyle: "bold",
fontFamily: 'Titillium Web',
boxWidth: 0
},
onClick: (e) => e.stopPropagation()
},
scales: {
yAxes: [{
ticks: {
beginAtZero: true,
fontColor: "white",
stepSize: 200
},
labelString: "Temperature",
gridLines: {
drawOnChartArea: false
}
}],
xAxes: [{
ticks: {
fontColor: "white"
},
gridLines: {
drawOnChartArea: false
}
}]
}
}
});
const precipitation_ctx = document.querySelector('.precipitation-chart');
const precipitationChart = new Chart(precipitation_ctx, {
type: 'line',
data: {
labels: [...labels],
datasets: [{
label: 'Change of precipitation percentage',
data: [...precipitation_data],
borderColor: '#50759F',
backgroundColor: "#e5e5e5",
borderWidth: 2,
}]
},
options: {
legend: {
labels: {
fontColor: "white",
fontSize: 18,
fontStyle: "bold",
fontFamily: 'Titillium Web',
boxWidth: 0
},
onClick: (e) => e.stopPropagation()
},
scales: {
yAxes: [{
ticks: {
beginAtZero: true,
fontColor: "white",
stepSize: 15
},
labelString: "Temperature",
gridLines: {
drawOnChartArea: false
},
}],
xAxes: [{
ticks: {
fontColor: "white"
},
gridLines: {
drawOnChartArea: false
}
}]
}
}
});
</script>
</body>
</html>