@@ -54,7 +54,9 @@ discard block |
||
54 | 54 | public function checkAll() { |
55 | 55 | global $globalDebug, $globalNoDB; |
56 | 56 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
57 | - if ($globalDebug) echo "Update last seen tracked data...\n"; |
|
57 | + if ($globalDebug) { |
|
58 | + echo "Update last seen tracked data...\n"; |
|
59 | + } |
|
58 | 60 | foreach ($this->all_tracked as $key => $flight) { |
59 | 61 | if (isset($this->all_tracked[$key]['id'])) { |
60 | 62 | //echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].' '.$this->all_tracked[$key]['longitude']."\n"; |
@@ -68,13 +70,17 @@ discard block |
||
68 | 70 | public function del() { |
69 | 71 | global $globalDebug, $globalNoDB, $globalNoImport; |
70 | 72 | // Delete old infos |
71 | - if ($globalDebug) echo 'Delete old values and update latest data...'."\n"; |
|
73 | + if ($globalDebug) { |
|
74 | + echo 'Delete old values and update latest data...'."\n"; |
|
75 | + } |
|
72 | 76 | foreach ($this->all_tracked as $key => $flight) { |
73 | 77 | if (isset($flight['lastupdate'])) { |
74 | 78 | if ($flight['lastupdate'] < (time()-3000)) { |
75 | 79 | if ((!isset($globalNoImport) || $globalNoImport !== TRUE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) { |
76 | 80 | if (isset($this->all_tracked[$key]['id'])) { |
77 | - if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n"; |
|
81 | + if ($globalDebug) { |
|
82 | + echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n"; |
|
83 | + } |
|
78 | 84 | /* |
79 | 85 | $MarineLive = new MarineLive(); |
80 | 86 | $MarineLive->deleteLiveMarineDataById($this->all_tracked[$key]['id']); |
@@ -84,7 +90,9 @@ discard block |
||
84 | 90 | $Marine = new Marine($this->db); |
85 | 91 | if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') { |
86 | 92 | $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']); |
87 | - if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
|
93 | + if ($globalDebug && $result != 'success') { |
|
94 | + echo '!!! ERROR : '.$result."\n"; |
|
95 | + } |
|
88 | 96 | } |
89 | 97 | // Put in archive |
90 | 98 | // $Marine->db = null; |
@@ -98,7 +106,9 @@ discard block |
||
98 | 106 | |
99 | 107 | public function add($line) { |
100 | 108 | global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked, $globalNoImport, $globalNoDB, $globalServerAPRS,$APRSMarine; |
101 | - if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02'; |
|
109 | + if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') { |
|
110 | + $globalCoordMinChange = '0.02'; |
|
111 | + } |
|
102 | 112 | date_default_timezone_set('UTC'); |
103 | 113 | $dataFound = false; |
104 | 114 | $send = false; |
@@ -112,20 +122,30 @@ discard block |
||
112 | 122 | // Increment message number |
113 | 123 | if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE) { |
114 | 124 | $current_date = date('Y-m-d'); |
115 | - if (isset($line['source_name'])) $source = $line['source_name']; |
|
116 | - else $source = ''; |
|
117 | - if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source']; |
|
125 | + if (isset($line['source_name'])) { |
|
126 | + $source = $line['source_name']; |
|
127 | + } else { |
|
128 | + $source = ''; |
|
129 | + } |
|
130 | + if ($source == '' || $line['format_source'] == 'aprs') { |
|
131 | + $source = $line['format_source']; |
|
132 | + } |
|
118 | 133 | if (!isset($this->stats[$current_date][$source]['msg'])) { |
119 | 134 | $this->stats[$current_date][$source]['msg']['date'] = time(); |
120 | 135 | $this->stats[$current_date][$source]['msg']['nb'] = 1; |
121 | - } else $this->stats[$current_date][$source]['msg']['nb'] += 1; |
|
136 | + } else { |
|
137 | + $this->stats[$current_date][$source]['msg']['nb'] += 1; |
|
138 | + } |
|
122 | 139 | } |
123 | 140 | |
124 | 141 | |
125 | 142 | $Common = new Common(); |
126 | 143 | $AIS = new AIS(); |
127 | - if (!isset($line['id'])) $id = trim($line['mmsi']); |
|
128 | - else $id = trim($line['id']); |
|
144 | + if (!isset($line['id'])) { |
|
145 | + $id = trim($line['mmsi']); |
|
146 | + } else { |
|
147 | + $id = trim($line['id']); |
|
148 | + } |
|
129 | 149 | |
130 | 150 | if (!isset($this->all_tracked[$id])) { |
131 | 151 | $this->all_tracked[$id] = array(); |
@@ -133,10 +153,16 @@ discard block |
||
133 | 153 | $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' => '')); |
134 | 154 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time())); |
135 | 155 | if (!isset($line['id'])) { |
136 | - if (!isset($globalDaemon)) $globalDaemon = TRUE; |
|
156 | + if (!isset($globalDaemon)) { |
|
157 | + $globalDaemon = TRUE; |
|
158 | + } |
|
137 | 159 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $id.'-'.date('YmdHi'))); |
138 | - } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id'])); |
|
139 | - if ($globalAllTracked !== FALSE) $dataFound = true; |
|
160 | + } else { |
|
161 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id'])); |
|
162 | + } |
|
163 | + if ($globalAllTracked !== FALSE) { |
|
164 | + $dataFound = true; |
|
165 | + } |
|
140 | 166 | } |
141 | 167 | |
142 | 168 | if (isset($line['mmsi']) && $line['mmsi'] != '' && $line['mmsi'] != $this->all_tracked[$id]['mmsi']) { |
@@ -191,7 +217,9 @@ discard block |
||
191 | 217 | if (isset($line['arrival_code']) && $line['arrival_code'] != '') { |
192 | 218 | if (!isset($this->all_tracked[$id]['arrival_code'])) { |
193 | 219 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_code' => $line['arrival_code'])); |
194 | - if ($globalDebug) echo $this->all_tracked[$id]['id'].' => New arrival: '.$line['arrival_code']."\n"; |
|
220 | + if ($globalDebug) { |
|
221 | + echo $this->all_tracked[$id]['id'].' => New arrival: '.$line['arrival_code']."\n"; |
|
222 | + } |
|
195 | 223 | if ($this->all_tracked[$id]['addedMarine'] != 0) { |
196 | 224 | if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
197 | 225 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
@@ -204,7 +232,9 @@ discard block |
||
204 | 232 | } |
205 | 233 | } elseif ($this->all_tracked[$id]['arrival_code'] != $line['arrival_code']) { |
206 | 234 | $this->all_tracked[$id]['arrival_code'] = $line['arrival_code']; |
207 | - if ($globalDebug) echo $this->all_tracked[$id]['id'].' => New arrival: '.$line['arrival_code']."\n"; |
|
235 | + if ($globalDebug) { |
|
236 | + echo $this->all_tracked[$id]['id'].' => New arrival: '.$line['arrival_code']."\n"; |
|
237 | + } |
|
208 | 238 | if (!isset($line['id'])) { |
209 | 239 | $this->all_tracked[$id]['id'] = $id.'-'.date('YmdHi'); |
210 | 240 | $this->all_tracked[$id]['forcenew'] = 1; |
@@ -213,7 +243,9 @@ discard block |
||
213 | 243 | } |
214 | 244 | } |
215 | 245 | if (isset($line['arrival_date']) && $line['arrival_date'] != '') { |
216 | - if (strtotime($line['arrival_date']) > time()) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date'])); |
|
246 | + if (strtotime($line['arrival_date']) > time()) { |
|
247 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date'])); |
|
248 | + } |
|
217 | 249 | } |
218 | 250 | |
219 | 251 | //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'])) { |
@@ -234,34 +266,49 @@ discard block |
||
234 | 266 | $Marine = new Marine($this->db); |
235 | 267 | $fromsource = NULL; |
236 | 268 | $result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource); |
237 | - if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
|
269 | + if ($globalDebug && $result != 'success') { |
|
270 | + echo '!!! ERROR : '.$result."\n"; |
|
271 | + } |
|
238 | 272 | $Marine->db = null; |
239 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
273 | + if ($globalDebugTimeElapsed) { |
|
274 | + echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
275 | + } |
|
240 | 276 | } |
241 | 277 | } |
242 | 278 | } |
243 | - if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident'])); |
|
279 | + if (!isset($this->all_tracked[$id]['id'])) { |
|
280 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident'])); |
|
281 | + } |
|
244 | 282 | } |
245 | 283 | |
246 | 284 | if (isset($line['datetime']) && strtotime($line['datetime']) > time()-30*60 && strtotime($line['datetime']) < time()+20*60) { |
247 | 285 | if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) { |
248 | 286 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime'])); |
249 | 287 | } else { |
250 | - 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"; |
|
251 | - 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"; |
|
288 | + if (strtotime($line['datetime']) == strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) { |
|
289 | + echo "!!! Date is the same as previous data for ".$this->all_tracked[$id]['mmsi']."\n"; |
|
290 | + } elseif (strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) { |
|
291 | + echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_tracked[$id]['datetime'].") !!! for ".$this->all_tracked[$id]['hex']." - format : ".$line['format_source']."\n"; |
|
292 | + } |
|
252 | 293 | return ''; |
253 | 294 | } |
254 | 295 | } elseif (isset($line['datetime']) && strtotime($line['datetime']) <= time()-30*60) { |
255 | - if ($globalDebug) echo "!!! Date is too old ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!\n"; |
|
296 | + if ($globalDebug) { |
|
297 | + echo "!!! Date is too old ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!\n"; |
|
298 | + } |
|
256 | 299 | return ''; |
257 | 300 | } elseif (isset($line['datetime']) && strtotime($line['datetime']) >= time()+20*60) { |
258 | - if ($globalDebug) echo "!!! Date is in the future ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!\n"; |
|
301 | + if ($globalDebug) { |
|
302 | + echo "!!! Date is in the future ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!\n"; |
|
303 | + } |
|
259 | 304 | return ''; |
260 | 305 | } elseif (!isset($line['datetime'])) { |
261 | 306 | date_default_timezone_set('UTC'); |
262 | 307 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => date('Y-m-d H:i:s'))); |
263 | 308 | } else { |
264 | - if ($globalDebug) echo "!!! Unknow date error ".$this->all_tracked[$id]['mmsi']." date: ".$line['datetime']." - format : ".$line['format_source']."!!!\n"; |
|
309 | + if ($globalDebug) { |
|
310 | + echo "!!! Unknow date error ".$this->all_tracked[$id]['mmsi']." date: ".$line['datetime']." - format : ".$line['format_source']."!!!\n"; |
|
311 | + } |
|
265 | 312 | return ''; |
266 | 313 | } |
267 | 314 | |
@@ -274,14 +321,21 @@ discard block |
||
274 | 321 | if ($distance > 1000 && $distance < 10000) { |
275 | 322 | $speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']); |
276 | 323 | $speed = $speed*3.6; |
277 | - if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed))); |
|
278 | - if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n"; |
|
324 | + if ($speed < 1000) { |
|
325 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed))); |
|
326 | + } |
|
327 | + if ($globalDebug) { |
|
328 | + echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n"; |
|
329 | + } |
|
279 | 330 | } |
280 | 331 | } |
281 | 332 | |
282 | 333 | if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) { |
283 | - if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']); |
|
284 | - else unset($timediff); |
|
334 | + if (isset($this->all_tracked[$id]['time_last_coord'])) { |
|
335 | + $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']); |
|
336 | + } else { |
|
337 | + unset($timediff); |
|
338 | + } |
|
285 | 339 | if ($this->tmd > 5 || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_tracked[$id]['latitude']) && isset($this->all_tracked[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')))) { |
286 | 340 | 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'])) { |
287 | 341 | 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'])) { |
@@ -289,22 +343,32 @@ discard block |
||
289 | 343 | $this->all_tracked[$id]['archive_longitude'] = $line['longitude']; |
290 | 344 | $this->all_tracked[$id]['putinarchive'] = true; |
291 | 345 | |
292 | - if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... '; |
|
346 | + if ($globalDebug) { |
|
347 | + echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... '; |
|
348 | + } |
|
293 | 349 | $timeelapsed = microtime(true); |
294 | 350 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
295 | 351 | $Marine = new Marine($this->db); |
296 | 352 | $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']); |
297 | - if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2']; |
|
353 | + if (!empty($all_country)) { |
|
354 | + $this->all_tracked[$id]['over_country'] = $all_country['iso2']; |
|
355 | + } |
|
298 | 356 | $Marine->db = null; |
299 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
357 | + if ($globalDebugTimeElapsed) { |
|
358 | + echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
359 | + } |
|
300 | 360 | } |
301 | 361 | $this->tmd = 0; |
302 | - if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n"; |
|
362 | + if ($globalDebug) { |
|
363 | + echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n"; |
|
364 | + } |
|
303 | 365 | } |
304 | 366 | } |
305 | 367 | |
306 | 368 | if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) { |
307 | - if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude']; |
|
369 | + if (!isset($this->all_tracked[$id]['archive_latitude'])) { |
|
370 | + $this->all_tracked[$id]['archive_latitude'] = $line['latitude']; |
|
371 | + } |
|
308 | 372 | 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') { |
309 | 373 | $this->all_tracked[$id]['livedb_latitude'] = $line['latitude']; |
310 | 374 | $dataFound = true; |
@@ -313,8 +377,12 @@ discard block |
||
313 | 377 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude'])); |
314 | 378 | } |
315 | 379 | if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) { |
316 | - if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360; |
|
317 | - if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude']; |
|
380 | + if ($line['longitude'] > 180) { |
|
381 | + $line['longitude'] = $line['longitude'] - 360; |
|
382 | + } |
|
383 | + if (!isset($this->all_tracked[$id]['archive_longitude'])) { |
|
384 | + $this->all_tracked[$id]['archive_longitude'] = $line['longitude']; |
|
385 | + } |
|
318 | 386 | 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') { |
319 | 387 | $this->all_tracked[$id]['livedb_longitude'] = $line['longitude']; |
320 | 388 | $dataFound = true; |
@@ -332,7 +400,9 @@ discard block |
||
332 | 400 | } |
333 | 401 | } |
334 | 402 | if (isset($line['last_update']) && $line['last_update'] != '') { |
335 | - if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true; |
|
403 | + if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) { |
|
404 | + $dataFound = true; |
|
405 | + } |
|
336 | 406 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update'])); |
337 | 407 | } |
338 | 408 | if (isset($line['format_source']) && $line['format_source'] != '') { |
@@ -346,15 +416,21 @@ discard block |
||
346 | 416 | } |
347 | 417 | |
348 | 418 | if (isset($line['heading']) && $line['heading'] != '') { |
349 | - if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true; |
|
419 | + if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) { |
|
420 | + $this->all_tracked[$id]['putinarchive'] = true; |
|
421 | + } |
|
350 | 422 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading']))); |
351 | 423 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true)); |
352 | 424 | //$dataFound = true; |
353 | 425 | } 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']) { |
354 | 426 | $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']); |
355 | 427 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading))); |
356 | - if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true; |
|
357 | - if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n"; |
|
428 | + if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) { |
|
429 | + $this->all_tracked[$id]['putinarchive'] = true; |
|
430 | + } |
|
431 | + if ($globalDebug) { |
|
432 | + echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n"; |
|
433 | + } |
|
358 | 434 | } |
359 | 435 | //if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false; |
360 | 436 | |
@@ -366,23 +442,38 @@ discard block |
||
366 | 442 | 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'])) { |
367 | 443 | if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) { |
368 | 444 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
369 | - if ($globalDebug) echo "Check if vessel is already in DB..."; |
|
445 | + if ($globalDebug) { |
|
446 | + echo "Check if vessel is already in DB..."; |
|
447 | + } |
|
370 | 448 | $timeelapsed = microtime(true); |
371 | 449 | $MarineLive = new MarineLive($this->db); |
372 | 450 | if (isset($line['id'])) { |
373 | 451 | $recent_ident = $MarineLive->checkIdRecent($line['id']); |
374 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
452 | + if ($globalDebugTimeElapsed) { |
|
453 | + echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
454 | + } |
|
375 | 455 | } elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') { |
376 | 456 | $recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']); |
377 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
457 | + if ($globalDebugTimeElapsed) { |
|
458 | + echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
459 | + } |
|
378 | 460 | } elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') { |
379 | 461 | $recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']); |
380 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
381 | - } else $recent_ident = ''; |
|
462 | + if ($globalDebugTimeElapsed) { |
|
463 | + echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
464 | + } |
|
465 | + } else { |
|
466 | + $recent_ident = ''; |
|
467 | + } |
|
382 | 468 | $MarineLive->db=null; |
383 | - if ($globalDebug && $recent_ident == '') echo " Not in DB.\n"; |
|
384 | - elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n"; |
|
385 | - } else $recent_ident = ''; |
|
469 | + if ($globalDebug && $recent_ident == '') { |
|
470 | + echo " Not in DB.\n"; |
|
471 | + } elseif ($globalDebug && $recent_ident != '') { |
|
472 | + echo " Already in DB.\n"; |
|
473 | + } |
|
474 | + } else { |
|
475 | + $recent_ident = ''; |
|
476 | + } |
|
386 | 477 | } else { |
387 | 478 | $recent_ident = ''; |
388 | 479 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0)); |
@@ -390,30 +481,44 @@ discard block |
||
390 | 481 | //if there was no vessel with the same callsign within the last hour and go post it into the archive |
391 | 482 | if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') |
392 | 483 | { |
393 | - if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : "; |
|
484 | + if ($globalDebug) { |
|
485 | + echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : "; |
|
486 | + } |
|
394 | 487 | //adds the spotter data for the archive |
395 | 488 | $highlight = ''; |
396 | - 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'))); |
|
489 | + if (!isset($this->all_tracked[$id]['id'])) { |
|
490 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi'))); |
|
491 | + } |
|
397 | 492 | if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
398 | 493 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
399 | 494 | $timeelapsed = microtime(true); |
400 | 495 | $Marine = new Marine($this->db); |
401 | 496 | $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']); |
402 | 497 | $Marine->db = null; |
403 | - if ($globalDebug && isset($result)) echo $result."\n"; |
|
404 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
498 | + if ($globalDebug && isset($result)) { |
|
499 | + echo $result."\n"; |
|
500 | + } |
|
501 | + if ($globalDebugTimeElapsed) { |
|
502 | + echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
503 | + } |
|
405 | 504 | } |
406 | 505 | } |
407 | 506 | if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') { |
408 | 507 | // Add source stat in DB |
409 | 508 | $Stats = new Stats($this->db); |
410 | 509 | if (!empty($this->stats)) { |
411 | - if ($globalDebug) echo 'Add source stats : '; |
|
510 | + if ($globalDebug) { |
|
511 | + echo 'Add source stats : '; |
|
512 | + } |
|
412 | 513 | foreach($this->stats as $date => $data) { |
413 | 514 | foreach($data as $source => $sourced) { |
414 | 515 | //print_r($sourced); |
415 | - if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar_marine',$date); |
|
416 | - if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist_marine',$date); |
|
516 | + if (isset($sourced['polar'])) { |
|
517 | + echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar_marine',$date); |
|
518 | + } |
|
519 | + if (isset($sourced['hist'])) { |
|
520 | + echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist_marine',$date); |
|
521 | + } |
|
417 | 522 | if (isset($sourced['msg'])) { |
418 | 523 | if (time() - $sourced['msg']['date'] > 10) { |
419 | 524 | $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date'])); |
@@ -426,7 +531,9 @@ discard block |
||
426 | 531 | unset($this->stats[$date]); |
427 | 532 | } |
428 | 533 | } |
429 | - if ($globalDebug) echo 'Done'."\n"; |
|
534 | + if ($globalDebug) { |
|
535 | + echo 'Done'."\n"; |
|
536 | + } |
|
430 | 537 | } |
431 | 538 | $Stats->db = null; |
432 | 539 | } |
@@ -436,13 +543,17 @@ discard block |
||
436 | 543 | $this->all_tracked[$id]['addedMarine'] = 1; |
437 | 544 | //print_r($this->all_tracked[$id]); |
438 | 545 | if ($this->last_delete == 0 || time() - $this->last_delete > 1800) { |
439 | - if ($globalDebug) echo "---- Deleting Live Marine data older than 9 hours..."; |
|
546 | + if ($globalDebug) { |
|
547 | + echo "---- Deleting Live Marine data older than 9 hours..."; |
|
548 | + } |
|
440 | 549 | //MarineLive->deleteLiveMarineDataNotUpdated(); |
441 | 550 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
442 | 551 | $MarineLive = new MarineLive($this->db); |
443 | 552 | $MarineLive->deleteLiveMarineData(); |
444 | 553 | $MarineLive->db=null; |
445 | - if ($globalDebug) echo " Done\n"; |
|
554 | + if ($globalDebug) { |
|
555 | + echo " Done\n"; |
|
556 | + } |
|
446 | 557 | } |
447 | 558 | $this->last_delete = time(); |
448 | 559 | } |
@@ -468,15 +579,21 @@ discard block |
||
468 | 579 | |
469 | 580 | if (!$ignoreImport) { |
470 | 581 | 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'])) { |
471 | - if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : "; |
|
582 | + if ($globalDebug) { |
|
583 | + echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : "; |
|
584 | + } |
|
472 | 585 | if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
473 | 586 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
474 | 587 | $timeelapsed = microtime(true); |
475 | 588 | $MarineLive = new MarineLive($this->db); |
476 | 589 | $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']); |
477 | 590 | $MarineLive->db = null; |
478 | - if ($globalDebug) echo $result."\n"; |
|
479 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
591 | + if ($globalDebug) { |
|
592 | + echo $result."\n"; |
|
593 | + } |
|
594 | + if ($globalDebugTimeElapsed) { |
|
595 | + echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
596 | + } |
|
480 | 597 | } |
481 | 598 | } |
482 | 599 | if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_tracked[$id]['putinarchive']) { |
@@ -488,7 +605,9 @@ discard block |
||
488 | 605 | |
489 | 606 | if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $line['format_source'] != 'aprs' && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') { |
490 | 607 | $source = $this->all_tracked[$id]['source_name']; |
491 | - if ($source == '') $source = $this->all_tracked[$id]['format_source']; |
|
608 | + if ($source == '') { |
|
609 | + $source = $this->all_tracked[$id]['format_source']; |
|
610 | + } |
|
492 | 611 | if (!isset($this->source_location[$source])) { |
493 | 612 | $Location = new Source($this->db); |
494 | 613 | $coord = $Location->getLocationInfobySourceName($source); |
@@ -509,7 +628,9 @@ discard block |
||
509 | 628 | $stats_heading = round($stats_heading/22.5); |
510 | 629 | $stats_distance = $Common->distance($latitude,$longitude,$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']); |
511 | 630 | $current_date = date('Y-m-d'); |
512 | - if ($stats_heading == 16) $stats_heading = 0; |
|
631 | + if ($stats_heading == 16) { |
|
632 | + $stats_heading = 0; |
|
633 | + } |
|
513 | 634 | if (!isset($this->stats[$current_date][$source]['polar'][1])) { |
514 | 635 | for ($i=0;$i<=15;$i++) { |
515 | 636 | $this->stats[$current_date][$source]['polar'][$i] = 0; |
@@ -527,7 +648,9 @@ discard block |
||
527 | 648 | if (isset($this->stats[$current_date][$source]['hist'][0])) { |
528 | 649 | end($this->stats[$current_date][$source]['hist']); |
529 | 650 | $mini = key($this->stats[$current_date][$source]['hist'])+10; |
530 | - } else $mini = 0; |
|
651 | + } else { |
|
652 | + $mini = 0; |
|
653 | + } |
|
531 | 654 | for ($i=$mini;$i<=$distance;$i+=10) { |
532 | 655 | $this->stats[$current_date][$source]['hist'][$i] = 0; |
533 | 656 | } |
@@ -539,19 +662,27 @@ discard block |
||
539 | 662 | |
540 | 663 | |
541 | 664 | $this->all_tracked[$id]['lastupdate'] = time(); |
542 | - if ($this->all_tracked[$id]['putinarchive']) $send = true; |
|
543 | - } 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"; |
|
665 | + if ($this->all_tracked[$id]['putinarchive']) { |
|
666 | + $send = true; |
|
667 | + } |
|
668 | + } elseif (isset($this->all_tracked[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) { |
|
669 | + echo "!! Too far -> Distance : ".$Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n"; |
|
670 | + } |
|
544 | 671 | //$this->del(); |
545 | 672 | |
546 | 673 | |
547 | 674 | if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) { |
548 | 675 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
549 | - if ($globalDebug) echo "---- Deleting Live Marine data Not updated since 2 hour..."; |
|
676 | + if ($globalDebug) { |
|
677 | + echo "---- Deleting Live Marine data Not updated since 2 hour..."; |
|
678 | + } |
|
550 | 679 | $MarineLive = new MarineLive($this->db); |
551 | 680 | $MarineLive->deleteLiveMarineDataNotUpdated(); |
552 | 681 | $MarineLive->db = null; |
553 | 682 | //MarineLive->deleteLiveMarineData(); |
554 | - if ($globalDebug) echo " Done\n"; |
|
683 | + if ($globalDebug) { |
|
684 | + echo " Done\n"; |
|
685 | + } |
|
555 | 686 | } |
556 | 687 | $this->last_delete_hourly = time(); |
557 | 688 | } |
@@ -560,7 +691,9 @@ discard block |
||
560 | 691 | //$ignoreImport = false; |
561 | 692 | } |
562 | 693 | //if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN); |
563 | - if ($send) return $this->all_tracked[$id]; |
|
694 | + if ($send) { |
|
695 | + return $this->all_tracked[$id]; |
|
696 | + } |
|
564 | 697 | } |
565 | 698 | } |
566 | 699 | } |