-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbt-mysql-report.php
136 lines (119 loc) · 3.99 KB
/
bt-mysql-report.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
<?php
//This script tries to visualize the number of Bluetooth devices discovered
//during differnt time spans
$servername="localhost";
$username="bt_user";
$password="123456";
$db="bluetooth";
$conn = new mysqli($servername,$username,$password,$db);
echo "<div>";
//Create Report that shows results for each MINUTE
echo "<div style='display:inline-block; margin-right:50px;'>";
$sql = "select * from log order by id desc";
$result = $conn->query($sql);
echo "<h2> BT Devices Detected per MINUTE</h2>";
echo "<table>
<tr><th>Day/ Minute</th><th># of Devices</th><th></th></tr>";
while($row = $result->fetch_assoc()){
$bt_all = $row['bt_list'];
$address = explode(",",$bt_all);
$count = count($address);
echo "<tr><td>";
echo date('d H:i:s',$row['timestamp'])."</td>";
echo "<td>$count</td>";
echo "<td>";
for($x = 0; $x <= $count; $x++){
echo "|";
}
echo "</td></tr>";
}
echo "</table>";
echo "</div>";
//Create Report that shows results for each HOUR
echo "<div style='display:inline-block; margin-right:50px;'>";
echo "<h2> BT Devices Detected per HOUR</h2>";
$sql = "select * from log order by id desc";
$result = $conn->query($sql);
$key_array = array();
while($row = $result->fetch_assoc()){
$time_code = date('d-H',$row['timestamp']);
$bt_all = $row['bt_list'];
$address = explode(",",$bt_all);
$count = count($address);
$key_array[$time_code] = $key_array[$time_code] + $count;
}
echo "<table>
<tr><th>Day/ Hour</th><th># of Devices</th><th></th></tr>";
foreach($key_array as $key => $value){
//$value2 divides total BT devices detected by approx. number of scans per hour
$value2 = intval($value/47);
echo "<tr><td>$key</td><td>$value2</td><td>";
for($x=0; $x <= $value2; $x++){
if($x >= min($key_array)/60){
echo "|";
}
}
echo "</td></tr>";
}
echo "</table>";
echo "</div>";
//Create Report that shows results for each DAY
echo "<div style='display:inline-block; margin-right:50px;'>";
echo "<h2> BT Devices Detected per DAY</h2>";
$sql = "select * from log order by id desc";
$result = $conn->query($sql);
$key_array = array();
while($row = $result->fetch_assoc()){
$time_code = date('d',$row['timestamp']);
$bt_all = $row['bt_list'];
$address = explode(",",$bt_all);
$count = count($address);
$key_array[$time_code] = $key_array[$time_code] + $count;
}
echo "<table>
<tr><th>Day</th><th># of Devices</th><th></th></tr>";
foreach($key_array as $key => $value){
//$value2 divides total BT devices detected by approx. number of scans per hour
$value2 = intval($value/47);
echo "<tr><td>$key</td><td>$value2</td><td>";
//in for loop increment $x by 5 to shrink the size of the chart
for($x=0; $x <= $value2; $x = $x+5){
if($x >= min($key_array)/60){
echo "|";
}
}
echo "</td></tr>";
}
echo "</table>";
echo "</div>";
//Create Report that shows results for Culumnlative HOUR
echo "<div style='display:inline-block;'>";
echo "<h2> Busiest Hour of Day</h2>";
$sql = "select * from log order by id desc";
$result = $conn->query($sql);
$key_array = array();
while($row = $result->fetch_assoc()){
$time_code = date('H',$row['timestamp']);
$bt_all = $row['bt_list'];
$address = explode(",",$bt_all);
$count = count($address);
$key_array[$time_code] = $key_array[$time_code] + $count;
}
ksort($key_array);
echo "<table>
<tr><th>Hour</th><th># of Devices</th><th></th></tr>";
foreach($key_array as $key => $value){
//$value2 divides total BT devices detected by approx. number of scans per hour
$value2 = intval($value/47);
echo "<tr><td>$key</td><td>$value2</td><td>";
for($x=0; $x <= $value2; $x++){
if($x >= min($key_array)/60){
echo "|";
}
}
echo "</td></tr>";
}
echo "</table>";
echo "</div>";
echo "</div>";
?>