From 4a53471e8883c880d751a8ef81b0e6229cf4f037 Mon Sep 17 00:00:00 2001 From: loviuz Date: Sat, 8 Aug 2020 18:26:50 +0200 Subject: [PATCH] Aggiunta pagina con device per orario --- gui/js/wifi-probe-aggregator.js | 103 ++++++++++++++++++++++++++ gui/orari.php | 127 +++++++------------------------- ws/reader.php | 119 ++++++++++++++++++++++++++++++ 3 files changed, 250 insertions(+), 99 deletions(-) diff --git a/gui/js/wifi-probe-aggregator.js b/gui/js/wifi-probe-aggregator.js index 4e7926a..7296ea4 100644 --- a/gui/js/wifi-probe-aggregator.js +++ b/gui/js/wifi-probe-aggregator.js @@ -86,4 +86,107 @@ function number_format(number, decimals, dec_point, thousands_sep) { s[1] += new Array(prec - s[1].length + 1).join('0'); } return s.join(dec); +} + +// Add a helper to format timestamp data +Date.prototype.formatMMDDYYYY = function() { + return (this.getMonth() + 1) + + "/" + this.getDate() + + "/" + this.getFullYear(); +} + +function drawLineChart( id, resource ) { + $.post( reader_url, { op: resource }, function(response){ + response = $.parseJSON(response); + + // Split timestamp and data into separate arrays + var labels = [], data=[] + for( i=0; i - - +
- - -
+
-
-
Dispositivi per orario
-
-
-
- -
+
+
Dispositivi per orario
+
+
+
+
@@ -29,96 +25,29 @@ include('parts/header.php');
+ +
+
+
+
+
Dispositivi per giorno
+
+
+
+ +
+
+
+
+
+ + + close(); } break; + + + case 'get-devices-by-hour': + // Connessione al database + $mysqli = mysqli_connect($config['db_host'], $config['db_user'], $config['db_pass'], $config['db_name']); + + // Errore nella connessione a database + if (mysqli_connect_errno($mysqli)) { + + $result = [ + 'status' => 'ERR', + 'message' => mysqli_connect_error(), + ]; + } else { + // Lettura numero di device unico nell'intervallo di date + $sql = " + SELECT + CONCAT( DATE_FORMAT(received_at, '%H'), ':00' ) AS indice, + COUNT(DISTINCT(mac)) AS valore + FROM + `logs` + GROUP BY + DATE_FORMAT(received_at, '%H')"; + + $stmt = $mysqli->prepare($sql); + + // Errore nella preparazione query + if (!$stmt) { + $result = [ + 'status' => 'ERR', + 'message' => $mysqli->error, + ]; + } else { + // Esecuzione statement + $stmt->execute(); + + $rs = $stmt->get_result(); + + while ($row = $rs->fetch_assoc()) { + $records[] = $row; + } + + $result = [ + 'status' => 'OK', + 'records' => $records, + ]; + } + } + + echo json_encode($result); + + $stmt->close(); + $mysqli->close(); + break; + + + case 'get-devices-by-weekday': + $weekdays = [ + 0 => 'domenica', + 1 => 'lunedì', + 2 => 'martedì', + 3 => 'mercoledì', + 4 => 'giovedì', + 5 => 'venerdì', + 6 => 'sabato', + ]; + + // Connessione al database + $mysqli = mysqli_connect($config['db_host'], $config['db_user'], $config['db_pass'], $config['db_name']); + + // Errore nella connessione a database + if (mysqli_connect_errno($mysqli)) { + + $result = [ + 'status' => 'ERR', + 'message' => mysqli_connect_error(), + ]; + } else { + // Lettura numero di device unico nell'intervallo di date + $sql = " + SELECT + DATE_FORMAT(received_at, '%w') AS indice, + COUNT(DISTINCT(mac)) AS valore + FROM + `logs` + GROUP BY + DATE_FORMAT(received_at, '%w')"; + + $stmt = $mysqli->prepare($sql); + + // Errore nella preparazione query + if (!$stmt) { + $result = [ + 'status' => 'ERR', + 'message' => $mysqli->error, + ]; + } else { + // Esecuzione statement + $stmt->execute(); + + $rs = $stmt->get_result(); + + while ($row = $rs->fetch_assoc()) { + $row['indice'] = $weekdays[ $row['indice'] ]; + $records[] = $row; + } + + $result = [ + 'status' => 'OK', + 'records' => $records, + ]; + } + } + + echo json_encode($result); + + $stmt->close(); + $mysqli->close(); + break; }