-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_stats.php
More file actions
92 lines (78 loc) · 1.99 KB
/
Copy pathget_stats.php
File metadata and controls
92 lines (78 loc) · 1.99 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
<?php
class MyDB extends SQLite3
{
function __construct() {
$this->open('stats_db', SQLITE3_OPEN_READONLY);
}
}
function doesEntryExist($database, $table, $column_num, $data) {
$db_data = $database->query('SELECT * FROM '.$table);
while($x = $db_data->fetchArray(SQLITE3_NUM)) {
if(strcmp($x[$column_num], $data) == 0) {
return true;
}
}
return false;
}
/* get type from URL */
$typeOfStats = htmlspecialchars($_GET["type"]);
$typeOfTime = htmlspecialchars($_GET["from"]);
date_default_timezone_set('Europe/Paris');
$db = new MyDB();
$currentDay = date("d-m-Y");
$period = new DatePeriod(
new DateTime($typeOfTime),
new DateInterval('P1D'),
new DateTime(date("d-m-Y", time() + (60 * 60)))
);
$dArray = [];
foreach ($period as $key => $value) {
for ($i=0; $i < 24; $i++) {
array_push($dArray, $value->format('d-m-Y')." ".sprintf("%02d", $i));
}
}
list($aH) = sscanf(date("H"), "%02d");
for ($j=0; $j <= $aH; $j++) {
array_push($dArray, date("d-m-Y")." ".sprintf("%02d", $j));
}
$dataPt = [];
foreach($dArray as $d) {
$s = $db->prepare('SELECT value_of FROM '.$typeOfStats.' WHERE date_time = :dat');
$s->bindValue(":dat", $d);
$q = $s->execute();
while($x = $q->fetchArray(SQLITE3_NUM)) {
$td = DateTime::createFromFormat('d-m-Y H', $d);
array_push($dataPt, array("x" => $td->getTimestamp()*1000, "y" => $x[0]));
}
}
?>
<!DOCTYPE HTML>
<html>
<head>
<script>
window.onload = function () {
var chart = new CanvasJS.Chart("chartContainer", {
title:{
text: "<?php echo "Users for ".$typeOfStats ?>"
},
axisY: {
title: "User Count",
},
data: [{
type: "splineArea",
color: "#6599FF",
markerSize: 5,
xValueFormatString: "DD-MM-YYYY HH:mm",
xValueType: "dateTime",
dataPoints: <?php echo json_encode($dataPt, JSON_NUMERIC_CHECK); ?>
}]
});
chart.render();
}
</script>
</head>
<body>
<div id="chartContainer" style="height: 50%; width: 100%;"></div>
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
</body>
</html>