forked from sa2blv/SVXportal
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathget_statistics.php
381 lines (236 loc) · 10.5 KB
/
get_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
376
377
378
379
380
381
<?php
include_once 'config.php';
// ini_set('display_errors', 1);
// ini_set('display_startup_errors', 1);
// error_reporting(E_ALL);
// Create connection
$conn = new mysqli($host, $user, $password, $db);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$json_array=array();
function secondsToDHMS($seconds) {
$s = (int)$seconds;
if($s >0)
return sprintf('%d:%02d:%02d:%02d', $s/86400, $s/3600%24, $s/60%60, $s%60);
else
return "0:00:00:00";
}
function get_time($station,$day)
{
global $link;
$station_qvery =" AND Callsign ='".$station."' ";
$tme_string ="`Time` BETWEEN '$day 00:00:00.000000' AND '$day 23:59:59.000000'";
//$sql_active ="SELECT sum(UNIX_TIMESTAMP(`Time`)),Callsign FROM RefletorNodeLOG WHERE `Type` = '1' $station_qvery AND `Active` ='1' AND $tme_string group by `Callsign`";
$sql_nonactive ="SELECT sum(Talktime), Callsign FROM RefletorNodeLOG WHERE `Type` = '1'$station_qvery AND `Active` ='0' AND $tme_string group by `Callsign` ";
// echo $sql_active;
// echo "<br>";
//$sqlref = $link->query($sql_active);
$sqla = $link->query($sql_nonactive);
$timesum =array();
while($row = $sqla->fetch_assoc()) {
$timesum[$row["Callsign"]] =$timesum[$row["Callsign"]]+$row["sum(Talktime)"];
}
return $timesum[$station];
}
$moste_used_station = array();
function get_most_use_reciver($day)
{
global $link;
global $moste_used_station;
$tme_string ="`Time` BETWEEN '$day 00:00:00.000000' AND '$day 23:59:00.000000'";
$quvery ="
SELECT MAX(`Nodename`),`Callsign` FROM `RefletorNodeLOG` WHERE $tme_string AND`Type` = 2 AND `Active` = 1 GROUP BY Callsign";
//echo $quvery;
$sqla = $link->query($quvery);
$count_array= array();
while($row2 = $sqla->fetch_assoc())
{
//echo '<pre>';
//var_dump($row2);
$count_array[$row2['Callsign']][$row2['MAX(`Nodename`)']]++;
$moste_used_station[$row2['Callsign']] = $row2['MAX(`Nodename`)'];
}
//echo '<pre>';
arsort($count_array);
while($row2 = $sqla->fetch_assoc())
{
$moste_used_station[$row2['Callsign']] =$count_array[$row2['Callsign']][0];
}
}
$day= $_GET['date'];
$station = $_GET['st'];
$qrv = $_GET['qrv'];
$mouth_s = $_GET['mouth'];
$link->set_charset("utf8");
/*
* Detect if station data
*
*/
if($station != "")
{
$station = $link->real_escape_string($station);
$station_qvery =" AND Callsign ='".$station."' ";
}
else
{
$station_qvery ="";
}
if($mouth_s != "")
{
$day = $link->real_escape_string($day);
$current_year= date("Y",strtotime($day));
if($_GET['filterpicker_repeater_year'] != "")
{
$station = $link->real_escape_string($_GET['filterpicker_repeater_year']);
$station_quvery = "AND Callsign ='$station'";
}
if($_GET['filterpicker_talgroup_year'] != "")
{
$talkgroupid = $link->real_escape_string($_GET['filterpicker_talgroup_year']);
$talkgroup_quvery = "AND Talkgroup ='$talkgroupid'";
}
$sql_stations ="SELECT SUM(`Talktime`),MONTH(`Time`) FROM RefletorNodeLOG
WHERE YEAR(`Time`) = $current_year AND Type='1' and Active='0' $station_quvery $talkgroup_quvery GROUP BY MONTH(`Time`)";
$sqla = $link->query($sql_stations);;
while($row = $sqla->fetch_assoc())
{
$json_array[$row["MONTH(`Time`)"]] ["Secound"] = secondsToDHMS($row['SUM(`Talktime`)']);
$json_array[$row["MONTH(`Time`)"]] ["unixtime"] = $row['SUM(`Talktime`)'];
}
$sql_activity ="SELECT SUM(`Talktime`), MONTH(`Time`) ,DAY(`Time`) FROM RefletorNodeLOG WHERE YEAR(`Time`) = $current_year AND Type='1' and Active='0' $station_quvery $talkgroup_quvery GROUP BY MONTH(`Time`), DAY(`Time`) ORDER BY SUM(`Talktime`) DESC limit 10";
$sqla = $link->query($sql_activity);;
$id=0;
while($row = $sqla->fetch_assoc())
{
$daystring=$current_year."-".$row['MONTH(`Time`)']."-".$row['DAY(`Time`)'];
$json_array["Toplist"][$id]["Secound"] = secondsToDHMS($row['SUM(`Talktime`)']);
$json_array["Toplist"][$id]["unixtime"] = $row['SUM(`Talktime`)'];
$json_array["Toplist"][$id]["day"] =date("Y-m-d",strtotime($daystring)) ;
$id++;
}
//
echo json_encode ($json_array);
}
else if($qrv != "")
{
$qrv = $link->real_escape_string($qrv);
$day = $link->real_escape_string($day);
$tme_string ="`Time` BETWEEN '$day 00:00:00.000000' AND '$day 23:59:59.000000'";
$sql_stations ="SELECT Callsign , sum(Talktime) FROM RefletorNodeLOG WHERE `Type` = '1' and Active='0' AND $tme_string group by `Callsign`";
$sqlstat = $link->query($sql_stations);
$outarray = array();
$i =0;
get_most_use_reciver($day);
$time_total_usage=0;
while($row = $sqlstat->fetch_assoc()) {
$outarray['data'][$i]['call']=$row["Callsign"];
//$outarray['data'][$i]['time'] =get_time($row["Callsign"],$day);
$outarray['data'][$i]['time'] = $row['sum(Talktime)'];
$time_total_usage = $time_total_usage+$outarray['data'][$i]['time'] ;
//$outarray['data'][$i]["Secound"] = secondsToDHMS(get_time($row["Callsign"],$day));
$outarray['data'][$i]["Secound"] = secondsToDHMS($row['sum(Talktime)']);
$outarray['data'][$i]["reciver"] = $moste_used_station[$row["Callsign"]];
$i++;
}
$outarray['total_secounds'] = $time_total_usage;
echo json_encode ($outarray);
}
else if( $_GET['time'] == "true")
{
$day = $link->real_escape_string($day);
//$tme_string ="`Time` BETWEEN '$day $timel:00:00.000000' AND '$day $timel:59:59.000000'";
$tme_string ="`Time` BETWEEN '$day 00:00:00.000000' AND '$day 23:59:59.000000'";
//$sql_active ="SELECT sum(UNIX_TIMESTAMP(`Time`)), `Talkgroup` FROM RefletorNodeLOG WHERE `Type` = '1' $station_qvery AND `Active` ='1' AND $tme_string group by `Talkgroup`";
$sql_nonactive ="SELECT UNIX_TIMESTAMP(Time), Talktime, `Talkgroup` FROM RefletorNodeLOG WHERE `Type` = '1' $station_qvery AND `Active` ='0' AND $tme_string ";
$sqla = $link->query($sql_nonactive);
$data = array();
while($row = $sqla->fetch_assoc()) {
$data[] = $row;
}
for($timel =0; $timel <= 24;$timel++)
{
$filterdate = strtotime($day);
$low_time =$filterdate+ ($timel*3600);
$high_time =$filterdate+ ($timel*3600)+(59*60)+59;
$timesum =array();
$timiesums =array();
$timiesums[$timel] =0;
// loop throu remove row if match is found
foreach ($data as & $row) {
if( $row['UNIX_TIMESTAMP(Time)'] >= $low_time && $row['UNIX_TIMESTAMP(Time)'] <=$high_time )
{
$timesum[$row['Talkgroup']] = $timesum[$row['Talkgroup']]+$row["Talktime"];
$timiesums[$timel] =$timiesums[$timel] +$row["Talktime"];
unset($row);
}
}
// echo $sql_active;
// echo "<br>";
// $sqlref = $link->query($sql_active);
/*
while($row = $sqlref->fetch_assoc())
{
$timesum[$row['Talkgroup']] =$timesum[$row['Talkgroup']] -$row["sum(UNIX_TIMESTAMP(`Time`))"];
// echo $row['Talkgroup'];
// echo "<pre>";
// var_dump($timesum[$row['Talkgroup']] );
if ($timesum[$row['Talkgroup']] > 3600)
{
$correction = strtotime($day);
$correction = $correction+ mktime(($timel),0,0,01,01,1970);
$timesum[$timel] = $timesum[$timel]- $correction;
}
if($timesum[$row['Talkgroup']] <0 )
{
$correction = strtotime($day);
$correction = $correction+ mktime(($timel),0,0,01,01,1970);
$timesum[$row['Talkgroup']] = $timesum[$row['Talkgroup']] + $correction;
// check if time is db erroer correct
}
if($timesum[$row['Talkgroup']] >= 0 && $timesum[$row['Talkgroup']] <= 3600)
{
$timiesums[$timel] =$timiesums[$timel] + $timesum[$row['Talkgroup']];
}
else
{
// clear incorect data disable if debuging
$timesum[$row['Talkgroup']]=0;
}
}
*/
$json_array[$timel] ["Secound"] = secondsToDHMS($timiesums[$timel]);
$json_array[$timel] ["unixtime"] = $timiesums[$timel];
$json_array[$timel] ["TG"]= $timesum;
}
echo json_encode ($json_array);
}
else
{
$json_array= array();
$day = $link->real_escape_string($day);
$tme_string ="`Time` BETWEEN '$day 00:00:00.000000' AND '$day 23:59:59.000000'";
//$sql_active ="SELECT sum(Talktime), `Talkgroup` FROM RefletorNodeLOG WHERE `Type` = '1' $station_qvery AND `Active` ='1' AND $tme_string group by `Talkgroup`";
$sql_nonactive ="SELECT sum(Talktime), `Talkgroup` FROM RefletorNodeLOG WHERE `Type` = '1'$station_qvery AND `Active` ='0' AND $tme_string group by `Talkgroup` ";
/*echo $sql_active;
echo "<br>";
*/
$sqla = $link->query($sql_nonactive);
$timesum =array();
while($row = $sqla->fetch_assoc()) {
$timesum[$row["Talkgroup"]] =$row["sum(Talktime)"];
}
$result = mysqli_query($link, "SELECT `Talkgroup` FROM `RefletorNodeLOG` GROUP BY `Talkgroup` ");
// Numeric array
//echo "<br />";
// Associative array
$json_array = array();
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC))
{
$json_array[$row["Talkgroup"]] ["Secound"] = secondsToDHMS($timesum[ $row["Talkgroup"]]);
$json_array[$row["Talkgroup"]] ["unixtime"] = $timesum[ $row["Talkgroup"]];
}
echo json_encode ($json_array);
}
?>