-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.php
71 lines (63 loc) · 2.52 KB
/
util.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
<?php
ini_set( 'serialize_precision', -1 );
function timeElapsedString($datetime, $full = false) {
$now = new DateTime;
$ago = new DateTime($datetime);
$diff = $now->diff($ago);
$diff->w = floor($diff->d / 7);
$diff->d -= $diff->w * 7;
$string = array(
'y' => 'year',
'm' => 'month',
'w' => 'week',
'd' => 'day',
'h' => 'hour',
'i' => 'minute',
's' => 'second',
);
foreach ($string as $k => &$v) {
if ($diff->$k) {
$v = $diff->$k . ' ' . $v . ($diff->$k > 1 ? 's' : '');
} else {
unset($string[$k]);
}
}
if (!$full) $string = array_slice($string, 0, 1);
return $string ? implode(', ', $string) . ' ago' : 'just now';
}
$sensorNames = array( "accelerometer"=>"Acceleration",
"accelerometer_x"=>"Acceleration X",
"accelerometer_y"=>"Acceleration Y",
"accelerometer_z"=>"Acceleration Z",
"luminosity"=>"Luminosity",
"temperature"=>"Temperature",
"soil_moisture"=>"Soil Moisture"
);
$sensorUnits = array( "accelerometer"=>"g",
"accelerometer_x"=>"g",
"accelerometer_y"=>"g",
"accelerometer_z"=>"g",
"luminosity"=>"%",
"temperature"=>"°C",
"soil_moisture"=>"%"
);
$keyNames = array( "acceleration"=>"accelerometer",
"acceleration_x"=>"accelerometer_x",
"accelerationx"=>"accelerometer_x",
"acceleration_y"=>"accelerometer_y",
"accelerationy"=>"accelerometer_y",
"acceleration_z"=>"accelerometer_z",
"accelerationz"=>"accelerometer_z",
"accelerometer" => "accelerometer",
"accelerometer_x"=>"accelerometer_x",
"accelerometerx"=>"accelerometer_x",
"accelerometer_y"=>"accelerometer_y",
"accelerometery"=>"accelerometer_y",
"accelerometer_z"=>"accelerometer_z",
"accelerometerz"=>"accelerometer_z",
"luminosity"=>"luminosity",
"temperature"=>"temperature",
"soil_moisture"=>"soil_moisture",
"soilmoisture"=>"soil_moisture"
);
?>