1
|
|
|
<?php |
2
|
|
|
require_once(dirname(__FILE__).'/class.Connection.php'); |
3
|
|
|
require_once(dirname(__FILE__).'/class.AIS.php'); |
4
|
|
|
require_once(dirname(__FILE__).'/class.Marine.php'); |
5
|
|
|
require_once(dirname(__FILE__).'/class.MarineLive.php'); |
6
|
|
|
require_once(dirname(__FILE__).'/class.MarineArchive.php'); |
7
|
|
|
require_once(dirname(__FILE__).'/class.Scheduler.php'); |
8
|
|
|
require_once(dirname(__FILE__).'/class.Translation.php'); |
9
|
|
|
require_once(dirname(__FILE__).'/class.Stats.php'); |
10
|
|
|
require_once(dirname(__FILE__).'/class.Source.php'); |
11
|
|
|
if (isset($globalServerAPRS) && $globalServerAPRS) { |
12
|
|
|
require_once(dirname(__FILE__).'/class.APRS.php'); |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
class MarineImport { |
16
|
|
|
private $all_tracked = array(); |
17
|
|
|
private $last_delete_hourly = 0; |
18
|
|
|
private $last_delete = 0; |
19
|
|
|
private $stats = array(); |
20
|
|
|
private $tmd = 0; |
21
|
|
|
private $source_location = array(); |
22
|
|
|
public $db = null; |
23
|
|
|
public $nb = 0; |
24
|
|
|
|
25
|
|
|
public function __construct($dbc = null) { |
26
|
|
|
global $globalBeta, $globalServerAPRS, $APRSMarine, $globalNoDB; |
27
|
|
|
if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
28
|
|
|
$Connection = new Connection($dbc); |
29
|
|
|
$this->db = $Connection->db(); |
30
|
|
|
date_default_timezone_set('UTC'); |
31
|
|
|
} |
32
|
|
|
// Get previous source stats |
33
|
|
|
/* |
34
|
|
|
$Stats = new Stats($dbc); |
35
|
|
|
$currentdate = date('Y-m-d'); |
36
|
|
|
$sourcestat = $Stats->getStatsSource($currentdate); |
37
|
|
|
if (!empty($sourcestat)) { |
38
|
|
|
foreach($sourcestat as $srcst) { |
39
|
|
|
$type = $srcst['stats_type']; |
40
|
|
|
if ($type == 'polar' || $type == 'hist') { |
41
|
|
|
$source = $srcst['source_name']; |
42
|
|
|
$data = $srcst['source_data']; |
43
|
|
|
$this->stats[$currentdate][$source][$type] = json_decode($data,true); |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
*/ |
48
|
|
|
if (isset($globalServerAPRS) && $globalServerAPRS) { |
49
|
|
|
$APRSMarine = new APRSMarine(); |
50
|
|
|
//$APRSSpotter->connect(); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function checkAll() { |
55
|
|
|
global $globalDebug, $globalNoDB; |
56
|
|
|
if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
57
|
|
|
if ($globalDebug) echo "Update last seen tracked data...\n"; |
58
|
|
|
foreach ($this->all_tracked as $key => $flight) { |
59
|
|
|
if (isset($this->all_tracked[$key]['id'])) { |
60
|
|
|
//echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].' '.$this->all_tracked[$key]['longitude']."\n"; |
61
|
|
|
$Marine = new Marine($this->db); |
62
|
|
|
if (isset($globalVM) && $globalVM) { |
63
|
|
|
if ($this->all_tracked[$key]['status'] == 'Racing') { |
64
|
|
|
$Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime'],$this->all_tracked[$id]['distance'],$this->all_tracked[$key]['race_rank'],$this->all_tracked[$key]['race_time'],$this->all_tracked[$key]['status']); |
|
|
|
|
65
|
|
|
} else { |
66
|
|
|
$finaldatetime = date('Y-m-d H:i:s',strtotime($this->all_tracked[$key]['race_begin'])+$this->all_tracked[$key]['race_time']); |
67
|
|
|
$Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$finaldatetime,$this->all_tracked[$id]['distance'],$this->all_tracked[$key]['race_rank'],$this->all_tracked[$key]['race_time'],$this->all_tracked[$key]['status']); |
68
|
|
|
} |
69
|
|
|
} else { |
70
|
|
|
$Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime'],$this->all_tracked[$id]['distance'],$this->all_tracked[$key]['race_rank'],$this->all_tracked[$key]['race_time'],$this->all_tracked[$key]['status']); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function del() { |
78
|
|
|
global $globalDebug, $globalNoDB, $globalNoImport; |
79
|
|
|
// Delete old infos |
80
|
|
|
if ($globalDebug) echo 'Delete old values and update latest data...'."\n"; |
81
|
|
|
foreach ($this->all_tracked as $key => $flight) { |
82
|
|
|
if (isset($flight['lastupdate'])) { |
83
|
|
|
if ($flight['lastupdate'] < (time()-3000)) { |
84
|
|
|
if ((!isset($globalNoImport) || $globalNoImport !== TRUE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) { |
85
|
|
|
if (isset($this->all_tracked[$key]['id'])) { |
86
|
|
|
if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n"; |
87
|
|
|
/* |
88
|
|
|
$MarineLive = new MarineLive(); |
89
|
|
|
$MarineLive->deleteLiveMarineDataById($this->all_tracked[$key]['id']); |
90
|
|
|
$MarineLive->db = null; |
91
|
|
|
*/ |
92
|
|
|
//$real_arrival = $this->arrival($key); |
93
|
|
|
$Marine = new Marine($this->db); |
94
|
|
|
if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') { |
95
|
|
|
if (isset($globalVM) && $globalVM) { |
96
|
|
|
if ($this->all_tracked[$key]['status'] == 'Racing') { |
97
|
|
|
$result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime'],$this->all_tracked[$id]['distance'],$this->all_tracked[$key]['race_rank'],$this->all_tracked[$key]['race_time'],$this->all_tracked[$key]['status']); |
|
|
|
|
98
|
|
|
} else { |
99
|
|
|
$finaldatetime = date('Y-m-d H:i:s',strtotime($this->all_tracked[$key]['race_begin'])+$this->all_tracked[$key]['race_time']); |
100
|
|
|
$result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$finaldatetime,$this->all_tracked[$id]['distance'],$this->all_tracked[$key]['race_rank'],$this->all_tracked[$key]['race_time'],$this->all_tracked[$key]['status']); |
101
|
|
|
} |
102
|
|
|
} else { |
103
|
|
|
$result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime'],$this->all_tracked[$key]['distance'],$this->all_tracked[$key]['race_rank'],$this->all_tracked[$key]['race_time'],$this->all_tracked[$key]['status']); |
104
|
|
|
} |
105
|
|
|
if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
106
|
|
|
} |
107
|
|
|
// Put in archive |
108
|
|
|
// $Marine->db = null; |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
unset($this->all_tracked[$key]); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public function add($line) { |
118
|
|
|
global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked, $globalNoImport, $globalNoDB, $globalServerAPRS,$APRSMarine, $globalLiveInterval, $globalVM; |
119
|
|
|
if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02'; |
120
|
|
|
date_default_timezone_set('UTC'); |
121
|
|
|
$dataFound = false; |
122
|
|
|
$send = false; |
123
|
|
|
|
124
|
|
|
// SBS format is CSV format |
125
|
|
|
if(is_array($line) && (isset($line['mmsi']) || isset($line['id']))) { |
126
|
|
|
//print_r($line); |
127
|
|
|
if (isset($line['mmsi']) || isset($line['id'])) { |
128
|
|
|
|
129
|
|
|
|
130
|
|
|
// Increment message number |
131
|
|
|
if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE) { |
132
|
|
|
$current_date = date('Y-m-d'); |
133
|
|
|
if (isset($line['source_name'])) $source = $line['source_name']; |
134
|
|
|
else $source = ''; |
135
|
|
|
if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source']; |
136
|
|
|
if (!isset($this->stats[$current_date][$source]['msg'])) { |
137
|
|
|
$this->stats[$current_date][$source]['msg']['date'] = time(); |
138
|
|
|
$this->stats[$current_date][$source]['msg']['nb'] = 1; |
139
|
|
|
} else $this->stats[$current_date][$source]['msg']['nb'] += 1; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
|
143
|
|
|
$Common = new Common(); |
144
|
|
|
$AIS = new AIS(); |
145
|
|
|
if (!isset($line['id'])) $id = trim($line['mmsi']); |
146
|
|
|
else $id = trim($line['id']); |
147
|
|
|
|
148
|
|
|
if (!isset($this->all_tracked[$id])) { |
149
|
|
|
$this->all_tracked[$id] = array(); |
150
|
|
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('addedMarine' => 0)); |
151
|
|
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '0', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','typeid' => '','noarchive' => false,'putinarchive' => true,'over_country' => '','mmsi' => '','status' => '','status_id' => '','imo' => '','callsign' => '','arrival_code' => '','arrival_date' => '','mmsi_type' => '','captain_id' => '','captain_name' => '','race_id' => '','race_name' => '','distance' => NULL,'race_rank' => NULL,'race_time' => NULL,'race_begin' => date('Y-m-d H:i:s'))); |
152
|
|
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time())); |
153
|
|
|
if (!isset($line['id'])) { |
154
|
|
|
if (!isset($globalDaemon)) $globalDaemon = TRUE; |
155
|
|
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $id.'-'.date('YmdHi'))); |
156
|
|
|
} else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id'])); |
157
|
|
|
if ($globalAllTracked !== FALSE) $dataFound = true; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
if (isset($line['mmsi']) && $line['mmsi'] != '' && $line['mmsi'] != $this->all_tracked[$id]['mmsi']) { |
161
|
|
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi' => $line['mmsi'])); |
162
|
|
|
if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
163
|
|
|
$Marine = new Marine($this->db); |
164
|
|
|
$identity = $Marine->getIdentity($line['mmsi']); |
165
|
|
|
if (!empty($identity)) { |
166
|
|
|
$this->all_tracked[$id]['ident'] = $identity['ship_name']; |
167
|
|
|
$this->all_tracked[$id]['type'] = $identity['type']; |
168
|
|
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('typeid' => $AIS->getShipTypeID($identity['type']))); |
169
|
|
|
} |
170
|
|
|
//print_r($identity); |
171
|
|
|
unset($Marine); |
172
|
|
|
//$dataFound = true; |
173
|
|
|
} |
174
|
|
|
} |
175
|
|
|
if (isset($line['type_id'])) { |
176
|
|
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $AIS->getShipType($line['type_id']))); |
177
|
|
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('typeid' => $line['type_id'])); |
178
|
|
|
} |
179
|
|
|
if (isset($line['type']) && $line['type'] != '' && $this->all_tracked[$id]['type'] == '') { |
180
|
|
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type'])); |
181
|
|
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('typeid' => $AIS->getShipTypeID($line['type']))); |
182
|
|
|
} elseif (isset($line['type']) && $line['type'] != '' && $this->all_tracked[$id]['type'] != '') { |
183
|
|
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type'])); |
184
|
|
|
} |
185
|
|
|
if (isset($line['status']) && $line['status'] != '') { |
186
|
|
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status' => $line['status'])); |
187
|
|
|
} |
188
|
|
|
if (isset($line['status_id']) && (!isset($this->all_tracked[$id]['status_id']) || $this->all_tracked[$id]['status_id'] != $line['status_id'])) { |
189
|
|
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status_id' => $line['status_id'])); |
190
|
|
|
if ($this->all_tracked[$id]['addedMarine'] == 1) { |
191
|
|
|
if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
192
|
|
|
if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
193
|
|
|
$Marine = new Marine($this->db); |
194
|
|
|
$Marine->updateStatusMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['status']); |
195
|
|
|
unset($Marine); |
196
|
|
|
} |
197
|
|
|
} |
198
|
|
|
} |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
|
202
|
|
|
if (isset($line['mmsi_type']) && $line['mmsi_type'] != '') { |
203
|
|
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi_type' => $line['mmsi_type'])); |
204
|
|
|
} |
205
|
|
|
if (isset($line['imo']) && $line['imo'] != '') { |
206
|
|
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('imo' => $line['imo'])); |
207
|
|
|
} |
208
|
|
|
if (isset($line['callsign']) && $line['callsign'] != '') { |
209
|
|
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('callsign' => $line['callsign'])); |
210
|
|
|
} |
211
|
|
|
if (isset($line['arrival_code']) && $line['arrival_code'] != '') { |
212
|
|
|
if (!isset($this->all_tracked[$id]['arrival_code'])) { |
213
|
|
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_code' => $line['arrival_code'])); |
214
|
|
|
if ($globalDebug) echo $this->all_tracked[$id]['id'].' => New arrival: '.$line['arrival_code']."\n"; |
215
|
|
|
if ($this->all_tracked[$id]['addedMarine'] != 0) { |
216
|
|
|
if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
217
|
|
|
if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
218
|
|
|
$Marine = new Marine($this->db); |
219
|
|
|
$fromsource = NULL; |
220
|
|
|
$Marine->updateArrivalPortNameMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['arrival_code'],$fromsource); |
221
|
|
|
$Marine->db = null; |
222
|
|
|
} |
223
|
|
|
} |
224
|
|
|
} |
225
|
|
|
} elseif ($this->all_tracked[$id]['arrival_code'] != $line['arrival_code']) { |
226
|
|
|
$this->all_tracked[$id]['arrival_code'] = $line['arrival_code']; |
227
|
|
|
if ($globalDebug) echo $this->all_tracked[$id]['id'].' => New arrival: '.$line['arrival_code']."\n"; |
228
|
|
|
if (!isset($line['id'])) { |
229
|
|
|
$this->all_tracked[$id]['id'] = $id.'-'.date('YmdHi'); |
230
|
|
|
$this->all_tracked[$id]['forcenew'] = 1; |
231
|
|
|
$this->all_tracked[$id]['addedMarine'] = 0; |
232
|
|
|
} |
233
|
|
|
} |
234
|
|
|
} |
235
|
|
|
if (isset($line['arrival_date']) && $line['arrival_date'] != '') { |
236
|
|
|
if (strtotime($line['arrival_date']) > time()) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date'])); |
237
|
|
|
} |
238
|
|
|
if (isset($line['captain_id']) && $line['captain_id'] != '') { |
239
|
|
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('captain_id' => $line['captain_id'])); |
240
|
|
|
} |
241
|
|
|
if (isset($line['captain_name']) && $line['captain_name'] != '') { |
242
|
|
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('captain_name' => $line['captain_name'])); |
243
|
|
|
} |
244
|
|
|
if (isset($line['race_id']) && $line['race_id'] != '') { |
245
|
|
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('race_id' => $line['race_id'])); |
246
|
|
|
} |
247
|
|
|
if (isset($line['race_name']) && $line['race_name'] != '') { |
248
|
|
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('race_name' => $line['race_name'])); |
249
|
|
|
} |
250
|
|
|
if (isset($line['race_rank']) && $line['race_rank'] != '') { |
251
|
|
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('race_rank' => $line['race_rank'])); |
252
|
|
|
} |
253
|
|
|
if (isset($line['race_time']) && $line['race_time'] != '') { |
254
|
|
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('race_time' => $line['race_time'])); |
255
|
|
|
} |
256
|
|
|
if (isset($line['race_begin']) && $line['race_begin'] != '') { |
257
|
|
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('race_begin' => $line['race_begin'])); |
258
|
|
|
} |
259
|
|
|
if (isset($line['distance']) && $line['distance'] != '') { |
260
|
|
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('distance' => $line['distance'])); |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
//if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_tracked[$id]['ident'] != trim($line['ident'])) && preg_match('/^[a-zA-Z0-9-]+$/', $line['ident'])) { |
264
|
|
|
if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_tracked[$id]['ident'] != trim($line['ident']))) { |
265
|
|
|
if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
266
|
|
|
if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
267
|
|
|
$timeelapsed = microtime(true); |
|
|
|
|
268
|
|
|
$Marine = new Marine($this->db); |
269
|
|
|
$Marine->addIdentity($this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['ident'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['type']); |
270
|
|
|
$Marine->db = null; |
271
|
|
|
} |
272
|
|
|
} |
273
|
|
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident']))); |
274
|
|
|
if ($this->all_tracked[$id]['addedMarine'] == 1) { |
275
|
|
|
if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
276
|
|
|
if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
277
|
|
|
$timeelapsed = microtime(true); |
278
|
|
|
$Marine = new Marine($this->db); |
279
|
|
|
$fromsource = NULL; |
280
|
|
|
$result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource); |
281
|
|
|
if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
282
|
|
|
$Marine->db = null; |
283
|
|
|
if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
284
|
|
|
} |
285
|
|
|
} |
286
|
|
|
} |
287
|
|
|
if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident'])); |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
if (isset($line['datetime']) && strtotime($line['datetime']) > time()-30*60 && strtotime($line['datetime']) < time()+20*60) { |
291
|
|
|
if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) { |
292
|
|
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime'])); |
293
|
|
|
} else { |
294
|
|
|
if (strtotime($line['datetime']) == strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_tracked[$id]['mmsi']."\n"; |
295
|
|
|
elseif (strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_tracked[$id]['datetime'].") !!! for ".$this->all_tracked[$id]['hex']." - format : ".$line['format_source']."\n"; |
296
|
|
|
return ''; |
297
|
|
|
} |
298
|
|
|
} elseif (isset($line['datetime']) && strtotime($line['datetime']) <= time()-30*60) { |
299
|
|
|
if ($globalDebug) echo "!!! Date is too old ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!\n"; |
300
|
|
|
return ''; |
301
|
|
|
} elseif (isset($line['datetime']) && strtotime($line['datetime']) >= time()+20*60) { |
302
|
|
|
if ($globalDebug) echo "!!! Date is in the future ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!\n"; |
303
|
|
|
return ''; |
304
|
|
|
} elseif (!isset($line['datetime'])) { |
305
|
|
|
date_default_timezone_set('UTC'); |
306
|
|
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => date('Y-m-d H:i:s'))); |
307
|
|
|
} else { |
308
|
|
|
if ($globalDebug) echo "!!! Unknow date error ".$this->all_tracked[$id]['mmsi']." date: ".$line['datetime']." - format : ".$line['format_source']."!!!\n"; |
309
|
|
|
return ''; |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
|
313
|
|
|
if (isset($line['speed'])) { |
314
|
|
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed'],2))); |
315
|
|
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true)); |
316
|
|
|
} else if (!isset($this->all_tracked[$id]['speed_fromsrc']) && isset($this->all_tracked[$id]['time_last_coord']) && $this->all_tracked[$id]['time_last_coord'] != time() && isset($line['latitude']) && isset($line['longitude'])) { |
317
|
|
|
$distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m'); |
318
|
|
|
if ($distance > 1000 && $distance < 10000) { |
319
|
|
|
$speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']); |
320
|
|
|
$speed = $speed*3.6; |
321
|
|
|
if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed,2))); |
322
|
|
|
if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n"; |
323
|
|
|
} |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) { |
327
|
|
|
if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']); |
328
|
|
|
else unset($timediff); |
329
|
|
|
if ($this->tmd > 5 || |
330
|
|
|
!isset($timediff) || |
331
|
|
|
$timediff > $globalLiveInterval || |
332
|
|
|
( |
333
|
|
|
$timediff > 30 && |
334
|
|
|
isset($this->all_tracked[$id]['latitude']) && |
335
|
|
|
isset($this->all_tracked[$id]['longitude']) && |
336
|
|
|
$Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')) |
337
|
|
|
) |
338
|
|
|
) { |
339
|
|
|
if (isset($this->all_tracked[$id]['archive_latitude']) && isset($this->all_tracked[$id]['archive_longitude']) && isset($this->all_tracked[$id]['livedb_latitude']) && isset($this->all_tracked[$id]['livedb_longitude'])) { |
340
|
|
|
if (!$Common->checkLine($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['livedb_latitude'],$this->all_tracked[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) { |
341
|
|
|
$this->all_tracked[$id]['archive_latitude'] = $line['latitude']; |
342
|
|
|
$this->all_tracked[$id]['archive_longitude'] = $line['longitude']; |
343
|
|
|
$this->all_tracked[$id]['putinarchive'] = true; |
344
|
|
|
|
345
|
|
|
if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... '; |
346
|
|
|
$timeelapsed = microtime(true); |
347
|
|
|
if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
348
|
|
|
$Marine = new Marine($this->db); |
349
|
|
|
$all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']); |
350
|
|
|
if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2']; |
351
|
|
|
$Marine->db = null; |
352
|
|
|
if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
353
|
|
|
} |
354
|
|
|
$this->tmd = 0; |
355
|
|
|
if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n"; |
356
|
|
|
} |
357
|
|
|
} |
358
|
|
|
|
359
|
|
|
if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) { |
360
|
|
|
if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude']; |
361
|
|
|
if (!isset($this->all_tracked[$id]['livedb_latitude']) || abs($this->all_tracked[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || $this->all_tracked[$id]['format_source'] == 'aprs') { |
362
|
|
|
$this->all_tracked[$id]['livedb_latitude'] = $line['latitude']; |
363
|
|
|
$dataFound = true; |
364
|
|
|
$this->all_tracked[$id]['time_last_coord'] = time(); |
365
|
|
|
} |
366
|
|
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude'])); |
367
|
|
|
} |
368
|
|
|
if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) { |
369
|
|
|
if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360; |
370
|
|
|
if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude']; |
371
|
|
|
if (!isset($this->all_tracked[$id]['livedb_longitude']) || abs($this->all_tracked[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || $this->all_tracked[$id]['format_source'] == 'aprs') { |
372
|
|
|
$this->all_tracked[$id]['livedb_longitude'] = $line['longitude']; |
373
|
|
|
$dataFound = true; |
374
|
|
|
$this->all_tracked[$id]['time_last_coord'] = time(); |
375
|
|
|
} |
376
|
|
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('longitude' => $line['longitude'])); |
377
|
|
|
} |
378
|
|
|
|
379
|
|
|
} else if ($globalDebug && $timediff > 20) { |
380
|
|
|
$this->tmd = $this->tmd + 1; |
381
|
|
|
echo '!!! Too much distance in short time... for '.$this->all_tracked[$id]['ident']."\n"; |
382
|
|
|
echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')."m -"; |
383
|
|
|
echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')/$timediff)*3.6)." km/h - "; |
384
|
|
|
echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_tracked[$id]['latitude'].' - prev long : '.$this->all_tracked[$id]['longitude']." \n"; |
385
|
|
|
} |
386
|
|
|
} |
387
|
|
|
if (isset($line['last_update']) && $line['last_update'] != '') { |
388
|
|
|
if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true; |
389
|
|
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update'])); |
390
|
|
|
} |
391
|
|
|
if (isset($line['format_source']) && $line['format_source'] != '') { |
392
|
|
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source'])); |
393
|
|
|
} |
394
|
|
|
if (isset($line['source_name']) && $line['source_name'] != '') { |
395
|
|
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name'])); |
396
|
|
|
} |
397
|
|
|
if (isset($line['noarchive']) && $line['noarchive'] === true) { |
398
|
|
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true)); |
399
|
|
|
} |
400
|
|
|
|
401
|
|
|
if (isset($line['heading']) && $line['heading'] != '') { |
402
|
|
|
if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true; |
403
|
|
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading']))); |
404
|
|
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true)); |
405
|
|
|
//$dataFound = true; |
406
|
|
|
} elseif (!isset($this->all_tracked[$id]['heading_fromsrc']) && isset($this->all_tracked[$id]['archive_latitude']) && $this->all_tracked[$id]['archive_latitude'] != $this->all_tracked[$id]['latitude'] && isset($this->all_tracked[$id]['archive_longitude']) && $this->all_tracked[$id]['archive_longitude'] != $this->all_tracked[$id]['longitude']) { |
407
|
|
|
$heading = $Common->getHeading($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']); |
408
|
|
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading))); |
409
|
|
|
if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true; |
410
|
|
|
if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n"; |
411
|
|
|
} |
412
|
|
|
//if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false; |
413
|
|
|
|
414
|
|
|
|
415
|
|
|
|
416
|
|
|
if ($dataFound === true && (isset($this->all_tracked[$id]['mmsi']) || isset($this->all_tracked[$id]['id']))) { |
417
|
|
|
$this->all_tracked[$id]['lastupdate'] = time(); |
418
|
|
|
if ($this->all_tracked[$id]['addedMarine'] == 0 || (isset($globalVM) && $globalVM)) { |
419
|
|
|
if (!isset($globalDistanceIgnore['latitude']) || $this->all_tracked[$id]['longitude'] == '' || $this->all_tracked[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) { |
420
|
|
|
if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) { |
421
|
|
|
if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
422
|
|
|
if ($globalDebug) echo "Check if vessel is already in DB..."; |
423
|
|
|
$timeelapsed = microtime(true); |
424
|
|
|
$MarineLive = new MarineLive($this->db); |
425
|
|
|
if (isset($line['id']) && isset($globalVM) && $globalVM) { |
426
|
|
|
$Marine = new Marine($this->db); |
427
|
|
|
$recent_ident = $Marine->checkId($line['id']); |
428
|
|
|
if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkId : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
429
|
|
|
$Marine->db=null; |
430
|
|
|
} elseif (isset($line['id'])) { |
431
|
|
|
$recent_ident = $MarineLive->checkIdRecent($line['id']); |
432
|
|
|
if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
433
|
|
|
} elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') { |
434
|
|
|
$recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']); |
435
|
|
|
if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
436
|
|
|
} elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') { |
437
|
|
|
$recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']); |
438
|
|
|
if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
439
|
|
|
} else $recent_ident = ''; |
440
|
|
|
$MarineLive->db=null; |
441
|
|
|
if ($globalDebug && $recent_ident == '') echo " Not in DB.\n"; |
442
|
|
|
elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n"; |
443
|
|
|
} else $recent_ident = ''; |
444
|
|
|
} else { |
445
|
|
|
$recent_ident = ''; |
446
|
|
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0)); |
447
|
|
|
} |
448
|
|
|
//if there was no vessel with the same callsign within the last hour and go post it into the archive |
449
|
|
|
if($recent_ident == "" && (($this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') || (isset($globalVM) && $globalVM))) |
450
|
|
|
{ |
451
|
|
|
if ($globalDebug) { |
452
|
|
|
if ($this->all_tracked[$id]['mmsi'] == '') echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : "; |
453
|
|
|
else echo "\o/ Add ".$this->all_tracked[$id]['ident']." in archive DB : "; |
454
|
|
|
} |
455
|
|
|
//adds the spotter data for the archive |
456
|
|
|
$highlight = ''; |
|
|
|
|
457
|
|
|
if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi'))); |
458
|
|
|
if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
459
|
|
|
if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
460
|
|
|
$timeelapsed = microtime(true); |
461
|
|
|
$Marine = new Marine($this->db); |
462
|
|
|
if (isset($globalVM) && $globalVM) { |
463
|
|
|
$result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['race_begin'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['captain_id'],$this->all_tracked[$id]['captain_name'],$this->all_tracked[$id]['race_id'],$this->all_tracked[$id]['race_name'],$this->all_tracked[$id]['distance'],$this->all_tracked[$id]['race_rank'],$this->all_tracked[$id]['race_time']); |
464
|
|
|
} else { |
465
|
|
|
$result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['captain_id'],$this->all_tracked[$id]['captain_name'],$this->all_tracked[$id]['race_id'],$this->all_tracked[$id]['race_name'],$this->all_tracked[$id]['distance'],$this->all_tracked[$id]['race_rank'],$this->all_tracked[$id]['race_time']); |
466
|
|
|
} |
467
|
|
|
$Marine->db = null; |
468
|
|
|
if ($globalDebug && isset($result)) echo $result."\n"; |
469
|
|
|
if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
470
|
|
|
} |
471
|
|
|
} |
472
|
|
|
if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') { |
473
|
|
|
// Add source stat in DB |
474
|
|
|
$Stats = new Stats($this->db); |
475
|
|
|
if (!empty($this->stats)) { |
476
|
|
|
if ($globalDebug) echo 'Add source stats : '; |
477
|
|
|
foreach($this->stats as $date => $data) { |
478
|
|
|
foreach($data as $source => $sourced) { |
479
|
|
|
//print_r($sourced); |
480
|
|
|
if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar_marine',$date); |
481
|
|
|
if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist_marine',$date); |
482
|
|
|
if (isset($sourced['msg'])) { |
483
|
|
|
if (time() - $sourced['msg']['date'] > 10) { |
484
|
|
|
$nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date'])); |
485
|
|
|
echo $Stats->addStatSource($nbmsg,$source,'msg_marine',$date); |
486
|
|
|
unset($this->stats[$date][$source]['msg']); |
487
|
|
|
} |
488
|
|
|
} |
489
|
|
|
} |
490
|
|
|
if ($date != date('Y-m-d')) { |
491
|
|
|
unset($this->stats[$date]); |
492
|
|
|
} |
493
|
|
|
} |
494
|
|
|
if ($globalDebug) echo 'Done'."\n"; |
495
|
|
|
} |
496
|
|
|
$Stats->db = null; |
497
|
|
|
} |
498
|
|
|
|
499
|
|
|
$this->del(); |
500
|
|
|
//$ignoreImport = false; |
501
|
|
|
$this->all_tracked[$id]['addedMarine'] = 1; |
502
|
|
|
//print_r($this->all_tracked[$id]); |
503
|
|
|
if ($this->last_delete == 0 || time() - $this->last_delete > 1800) { |
504
|
|
|
if ($globalDebug) echo "---- Deleting Live Marine data older than 9 hours..."; |
505
|
|
|
//MarineLive->deleteLiveMarineDataNotUpdated(); |
506
|
|
|
if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
507
|
|
|
$MarineLive = new MarineLive($this->db); |
508
|
|
|
$MarineLive->deleteLiveMarineData(); |
509
|
|
|
$MarineLive->db=null; |
510
|
|
|
if ($globalDebug) echo " Done\n"; |
511
|
|
|
} |
512
|
|
|
$this->last_delete = time(); |
513
|
|
|
} |
514
|
|
|
} elseif ($recent_ident != '') { |
515
|
|
|
$this->all_tracked[$id]['id'] = $recent_ident; |
516
|
|
|
$this->all_tracked[$id]['addedMarine'] = 1; |
517
|
|
|
if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
518
|
|
|
if ((isset($globalDaemon) && !$globalDaemon) || (isset($globalVM) && $globalVM)) { |
519
|
|
|
$Marine = new Marine($this->db); |
520
|
|
|
if (isset($globalVM) && $globalVM) { |
521
|
|
|
if ($this->all_tracked[$id]['status'] == 'Racing') { |
522
|
|
|
$Marine->updateLatestMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'],$this->all_tracked[$id]['distance'],$this->all_tracked[$id]['race_rank'],$this->all_tracked[$id]['race_time'],$this->all_tracked[$id]['status']); |
523
|
|
|
} else { |
524
|
|
|
$finaldatetime = date('Y-m-d H:i:s',strtotime($this->all_tracked[$id]['race_begin'])+$this->all_tracked[$id]['race_time']); |
525
|
|
|
$Marine->updateLatestMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$this->all_tracked[$id]['speed'],$finaldatetime,$this->all_tracked[$id]['distance'],$this->all_tracked[$id]['race_rank'],$this->all_tracked[$id]['race_time'],$this->all_tracked[$id]['status']); |
526
|
|
|
} |
527
|
|
|
} else { |
528
|
|
|
$Marine->updateLatestMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'],$this->all_tracked[$id]['distance'],$this->all_tracked[$id]['race_rank'],$this->all_tracked[$id]['race_time'],$this->all_tracked[$id]['status']); |
529
|
|
|
} |
530
|
|
|
$Marine->db = null; |
531
|
|
|
} |
532
|
|
|
} |
533
|
|
|
|
534
|
|
|
} |
535
|
|
|
} |
536
|
|
|
} |
537
|
|
|
//adds the spotter LIVE data |
538
|
|
|
if ($globalDebug) { |
539
|
|
|
echo 'DATA : ident : '.$this->all_tracked[$id]['ident'].' - type : '.$this->all_tracked[$id]['type'].' - Latitude : '.$this->all_tracked[$id]['latitude'].' - Longitude : '.$this->all_tracked[$id]['longitude'].' - Heading : '.$this->all_tracked[$id]['heading'].' - Speed : '.$this->all_tracked[$id]['speed']."\n"; |
540
|
|
|
} |
541
|
|
|
$ignoreImport = false; |
542
|
|
|
if ((isset($globalVM) && $globalVM) && $this->all_tracked[$id]['status'] != 'Racing') $ignoreImport = true; |
543
|
|
|
if (!$ignoreImport) { |
544
|
|
|
if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) { |
545
|
|
|
if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : "; |
546
|
|
|
if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
547
|
|
|
if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
548
|
|
|
$timeelapsed = microtime(true); |
549
|
|
|
$MarineLive = new MarineLive($this->db); |
550
|
|
|
$result = $MarineLive->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'],$this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country'],$this->all_tracked[$id]['captain_id'],$this->all_tracked[$id]['captain_name'],$this->all_tracked[$id]['race_id'],$this->all_tracked[$id]['race_name'],$this->all_tracked[$id]['distance'],$this->all_tracked[$id]['race_rank'],$this->all_tracked[$id]['race_time']); |
551
|
|
|
$MarineLive->db = null; |
552
|
|
|
if ($globalDebug) echo $result."\n"; |
553
|
|
|
if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
554
|
|
|
} |
555
|
|
|
} |
556
|
|
|
if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_tracked[$id]['putinarchive']) { |
557
|
|
|
$APRSMarine->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'],$this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country']); |
558
|
|
|
} |
559
|
|
|
$this->all_tracked[$id]['putinarchive'] = false; |
560
|
|
|
|
561
|
|
|
// Put statistics in $this->stats variable |
562
|
|
|
|
563
|
|
|
if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $line['format_source'] != 'aprs' && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') { |
564
|
|
|
$source = $this->all_tracked[$id]['source_name']; |
565
|
|
|
if ($source == '') $source = $this->all_tracked[$id]['format_source']; |
566
|
|
|
if (!isset($this->source_location[$source])) { |
567
|
|
|
$Location = new Source($this->db); |
568
|
|
|
$coord = $Location->getLocationInfobySourceName($source); |
569
|
|
|
if (count($coord) > 0) { |
570
|
|
|
$latitude = $coord[0]['latitude']; |
571
|
|
|
$longitude = $coord[0]['longitude']; |
572
|
|
|
} else { |
573
|
|
|
$latitude = $globalCenterLatitude; |
574
|
|
|
$longitude = $globalCenterLongitude; |
575
|
|
|
} |
576
|
|
|
$this->source_location[$source] = array('latitude' => $latitude,'longitude' => $longitude); |
577
|
|
|
} else { |
578
|
|
|
$latitude = $this->source_location[$source]['latitude']; |
579
|
|
|
$longitude = $this->source_location[$source]['longitude']; |
580
|
|
|
} |
581
|
|
|
$stats_heading = $Common->getHeading($latitude,$longitude,$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']); |
582
|
|
|
//$stats_heading = $stats_heading%22.5; |
583
|
|
|
$stats_heading = round($stats_heading/22.5); |
584
|
|
|
$stats_distance = $Common->distance($latitude,$longitude,$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']); |
585
|
|
|
$current_date = date('Y-m-d'); |
586
|
|
|
if ($stats_heading == 16) $stats_heading = 0; |
587
|
|
|
if (!isset($this->stats[$current_date][$source]['polar'][1])) { |
588
|
|
|
for ($i=0;$i<=15;$i++) { |
589
|
|
|
$this->stats[$current_date][$source]['polar'][$i] = 0; |
590
|
|
|
} |
591
|
|
|
$this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance; |
592
|
|
|
} else { |
593
|
|
|
if ($this->stats[$current_date][$source]['polar'][$stats_heading] < $stats_distance) { |
594
|
|
|
$this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance; |
595
|
|
|
} |
596
|
|
|
} |
597
|
|
|
$distance = (round($stats_distance/10)*10); |
598
|
|
|
//echo '$$$$$$$$$$ DISTANCE : '.$distance.' - '.$source."\n"; |
599
|
|
|
//var_dump($this->stats); |
600
|
|
|
if (!isset($this->stats[$current_date][$source]['hist'][$distance])) { |
601
|
|
|
if (isset($this->stats[$current_date][$source]['hist'][0])) { |
602
|
|
|
end($this->stats[$current_date][$source]['hist']); |
603
|
|
|
$mini = key($this->stats[$current_date][$source]['hist'])+10; |
604
|
|
|
} else $mini = 0; |
605
|
|
|
for ($i=$mini;$i<=$distance;$i+=10) { |
606
|
|
|
$this->stats[$current_date][$source]['hist'][$i] = 0; |
607
|
|
|
} |
608
|
|
|
$this->stats[$current_date][$source]['hist'][$distance] = 1; |
609
|
|
|
} else { |
610
|
|
|
$this->stats[$current_date][$source]['hist'][$distance] += 1; |
611
|
|
|
} |
612
|
|
|
} |
613
|
|
|
|
614
|
|
|
|
615
|
|
|
$this->all_tracked[$id]['lastupdate'] = time(); |
616
|
|
|
if ($this->all_tracked[$id]['putinarchive']) $send = true; |
617
|
|
|
} elseif (isset($this->all_tracked[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n"; |
618
|
|
|
//$this->del(); |
619
|
|
|
|
620
|
|
|
|
621
|
|
|
if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) { |
622
|
|
|
if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
623
|
|
|
if ($globalDebug) echo "---- Deleting Live Marine data Not updated since 2 hour..."; |
624
|
|
|
$MarineLive = new MarineLive($this->db); |
625
|
|
|
$MarineLive->deleteLiveMarineDataNotUpdated(); |
626
|
|
|
$MarineLive->db = null; |
627
|
|
|
//MarineLive->deleteLiveMarineData(); |
628
|
|
|
if ($globalDebug) echo " Done\n"; |
629
|
|
|
} |
630
|
|
|
$this->last_delete_hourly = time(); |
631
|
|
|
} |
632
|
|
|
|
633
|
|
|
} |
634
|
|
|
//$ignoreImport = false; |
635
|
|
|
} |
636
|
|
|
//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN); |
637
|
|
|
if ($send) return $this->all_tracked[$id]; |
638
|
|
|
} |
639
|
|
|
} |
640
|
|
|
} |
641
|
|
|
} |
642
|
|
|
?> |
643
|
|
|
|
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.