-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsvggraph.php
More file actions
133 lines (112 loc) · 4.72 KB
/
Copy pathsvggraph.php
File metadata and controls
133 lines (112 loc) · 4.72 KB
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
<?php
require 'SVGGraph/autoloader.php';
function geoRevLoc ($lat, $lon)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "TileProxy/1.0");
curl_setopt($ch, CURLOPT_URL, "https://nominatim.openstreetmap.org/reverse?lat=$lat&lon=$lon&format=json&accept-language=sk");
$place = curl_exec($ch);
curl_close($ch);
$place = "[" . $place . "]";
$place = json_decode($place, true);
// print_r($place);
$amenity = isset($place[0]['address']['amenity']) ? $place[0]['address']['amenity'] . ', ' : '';
$road = isset($place[0]['address']['road']) ? $place[0]['address']['road'] : '';
$house_number = isset($place[0]['address']['house_number']) ? ' ' . $place[0]['address']['house_number'] . ', ' : ', ';
$city = isset($place[0]['address']['city']) ? $place[0]['address']['city'] :
( isset($place[0]['address']['town']) ? $place[0]['address']['town'] :
( isset($place[0]['address']['village']) ? $place[0]['address']['village'] : '' ));
return ($amenity.$road.$house_number.$city);
}
$settings = [
'auto_fit' => true,
'thousands' => ' ',
'decimal' => ',',
// 'datetime_keys' => true,
// 'structured_data' => true,
'back_colour' => '#fff',
// 'back_stroke_width' => 0,
// 'back_stroke_colour' => '#eee',
// 'stroke_colour' => '#000',
// 'axis_colour' => '#333',
'axis_overlap' => 2,
'grid_colour' => '#666',
'label_colour' => '#000',
'axis_font' => 'Verdana',
'axis_font_size' => 10,
'label_v' => 'nabíjací výkon [kW]',
// 'label_colour_v' => 'blue',
// 'units_y' => 'kW',
'axis_min_h' => 0,
'axis_max_h' => 100,
'label_h' => '% SOC',
'minimum_grid_spacing' => 20,
'show_subdivisions' => true,
'show_grid_subdivisions' => true,
// 'grid_subdivision_colour' => '#ccc',
'line_stroke_width' => 1,
'marker_size' => 2,
'legend_entry_height' => 10,
'legend_position' => 'outer bottom 5 -5',
'legend_stroke_width' => 0,
'legend_shadow_opacity' => 0,
];
$markers = "circle square triangle cross x pentagon diamond hexagon octagon asterisk star threestar fourstar eightstar";
$settings['marker_type'] = explode(' ', $markers);
$mode = LiveData::MODE_IDLE;
$oldMode = LiveData::MODE_IDLE;
$oldSOC = -1;
foreach ($this->jsonData as $row) {
if ($row === false)
continue;
if ($row['odoKm'] <= 0 || $row['socPerc'] == -1)
continue;
if ($row['carType'] < 9 || $row['carType'] > 11) {
if (($row['motorRpm'] == -1 || $row['motorRpm'] == 0) && $row['batPowKw'] > 0.5) {
$mode = LiveData::MODE_CHARGING;
} else {
$mode = LiveData::MODE_IDLE;
}
if ($row['motorRpm'] > 0) {
$mode = LiveData::MODE_DRIVE;
}
} else {
// if (isset($row['speedKmhGPS']) && $row['speedKmhGPS'] != -1) {
// $row['speedKmh'] = $row['speedKmhGPS'];
// }
if ($row['speedKmh'] == 0 && $row['batPowKw'] > 0.5) {
$mode = LiveData::MODE_CHARGING;
} else {
$mode = LiveData::MODE_IDLE;
}
if ($row['speedKmh'] > 0) {
$mode = LiveData::MODE_DRIVE;
}
}
if ($mode == LiveData::MODE_CHARGING && $row['socPerc'] != $oldSOC)
{
if ($oldSOC == -1)
for ($i = 0; $i < $row['socPerc']; $i++)
$dat[$i] = null;
$oldSOC = $row['socPerc'];
$dat[$oldSOC] = $row['batPowKw'];
}
if ($oldMode == LiveData::MODE_CHARGING && $mode != LiveData::MODE_CHARGING)
{
$data [] = $dat;
$dat = [];
$oldSOC = -1;
$settings['legend_entries'][] = geoRevLoc($row['lat'], $row['lon']);
}
$oldMode = $mode;
}
$settings['pad_bottom']= 5 + 16 * count ($data);
$graph = new Goat1000\SVGGraph\SVGGraph(960, 520, $settings);
$graph->values($data);
//$graph->colours(array('blue','green'));
echo $graph->fetch('MultiLineGraph', false);
//print_r ($data);
//var_export ($data);
//var_export ($settings['legend_entries']);
?>