summaryrefslogtreecommitdiff
path: root/pages/stats.inc
diff options
context:
space:
mode:
Diffstat (limited to 'pages/stats.inc')
-rw-r--r--pages/stats.inc226
1 files changed, 226 insertions, 0 deletions
diff --git a/pages/stats.inc b/pages/stats.inc
index 75b9e9d..510c317 100644
--- a/pages/stats.inc
+++ b/pages/stats.inc
@@ -263,6 +263,232 @@ $switchesCloudburst = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] .
}
});
</script>
+
+ <h3 style="margin-top: 15px;">Average switches per day of the week</h3>
+ <canvas id="graph-01" style="width: 100%; height: 300px; max-height: 100%;"></canvas>
+ <?php
+
+ $switchesDaysRaindrops = [0, 0, 0, 0, 0, 0, 0];
+ $amountDaysRaindrops = [0, 0, 0, 0, 0, 0, 0];
+ $switchDoWRaindrops = [0, 0, 0, 0, 0, 0, 0];
+ $daysRaindrops = [];
+
+ $switchesDaysCloudburst = [0, 0, 0, 0, 0, 0, 0];
+ $amountDaysCloudburst = [0, 0, 0, 0, 0, 0, 0];
+ $switchDoWCloudburst = [0, 0, 0, 0, 0, 0, 0];
+ $daysCloudburst = [];
+
+ foreach ($switchesCloudburst as $switch) {
+ if (!in_array(date("Y-m-d", strtotime($switch["timestamp"])), $daysCloudburst)) {
+ $daysCloudburst[] = date("Y-m-d", strtotime($switch["timestamp"]));
+ $amountDaysCloudburst[(int)date('N', strtotime($switch["timestamp"])) - 1]++;
+ }
+
+ $switchesDaysCloudburst[(int)date('N', strtotime($switch["timestamp"])) - 1]++;
+ }
+
+ $switchDoWCloudburst = [
+ $switchesDaysCloudburst[0] / $amountDaysCloudburst[0],
+ $switchesDaysCloudburst[1] / $amountDaysCloudburst[1],
+ $switchesDaysCloudburst[2] / $amountDaysCloudburst[2],
+ $switchesDaysCloudburst[3] / $amountDaysCloudburst[3],
+ $switchesDaysCloudburst[4] / $amountDaysCloudburst[4],
+ $switchesDaysCloudburst[5] / $amountDaysCloudburst[5],
+ $switchesDaysCloudburst[6] / $amountDaysCloudburst[6]
+ ];
+
+ foreach ($switchesRaindrops as $switch) {
+ if (!in_array(date("Y-m-d", strtotime($switch["timestamp"])), $daysRaindrops)) {
+ $daysRaindrops[] = date("Y-m-d", strtotime($switch["timestamp"]));
+ $amountDaysRaindrops[(int)date('N', strtotime($switch["timestamp"])) - 1]++;
+ }
+
+ $switchesDaysRaindrops[(int)date('N', strtotime($switch["timestamp"])) - 1]++;
+ }
+
+ $switchDoWRaindrops = [
+ $switchesDaysRaindrops[0] / $amountDaysRaindrops[0],
+ $switchesDaysRaindrops[1] / $amountDaysRaindrops[1],
+ $switchesDaysRaindrops[2] / $amountDaysRaindrops[2],
+ $switchesDaysRaindrops[3] / $amountDaysRaindrops[3],
+ $switchesDaysRaindrops[4] / $amountDaysRaindrops[4],
+ $switchesDaysRaindrops[5] / $amountDaysRaindrops[5],
+ $switchesDaysRaindrops[6] / $amountDaysRaindrops[6]
+ ];
+
+ $switchDoW = [
+ $switchDoWCloudburst[0] + $switchDoWRaindrops[0],
+ $switchDoWCloudburst[1] + $switchDoWRaindrops[1],
+ $switchDoWCloudburst[2] + $switchDoWRaindrops[2],
+ $switchDoWCloudburst[3] + $switchDoWRaindrops[3],
+ $switchDoWCloudburst[4] + $switchDoWRaindrops[4],
+ $switchDoWCloudburst[5] + $switchDoWRaindrops[5],
+ $switchDoWCloudburst[6] + $switchDoWRaindrops[6]
+ ];
+
+ ?>
+ <script>
+ const ctx1 = document.getElementById('graph-01').getContext('2d');
+ window.chart01 = [
+ {
+ label: "Switches per week",
+ data: JSON.parse(`<?= json_encode($switchDoW) ?>`),
+ backgroundColor: [
+ 'rgba(255, 99, 132, 0.2)',
+ 'rgba(255, 159, 64, 0.2)',
+ 'rgba(255, 205, 86, 0.2)',
+ 'rgba(75, 192, 192, 0.2)',
+ 'rgba(54, 162, 235, 0.2)',
+ 'rgba(153, 102, 255, 0.2)',
+ 'rgba(201, 203, 207, 0.2)'
+ ],
+ borderColor: [
+ 'rgb(255, 99, 132)',
+ 'rgb(255, 159, 64)',
+ 'rgb(255, 205, 86)',
+ 'rgb(75, 192, 192)',
+ 'rgb(54, 162, 235)',
+ 'rgb(153, 102, 255)',
+ 'rgb(201, 203, 207)'
+ ],
+ borderWidth: 1
+ }
+ ];
+ const graph1 = new Chart(ctx1, {
+ type: 'bar',
+ data: {
+ labels: ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
+ datasets: window.chart01
+ },
+ options: {
+ animation: {
+ duration: 0
+ },
+ scales: {
+ y: {
+ grid: {
+ color: "rgba(255,255,255,0.25)"
+ }
+ }
+ },
+ plugins: {
+ legend: {
+ display: false
+ },
+ tooltip: {
+ intersect: false
+ }
+ }
+ }
+ });
+ </script>
+
+ <h3 style="margin-top: 15px;">Switches per hour of the day</h3>
+ <canvas id="graph-02" style="width: 100%; height: 300px; max-height: 100%;"></canvas>
+ <?php
+
+ $switchHoursRaindrops = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
+ $switchHoursCloudburst = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
+
+ foreach ($switchesCloudburst as $switch) {
+ $switchHoursCloudburst[(int)date('G', strtotime($switch["timestamp"]))]++;
+ }
+
+ foreach ($switchesRaindrops as $switch) {
+ $switchHoursRaindrops[(int)date('G', strtotime($switch["timestamp"]))]++;
+ }
+
+ $switchHours = [
+ $switchHoursRaindrops[0] + $switchHoursCloudburst[0],
+ $switchHoursRaindrops[1] + $switchHoursCloudburst[1],
+ $switchHoursRaindrops[2] + $switchHoursCloudburst[2],
+ $switchHoursRaindrops[3] + $switchHoursCloudburst[3],
+ $switchHoursRaindrops[4] + $switchHoursCloudburst[4],
+ $switchHoursRaindrops[5] + $switchHoursCloudburst[5],
+ $switchHoursRaindrops[6] + $switchHoursCloudburst[6],
+ $switchHoursRaindrops[7] + $switchHoursCloudburst[7],
+ $switchHoursRaindrops[8] + $switchHoursCloudburst[8],
+ $switchHoursRaindrops[9] + $switchHoursCloudburst[9],
+ $switchHoursRaindrops[10] + $switchHoursCloudburst[10],
+ $switchHoursRaindrops[11] + $switchHoursCloudburst[11],
+ $switchHoursRaindrops[12] + $switchHoursCloudburst[12],
+ $switchHoursRaindrops[13] + $switchHoursCloudburst[13],
+ $switchHoursRaindrops[14] + $switchHoursCloudburst[14],
+ $switchHoursRaindrops[15] + $switchHoursCloudburst[15],
+ $switchHoursRaindrops[16] + $switchHoursCloudburst[16],
+ $switchHoursRaindrops[17] + $switchHoursCloudburst[17],
+ $switchHoursRaindrops[18] + $switchHoursCloudburst[18],
+ $switchHoursRaindrops[19] + $switchHoursCloudburst[19],
+ $switchHoursRaindrops[20] + $switchHoursCloudburst[20],
+ $switchHoursRaindrops[21] + $switchHoursCloudburst[21],
+ $switchHoursRaindrops[22] + $switchHoursCloudburst[22],
+ $switchHoursRaindrops[23] + $switchHoursCloudburst[23],
+ ];
+
+ ?>
+ <script>
+ const ctx2 = document.getElementById('graph-02').getContext('2d');
+ window.chart02 = [
+ {
+ label: "Switches per hour of day",
+ data: JSON.parse(`<?= json_encode($switchHours) ?>`),
+ borderColor: "rgb(160,255,153)"
+ }
+ ];
+ const graph2 = new Chart(ctx2, {
+ type: 'line',
+ data: {
+ labels: [
+ "12am",
+ "1am",
+ "2am",
+ "3am",
+ "4am",
+ "5am",
+ "6am",
+ "7am",
+ "8am",
+ "9am",
+ "10am",
+ "11am",
+ "12pm",
+ "1pm",
+ "2pm",
+ "3pm",
+ "4pm",
+ "5pm",
+ "6pm",
+ "7pm",
+ "8pm",
+ "9pm",
+ "10pm",
+ "11pm"
+ ],
+ datasets: window.chart02
+ },
+ options: {
+ animation: {
+ duration: 0
+ },
+ scales: {
+ y: {
+ beginAtZero: true,
+ grid: {
+ color: "rgba(255,255,255,0.25)"
+ }
+ }
+ },
+ plugins: {
+ legend: {
+ display: false
+ },
+ tooltip: {
+ intersect: false
+ }
+ }
+ }
+ });
+ </script>
</div>
</div>