-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
json.php
executable file
·59 lines (50 loc) · 1.44 KB
/
json.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
<?php
require_once 'telemetry_db.php';
/**
* @param int|float $d
*
* @return string
*/
function format($d)
{
if ($d < 10) {
return number_format($d, 2, '.', '');
}
if ($d < 100) {
return number_format($d, 1, '.', '');
}
return number_format($d, 0, '.', '');
}
/**
* @param array $speedtest
*
* @return array
*/
function formatSpeedtestData($speedtest)
{
// format values for the image
$speedtest['dl'] = format($speedtest['dl']);
$speedtest['ul'] = format($speedtest['ul']);
$speedtest['ping'] = format($speedtest['ping']);
$speedtest['jitter'] = format($speedtest['jitter']);
$speedtest['timestamp'] = $speedtest['timestamp'];
$ispinfo = json_decode($speedtest['ispinfo'], true)['processedString'];
$dash = strpos($ispinfo, '-');
if ($dash !== false) {
$ispinfo = substr($ispinfo, $dash + 2);
$par = strrpos($ispinfo, '(');
if ($par !== false) {
$ispinfo = substr($ispinfo, 0, $par);
}
} else {
$ispinfo = '';
}
$speedtest['ispinfo'] = $ispinfo;
return $speedtest;
}
$speedtest = getSpeedtestUserById($_GET['id']);
if (!is_array($speedtest)) {
echo '{}';
}
$speedtest = formatSpeedtestData($speedtest);
echo json_encode(array('timestamp'=>$speedtest['timestamp'],'download'=>$speedtest['dl'],'upload'=>$speedtest['ul'],'ping'=>$speedtest['ping'],'jitter'=>$speedtest['jitter'],'ispinfo'=>$speedtest['ispinfo']));