@@ -9,25 +9,25 @@ discard block |
||
| 9 | 9 | require_once(dirname(__FILE__).'/class.Stats.php'); |
| 10 | 10 | require_once(dirname(__FILE__).'/class.Source.php'); |
| 11 | 11 | if (isset($globalServerAPRS) && $globalServerAPRS) { |
| 12 | - require_once(dirname(__FILE__).'/class.APRS.php'); |
|
| 12 | + require_once(dirname(__FILE__).'/class.APRS.php'); |
|
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 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; |
|
| 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 | 24 | |
| 25 | - public function __construct($dbc = null) { |
|
| 25 | + public function __construct($dbc = null) { |
|
| 26 | 26 | global $globalBeta, $globalServerAPRS, $APRSSpotter, $globalNoDB; |
| 27 | 27 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 28 | - $Connection = new Connection($dbc); |
|
| 29 | - $this->db = $Connection->db(); |
|
| 30 | - date_default_timezone_set('UTC'); |
|
| 28 | + $Connection = new Connection($dbc); |
|
| 29 | + $this->db = $Connection->db(); |
|
| 30 | + date_default_timezone_set('UTC'); |
|
| 31 | 31 | } |
| 32 | 32 | // Get previous source stats |
| 33 | 33 | /* |
@@ -46,53 +46,53 @@ discard block |
||
| 46 | 46 | } |
| 47 | 47 | */ |
| 48 | 48 | if (isset($globalServerAPRS) && $globalServerAPRS) { |
| 49 | - $APRSMarine = new APRSMarine(); |
|
| 50 | - //$APRSSpotter->connect(); |
|
| 49 | + $APRSMarine = new APRSMarine(); |
|
| 50 | + //$APRSSpotter->connect(); |
|
| 51 | + } |
|
| 51 | 52 | } |
| 52 | - } |
|
| 53 | 53 | |
| 54 | - public function checkAll() { |
|
| 54 | + public function checkAll() { |
|
| 55 | 55 | global $globalDebug; |
| 56 | 56 | if ($globalDebug) echo "Update last seen tracked data...\n"; |
| 57 | 57 | foreach ($this->all_tracked as $key => $flight) { |
| 58 | - if (isset($this->all_tracked[$key]['id'])) { |
|
| 58 | + if (isset($this->all_tracked[$key]['id'])) { |
|
| 59 | 59 | //echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].' '.$this->all_tracked[$key]['longitude']."\n"; |
| 60 | - $Marine = new Marine($this->db); |
|
| 61 | - $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']); |
|
| 62 | - } |
|
| 60 | + $Marine = new Marine($this->db); |
|
| 61 | + $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']); |
|
| 62 | + } |
|
| 63 | + } |
|
| 63 | 64 | } |
| 64 | - } |
|
| 65 | 65 | |
| 66 | - public function del() { |
|
| 66 | + public function del() { |
|
| 67 | 67 | global $globalDebug; |
| 68 | 68 | // Delete old infos |
| 69 | 69 | if ($globalDebug) echo 'Delete old values and update latest data...'."\n"; |
| 70 | 70 | foreach ($this->all_tracked as $key => $flight) { |
| 71 | - if (isset($flight['lastupdate'])) { |
|
| 72 | - if ($flight['lastupdate'] < (time()-3000)) { |
|
| 73 | - if (isset($this->all_tracked[$key]['id'])) { |
|
| 74 | - if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n"; |
|
| 71 | + if (isset($flight['lastupdate'])) { |
|
| 72 | + if ($flight['lastupdate'] < (time()-3000)) { |
|
| 73 | + if (isset($this->all_tracked[$key]['id'])) { |
|
| 74 | + if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n"; |
|
| 75 | 75 | /* |
| 76 | 76 | $MarineLive = new MarineLive(); |
| 77 | 77 | $MarineLive->deleteLiveMarineDataById($this->all_tracked[$key]['id']); |
| 78 | 78 | $MarineLive->db = null; |
| 79 | 79 | */ |
| 80 | - //$real_arrival = $this->arrival($key); |
|
| 81 | - $Marine = new Marine($this->db); |
|
| 82 | - if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') { |
|
| 80 | + //$real_arrival = $this->arrival($key); |
|
| 81 | + $Marine = new Marine($this->db); |
|
| 82 | + if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') { |
|
| 83 | 83 | $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']); |
| 84 | 84 | if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
| 85 | 85 | } |
| 86 | 86 | // Put in archive |
| 87 | 87 | // $Marine->db = null; |
| 88 | - } |
|
| 89 | - unset($this->all_tracked[$key]); |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - } |
|
| 93 | - } |
|
| 88 | + } |
|
| 89 | + unset($this->all_tracked[$key]); |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - public function add($line) { |
|
| 95 | + public function add($line) { |
|
| 96 | 96 | global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked, $globalNoImport, $globalNoDB; |
| 97 | 97 | if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02'; |
| 98 | 98 | date_default_timezone_set('UTC'); |
@@ -101,8 +101,8 @@ discard block |
||
| 101 | 101 | |
| 102 | 102 | // SBS format is CSV format |
| 103 | 103 | if(is_array($line) && isset($line['mmsi'])) { |
| 104 | - //print_r($line); |
|
| 105 | - if (isset($line['mmsi'])) { |
|
| 104 | + //print_r($line); |
|
| 105 | + if (isset($line['mmsi'])) { |
|
| 106 | 106 | |
| 107 | 107 | /* |
| 108 | 108 | // Increment message number |
@@ -119,61 +119,61 @@ discard block |
||
| 119 | 119 | |
| 120 | 120 | $Common = new Common(); |
| 121 | 121 | $AIS = new AIS(); |
| 122 | - if (!isset($line['id'])) $id = trim($line['mmsi']); |
|
| 123 | - else $id = trim($line['id']); |
|
| 122 | + if (!isset($line['id'])) $id = trim($line['mmsi']); |
|
| 123 | + else $id = trim($line['id']); |
|
| 124 | 124 | |
| 125 | 125 | if (!isset($this->all_tracked[$id])) { |
| 126 | - $this->all_tracked[$id] = array(); |
|
| 127 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('addedMarine' => 0)); |
|
| 128 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','typeid' => '','noarchive' => false,'putinarchive' => true,'over_country' => '','mmsi' => '','status' => '','imo' => '','callsign' => '','arrival_code' => '','arrival_date' => '')); |
|
| 129 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time())); |
|
| 130 | - if (!isset($line['id'])) { |
|
| 126 | + $this->all_tracked[$id] = array(); |
|
| 127 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('addedMarine' => 0)); |
|
| 128 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','typeid' => '','noarchive' => false,'putinarchive' => true,'over_country' => '','mmsi' => '','status' => '','imo' => '','callsign' => '','arrival_code' => '','arrival_date' => '')); |
|
| 129 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time())); |
|
| 130 | + if (!isset($line['id'])) { |
|
| 131 | 131 | if (!isset($globalDaemon)) $globalDaemon = TRUE; |
| 132 | 132 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $id.'-'.date('YmdHi'))); |
| 133 | - } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id'])); |
|
| 134 | - if ($globalAllTracked !== FALSE) $dataFound = true; |
|
| 133 | + } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id'])); |
|
| 134 | + if ($globalAllTracked !== FALSE) $dataFound = true; |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | if (isset($line['mmsi']) && $line['mmsi'] != '' && $line['mmsi'] != $this->all_tracked[$id]['mmsi']) { |
| 138 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi' => $line['mmsi'])); |
|
| 139 | - if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
|
| 138 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi' => $line['mmsi'])); |
|
| 139 | + if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
|
| 140 | 140 | $Marine = new Marine($this->db); |
| 141 | 141 | $identity = $Marine->getIdentity($line['mmsi']); |
| 142 | 142 | if (!empty($identity)) { |
| 143 | - $this->all_tracked[$id]['ident'] = $identity['ship_name']; |
|
| 144 | - $this->all_tracked[$id]['type'] = $identity['type']; |
|
| 143 | + $this->all_tracked[$id]['ident'] = $identity['ship_name']; |
|
| 144 | + $this->all_tracked[$id]['type'] = $identity['type']; |
|
| 145 | 145 | } |
| 146 | 146 | //print_r($identity); |
| 147 | 147 | unset($Marine); |
| 148 | 148 | //$dataFound = true; |
| 149 | - } |
|
| 149 | + } |
|
| 150 | 150 | } |
| 151 | 151 | if (isset($line['type_id']) && $line['type_id'] != '') { |
| 152 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $AIS->getShipType($line['type_id']))); |
|
| 152 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $AIS->getShipType($line['type_id']))); |
|
| 153 | 153 | } |
| 154 | 154 | if (isset($line['type']) && $line['type'] != '') { |
| 155 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type'])); |
|
| 155 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type'])); |
|
| 156 | 156 | } |
| 157 | 157 | if (isset($line['imo']) && $line['imo'] != '') { |
| 158 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('imo' => $line['imo'])); |
|
| 158 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('imo' => $line['imo'])); |
|
| 159 | 159 | } |
| 160 | 160 | if (isset($line['callsign']) && $line['callsign'] != '') { |
| 161 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('callsign' => $line['callsign'])); |
|
| 161 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('callsign' => $line['callsign'])); |
|
| 162 | 162 | } |
| 163 | 163 | if (isset($line['arrival_code']) && $line['arrival_code'] != '') { |
| 164 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_code' => $line['arrival_code'])); |
|
| 164 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_code' => $line['arrival_code'])); |
|
| 165 | 165 | } |
| 166 | 166 | if (isset($line['arrival_date']) && $line['arrival_date'] != '') { |
| 167 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date'])); |
|
| 167 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date'])); |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | |
| 171 | 171 | //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'])) { |
| 172 | 172 | if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_tracked[$id]['ident'] != trim($line['ident']))) { |
| 173 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident']))); |
|
| 174 | - if ($this->all_tracked[$id]['addedMarine'] == 1) { |
|
| 173 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident']))); |
|
| 174 | + if ($this->all_tracked[$id]['addedMarine'] == 1) { |
|
| 175 | 175 | if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
| 176 | - if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
|
| 176 | + if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
|
| 177 | 177 | $timeelapsed = microtime(true); |
| 178 | 178 | $Marine = new Marine($this->db); |
| 179 | 179 | $fromsource = NULL; |
@@ -181,31 +181,31 @@ discard block |
||
| 181 | 181 | if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
| 182 | 182 | $Marine->db = null; |
| 183 | 183 | if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
| 184 | - } |
|
| 184 | + } |
|
| 185 | 185 | } |
| 186 | - } |
|
| 187 | - if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident'])); |
|
| 186 | + } |
|
| 187 | + if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident'])); |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | if (isset($line['speed']) && $line['speed'] != '') { |
| 191 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed']))); |
|
| 192 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true)); |
|
| 191 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed']))); |
|
| 192 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true)); |
|
| 193 | 193 | } 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'])) { |
| 194 | - $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m'); |
|
| 195 | - if ($distance > 1000 && $distance < 10000) { |
|
| 194 | + $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m'); |
|
| 195 | + if ($distance > 1000 && $distance < 10000) { |
|
| 196 | 196 | $speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']); |
| 197 | 197 | $speed = $speed*3.6; |
| 198 | 198 | if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed))); |
| 199 | 199 | if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n"; |
| 200 | - } |
|
| 200 | + } |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | - if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) { |
|
| 204 | - if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']); |
|
| 205 | - else unset($timediff); |
|
| 206 | - 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')))) { |
|
| 203 | + if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) { |
|
| 204 | + if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']); |
|
| 205 | + else unset($timediff); |
|
| 206 | + 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')))) { |
|
| 207 | 207 | 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'])) { |
| 208 | - 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'])) { |
|
| 208 | + 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'])) { |
|
| 209 | 209 | $this->all_tracked[$id]['archive_latitude'] = $line['latitude']; |
| 210 | 210 | $this->all_tracked[$id]['archive_longitude'] = $line['longitude']; |
| 211 | 211 | $this->all_tracked[$id]['putinarchive'] = true; |
@@ -213,84 +213,84 @@ discard block |
||
| 213 | 213 | if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... '; |
| 214 | 214 | $timeelapsed = microtime(true); |
| 215 | 215 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 216 | - $Marine = new Marine($this->db); |
|
| 217 | - $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']); |
|
| 218 | - if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2']; |
|
| 219 | - $Marine->db = null; |
|
| 220 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 216 | + $Marine = new Marine($this->db); |
|
| 217 | + $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']); |
|
| 218 | + if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2']; |
|
| 219 | + $Marine->db = null; |
|
| 220 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 221 | 221 | } |
| 222 | 222 | $this->tmd = 0; |
| 223 | 223 | if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n"; |
| 224 | - } |
|
| 224 | + } |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) { |
| 228 | 228 | if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude']; |
| 229 | 229 | 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') { |
| 230 | - $this->all_tracked[$id]['livedb_latitude'] = $line['latitude']; |
|
| 231 | - $dataFound = true; |
|
| 232 | - $this->all_tracked[$id]['time_last_coord'] = time(); |
|
| 230 | + $this->all_tracked[$id]['livedb_latitude'] = $line['latitude']; |
|
| 231 | + $dataFound = true; |
|
| 232 | + $this->all_tracked[$id]['time_last_coord'] = time(); |
|
| 233 | 233 | } |
| 234 | 234 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude'])); |
| 235 | 235 | } |
| 236 | 236 | if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) { |
| 237 | - if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360; |
|
| 237 | + if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360; |
|
| 238 | 238 | if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude']; |
| 239 | 239 | 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') { |
| 240 | - $this->all_tracked[$id]['livedb_longitude'] = $line['longitude']; |
|
| 241 | - $dataFound = true; |
|
| 242 | - $this->all_tracked[$id]['time_last_coord'] = time(); |
|
| 240 | + $this->all_tracked[$id]['livedb_longitude'] = $line['longitude']; |
|
| 241 | + $dataFound = true; |
|
| 242 | + $this->all_tracked[$id]['time_last_coord'] = time(); |
|
| 243 | 243 | } |
| 244 | 244 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('longitude' => $line['longitude'])); |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | - } else if ($globalDebug && $timediff > 20) { |
|
| 247 | + } else if ($globalDebug && $timediff > 20) { |
|
| 248 | 248 | $this->tmd = $this->tmd + 1; |
| 249 | 249 | echo '!!! Too much distance in short time... for '.$this->all_tracked[$id]['ident']."\n"; |
| 250 | 250 | echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')."m -"; |
| 251 | 251 | echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')/$timediff)*3.6)." km/h - "; |
| 252 | 252 | echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_tracked[$id]['latitude'].' - prev long : '.$this->all_tracked[$id]['longitude']." \n"; |
| 253 | - } |
|
| 253 | + } |
|
| 254 | 254 | } |
| 255 | 255 | if (isset($line['last_update']) && $line['last_update'] != '') { |
| 256 | - if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true; |
|
| 257 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update'])); |
|
| 256 | + if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true; |
|
| 257 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update'])); |
|
| 258 | 258 | } |
| 259 | 259 | if (isset($line['format_source']) && $line['format_source'] != '') { |
| 260 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source'])); |
|
| 260 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source'])); |
|
| 261 | 261 | } |
| 262 | 262 | if (isset($line['source_name']) && $line['source_name'] != '') { |
| 263 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name'])); |
|
| 263 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name'])); |
|
| 264 | 264 | } |
| 265 | 265 | if (isset($line['status']) && $line['status'] != '') { |
| 266 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status' => $line['status'])); |
|
| 266 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status' => $line['status'])); |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | if (isset($line['noarchive']) && $line['noarchive'] === true) { |
| 270 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true)); |
|
| 270 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true)); |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | if (isset($line['heading']) && $line['heading'] != '') { |
| 274 | - if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true; |
|
| 275 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading']))); |
|
| 276 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true)); |
|
| 277 | - //$dataFound = true; |
|
| 274 | + if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true; |
|
| 275 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading']))); |
|
| 276 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true)); |
|
| 277 | + //$dataFound = true; |
|
| 278 | 278 | } 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']) { |
| 279 | - $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']); |
|
| 280 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading))); |
|
| 281 | - if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true; |
|
| 282 | - if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n"; |
|
| 279 | + $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']); |
|
| 280 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading))); |
|
| 281 | + if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true; |
|
| 282 | + if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n"; |
|
| 283 | 283 | } |
| 284 | 284 | //if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false; |
| 285 | 285 | |
| 286 | 286 | if (isset($line['datetime'])) { |
| 287 | - if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) { |
|
| 287 | + if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) { |
|
| 288 | 288 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime'])); |
| 289 | - } else { |
|
| 289 | + } else { |
|
| 290 | 290 | 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"; |
| 291 | 291 | 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"; |
| 292 | 292 | return ''; |
| 293 | - } |
|
| 293 | + } |
|
| 294 | 294 | } else { |
| 295 | 295 | date_default_timezone_set('UTC'); |
| 296 | 296 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => date('Y-m-d H:i:s'))); |
@@ -298,50 +298,50 @@ discard block |
||
| 298 | 298 | |
| 299 | 299 | |
| 300 | 300 | if ($dataFound === true && isset($this->all_tracked[$id]['mmsi'])) { |
| 301 | - $this->all_tracked[$id]['lastupdate'] = time(); |
|
| 302 | - if ($this->all_tracked[$id]['addedMarine'] == 0) { |
|
| 303 | - 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'])) { |
|
| 304 | - if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) { |
|
| 301 | + $this->all_tracked[$id]['lastupdate'] = time(); |
|
| 302 | + if ($this->all_tracked[$id]['addedMarine'] == 0) { |
|
| 303 | + 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'])) { |
|
| 304 | + if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) { |
|
| 305 | 305 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 306 | - if ($globalDebug) echo "Check if aircraft is already in DB..."; |
|
| 307 | - $timeelapsed = microtime(true); |
|
| 308 | - $MarineLive = new MarineLive($this->db); |
|
| 309 | - if (isset($line['id'])) { |
|
| 306 | + if ($globalDebug) echo "Check if aircraft is already in DB..."; |
|
| 307 | + $timeelapsed = microtime(true); |
|
| 308 | + $MarineLive = new MarineLive($this->db); |
|
| 309 | + if (isset($line['id'])) { |
|
| 310 | 310 | $recent_ident = $MarineLive->checkIdRecent($line['id']); |
| 311 | 311 | if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
| 312 | - } elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') { |
|
| 312 | + } elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') { |
|
| 313 | 313 | $recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']); |
| 314 | 314 | if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
| 315 | - } elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') { |
|
| 315 | + } elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') { |
|
| 316 | 316 | $recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']); |
| 317 | 317 | if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
| 318 | - } else $recent_ident = ''; |
|
| 319 | - $MarineLive->db=null; |
|
| 320 | - if ($globalDebug && $recent_ident == '') echo " Not in DB.\n"; |
|
| 321 | - elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n"; |
|
| 318 | + } else $recent_ident = ''; |
|
| 319 | + $MarineLive->db=null; |
|
| 320 | + if ($globalDebug && $recent_ident == '') echo " Not in DB.\n"; |
|
| 321 | + elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n"; |
|
| 322 | 322 | } else $recent_ident = ''; |
| 323 | - } else { |
|
| 323 | + } else { |
|
| 324 | 324 | $recent_ident = ''; |
| 325 | 325 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0)); |
| 326 | - } |
|
| 327 | - //if there was no aircraft with the same callsign within the last hour and go post it into the archive |
|
| 328 | - if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') |
|
| 329 | - { |
|
| 326 | + } |
|
| 327 | + //if there was no aircraft with the same callsign within the last hour and go post it into the archive |
|
| 328 | + if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') |
|
| 329 | + { |
|
| 330 | 330 | if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : "; |
| 331 | 331 | //adds the spotter data for the archive |
| 332 | - $highlight = ''; |
|
| 333 | - 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'))); |
|
| 334 | - if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
|
| 332 | + $highlight = ''; |
|
| 333 | + 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'))); |
|
| 334 | + if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
|
| 335 | 335 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 336 | - $timeelapsed = microtime(true); |
|
| 337 | - $Marine = new Marine($this->db); |
|
| 338 | - $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]['format_source'],$this->all_tracked[$id]['source_name']); |
|
| 339 | - $Marine->db = null; |
|
| 340 | - if ($globalDebug && isset($result)) echo $result."\n"; |
|
| 341 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 336 | + $timeelapsed = microtime(true); |
|
| 337 | + $Marine = new Marine($this->db); |
|
| 338 | + $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]['format_source'],$this->all_tracked[$id]['source_name']); |
|
| 339 | + $Marine->db = null; |
|
| 340 | + if ($globalDebug && isset($result)) echo $result."\n"; |
|
| 341 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 342 | 342 | } |
| 343 | - } |
|
| 344 | - /* |
|
| 343 | + } |
|
| 344 | + /* |
|
| 345 | 345 | // Add source stat in DB |
| 346 | 346 | $Stats = new Stats($this->db); |
| 347 | 347 | if (!empty($this->stats)) { |
@@ -368,55 +368,55 @@ discard block |
||
| 368 | 368 | } |
| 369 | 369 | $Stats->db = null; |
| 370 | 370 | */ |
| 371 | - $this->del(); |
|
| 371 | + $this->del(); |
|
| 372 | 372 | //$ignoreImport = false; |
| 373 | 373 | $this->all_tracked[$id]['addedMarine'] = 1; |
| 374 | 374 | //print_r($this->all_tracked[$id]); |
| 375 | 375 | if ($this->last_delete == 0 || time() - $this->last_delete > 1800) { |
| 376 | - if ($globalDebug) echo "---- Deleting Live Marine data older than 9 hours..."; |
|
| 377 | - //MarineLive->deleteLiveMarineDataNotUpdated(); |
|
| 378 | - if (!isset($globaNoDB) || $globalNoDB !== TRUE) { |
|
| 376 | + if ($globalDebug) echo "---- Deleting Live Marine data older than 9 hours..."; |
|
| 377 | + //MarineLive->deleteLiveMarineDataNotUpdated(); |
|
| 378 | + if (!isset($globaNoDB) || $globalNoDB !== TRUE) { |
|
| 379 | 379 | $MarineLive = new MarineLive($this->db); |
| 380 | 380 | $MarineLive->deleteLiveMarineData(); |
| 381 | 381 | $MarineLive->db=null; |
| 382 | 382 | if ($globalDebug) echo " Done\n"; |
| 383 | - } |
|
| 384 | - $this->last_delete = time(); |
|
| 383 | + } |
|
| 384 | + $this->last_delete = time(); |
|
| 385 | 385 | } |
| 386 | - } elseif ($recent_ident != '') { |
|
| 386 | + } elseif ($recent_ident != '') { |
|
| 387 | 387 | $this->all_tracked[$id]['id'] = $recent_ident; |
| 388 | 388 | $this->all_tracked[$id]['addedMarine'] = 1; |
| 389 | 389 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 390 | - if (isset($globalDaemon) && !$globalDaemon) { |
|
| 390 | + if (isset($globalDaemon) && !$globalDaemon) { |
|
| 391 | 391 | $Marine = new Marine($this->db); |
| 392 | 392 | $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']); |
| 393 | 393 | $Marine->db = null; |
| 394 | - } |
|
| 394 | + } |
|
| 395 | 395 | } |
| 396 | 396 | |
| 397 | - } |
|
| 397 | + } |
|
| 398 | 398 | } |
| 399 | - } |
|
| 400 | - //adds the spotter LIVE data |
|
| 401 | - if ($globalDebug) { |
|
| 399 | + } |
|
| 400 | + //adds the spotter LIVE data |
|
| 401 | + if ($globalDebug) { |
|
| 402 | 402 | 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"; |
| 403 | - } |
|
| 404 | - $ignoreImport = false; |
|
| 403 | + } |
|
| 404 | + $ignoreImport = false; |
|
| 405 | 405 | |
| 406 | - if (!$ignoreImport) { |
|
| 406 | + if (!$ignoreImport) { |
|
| 407 | 407 | 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'])) { |
| 408 | 408 | if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : "; |
| 409 | 409 | if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
| 410 | - if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
|
| 410 | + if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
|
| 411 | 411 | $timeelapsed = microtime(true); |
| 412 | 412 | $MarineLive = new MarineLive($this->db); |
| 413 | 413 | $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]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country']); |
| 414 | 414 | $MarineLive->db = null; |
| 415 | 415 | if ($globalDebug) echo $result."\n"; |
| 416 | - } |
|
| 416 | + } |
|
| 417 | 417 | } |
| 418 | 418 | if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_flights[$id]['putinarchive']) { |
| 419 | - $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]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country']); |
|
| 419 | + $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]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country']); |
|
| 420 | 420 | } |
| 421 | 421 | $this->all_tracked[$id]['putinarchive'] = false; |
| 422 | 422 | if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
@@ -482,24 +482,24 @@ discard block |
||
| 482 | 482 | |
| 483 | 483 | |
| 484 | 484 | if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) { |
| 485 | - if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
|
| 485 | + if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
|
| 486 | 486 | if ($globalDebug) echo "---- Deleting Live Marine data Not updated since 2 hour..."; |
| 487 | 487 | $MarineLive = new MarineLive($this->db); |
| 488 | 488 | $MarineLive->deleteLiveMarineDataNotUpdated(); |
| 489 | 489 | $MarineLive->db = null; |
| 490 | 490 | //MarineLive->deleteLiveMarineData(); |
| 491 | 491 | if ($globalDebug) echo " Done\n"; |
| 492 | - } |
|
| 493 | - $this->last_delete_hourly = time(); |
|
| 492 | + } |
|
| 493 | + $this->last_delete_hourly = time(); |
|
| 494 | 494 | } |
| 495 | 495 | |
| 496 | - } |
|
| 497 | - //$ignoreImport = false; |
|
| 496 | + } |
|
| 497 | + //$ignoreImport = false; |
|
| 498 | 498 | } |
| 499 | 499 | //if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN); |
| 500 | 500 | if ($send) return $this->all_tracked[$id]; |
| 501 | - } |
|
| 501 | + } |
|
| 502 | + } |
|
| 502 | 503 | } |
| 503 | - } |
|
| 504 | 504 | } |
| 505 | 505 | ?> |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | if (isset($this->all_tracked[$key]['id'])) { |
| 59 | 59 | //echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].' '.$this->all_tracked[$key]['longitude']."\n"; |
| 60 | 60 | $Marine = new Marine($this->db); |
| 61 | - $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']); |
|
| 61 | + $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']); |
|
| 62 | 62 | } |
| 63 | 63 | } |
| 64 | 64 | } |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | if ($globalDebug) echo 'Delete old values and update latest data...'."\n"; |
| 70 | 70 | foreach ($this->all_tracked as $key => $flight) { |
| 71 | 71 | if (isset($flight['lastupdate'])) { |
| 72 | - if ($flight['lastupdate'] < (time()-3000)) { |
|
| 72 | + if ($flight['lastupdate'] < (time() - 3000)) { |
|
| 73 | 73 | if (isset($this->all_tracked[$key]['id'])) { |
| 74 | 74 | if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n"; |
| 75 | 75 | /* |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | //$real_arrival = $this->arrival($key); |
| 81 | 81 | $Marine = new Marine($this->db); |
| 82 | 82 | if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') { |
| 83 | - $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']); |
|
| 83 | + $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']); |
|
| 84 | 84 | if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
| 85 | 85 | } |
| 86 | 86 | // Put in archive |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | $send = false; |
| 101 | 101 | |
| 102 | 102 | // SBS format is CSV format |
| 103 | - if(is_array($line) && isset($line['mmsi'])) { |
|
| 103 | + if (is_array($line) && isset($line['mmsi'])) { |
|
| 104 | 104 | //print_r($line); |
| 105 | 105 | if (isset($line['mmsi'])) { |
| 106 | 106 | |
@@ -124,18 +124,18 @@ discard block |
||
| 124 | 124 | |
| 125 | 125 | if (!isset($this->all_tracked[$id])) { |
| 126 | 126 | $this->all_tracked[$id] = array(); |
| 127 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('addedMarine' => 0)); |
|
| 128 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','typeid' => '','noarchive' => false,'putinarchive' => true,'over_country' => '','mmsi' => '','status' => '','imo' => '','callsign' => '','arrival_code' => '','arrival_date' => '')); |
|
| 129 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time())); |
|
| 127 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('addedMarine' => 0)); |
|
| 128 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('ident' => '', 'latitude' => '', 'longitude' => '', 'speed' => '', 'heading' => '', 'format_source' => '', 'source_name' => '', 'comment'=> '', 'type' => '', 'typeid' => '', 'noarchive' => false, 'putinarchive' => true, 'over_country' => '', 'mmsi' => '', 'status' => '', 'imo' => '', 'callsign' => '', 'arrival_code' => '', 'arrival_date' => '')); |
|
| 129 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('lastupdate' => time())); |
|
| 130 | 130 | if (!isset($line['id'])) { |
| 131 | 131 | if (!isset($globalDaemon)) $globalDaemon = TRUE; |
| 132 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $id.'-'.date('YmdHi'))); |
|
| 133 | - } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id'])); |
|
| 132 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('id' => $id.'-'.date('YmdHi'))); |
|
| 133 | + } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('id' => $line['id'])); |
|
| 134 | 134 | if ($globalAllTracked !== FALSE) $dataFound = true; |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | if (isset($line['mmsi']) && $line['mmsi'] != '' && $line['mmsi'] != $this->all_tracked[$id]['mmsi']) { |
| 138 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi' => $line['mmsi'])); |
|
| 138 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('mmsi' => $line['mmsi'])); |
|
| 139 | 139 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 140 | 140 | $Marine = new Marine($this->db); |
| 141 | 141 | $identity = $Marine->getIdentity($line['mmsi']); |
@@ -149,63 +149,63 @@ discard block |
||
| 149 | 149 | } |
| 150 | 150 | } |
| 151 | 151 | if (isset($line['type_id']) && $line['type_id'] != '') { |
| 152 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $AIS->getShipType($line['type_id']))); |
|
| 152 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('type' => $AIS->getShipType($line['type_id']))); |
|
| 153 | 153 | } |
| 154 | 154 | if (isset($line['type']) && $line['type'] != '') { |
| 155 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type'])); |
|
| 155 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('type' => $line['type'])); |
|
| 156 | 156 | } |
| 157 | 157 | if (isset($line['imo']) && $line['imo'] != '') { |
| 158 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('imo' => $line['imo'])); |
|
| 158 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('imo' => $line['imo'])); |
|
| 159 | 159 | } |
| 160 | 160 | if (isset($line['callsign']) && $line['callsign'] != '') { |
| 161 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('callsign' => $line['callsign'])); |
|
| 161 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('callsign' => $line['callsign'])); |
|
| 162 | 162 | } |
| 163 | 163 | if (isset($line['arrival_code']) && $line['arrival_code'] != '') { |
| 164 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_code' => $line['arrival_code'])); |
|
| 164 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('arrival_code' => $line['arrival_code'])); |
|
| 165 | 165 | } |
| 166 | 166 | if (isset($line['arrival_date']) && $line['arrival_date'] != '') { |
| 167 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date'])); |
|
| 167 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('arrival_date' => $line['arrival_date'])); |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | |
| 171 | 171 | //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'])) { |
| 172 | 172 | if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_tracked[$id]['ident'] != trim($line['ident']))) { |
| 173 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident']))); |
|
| 173 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('ident' => trim($line['ident']))); |
|
| 174 | 174 | if ($this->all_tracked[$id]['addedMarine'] == 1) { |
| 175 | 175 | if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
| 176 | 176 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 177 | 177 | $timeelapsed = microtime(true); |
| 178 | 178 | $Marine = new Marine($this->db); |
| 179 | 179 | $fromsource = NULL; |
| 180 | - $result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource); |
|
| 180 | + $result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $fromsource); |
|
| 181 | 181 | if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
| 182 | 182 | $Marine->db = null; |
| 183 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 183 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
| 184 | 184 | } |
| 185 | 185 | } |
| 186 | 186 | } |
| 187 | - if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident'])); |
|
| 187 | + if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('id' => $this->all_tracked[$id]['ident'])); |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | if (isset($line['speed']) && $line['speed'] != '') { |
| 191 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed']))); |
|
| 192 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true)); |
|
| 191 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('speed' => round($line['speed']))); |
|
| 192 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('speed_fromsrc' => true)); |
|
| 193 | 193 | } 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'])) { |
| 194 | - $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m'); |
|
| 194 | + $distance = $Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm'); |
|
| 195 | 195 | if ($distance > 1000 && $distance < 10000) { |
| 196 | 196 | $speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']); |
| 197 | 197 | $speed = $speed*3.6; |
| 198 | - if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed))); |
|
| 198 | + if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('speed' => round($speed))); |
|
| 199 | 199 | if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n"; |
| 200 | 200 | } |
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) { |
| 204 | - if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']); |
|
| 204 | + if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time() - $this->all_tracked[$id]['time_last_coord']); |
|
| 205 | 205 | else unset($timediff); |
| 206 | - 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')))) { |
|
| 206 | + 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')))) { |
|
| 207 | 207 | 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'])) { |
| 208 | - 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'])) { |
|
| 208 | + 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'])) { |
|
| 209 | 209 | $this->all_tracked[$id]['archive_latitude'] = $line['latitude']; |
| 210 | 210 | $this->all_tracked[$id]['archive_longitude'] = $line['longitude']; |
| 211 | 211 | $this->all_tracked[$id]['putinarchive'] = true; |
@@ -214,10 +214,10 @@ discard block |
||
| 214 | 214 | $timeelapsed = microtime(true); |
| 215 | 215 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 216 | 216 | $Marine = new Marine($this->db); |
| 217 | - $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']); |
|
| 217 | + $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'], $line['longitude']); |
|
| 218 | 218 | if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2']; |
| 219 | 219 | $Marine->db = null; |
| 220 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 220 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
| 221 | 221 | } |
| 222 | 222 | $this->tmd = 0; |
| 223 | 223 | if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n"; |
@@ -226,66 +226,66 @@ discard block |
||
| 226 | 226 | |
| 227 | 227 | if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) { |
| 228 | 228 | if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude']; |
| 229 | - 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') { |
|
| 229 | + 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') { |
|
| 230 | 230 | $this->all_tracked[$id]['livedb_latitude'] = $line['latitude']; |
| 231 | 231 | $dataFound = true; |
| 232 | 232 | $this->all_tracked[$id]['time_last_coord'] = time(); |
| 233 | 233 | } |
| 234 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude'])); |
|
| 234 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('latitude' => $line['latitude'])); |
|
| 235 | 235 | } |
| 236 | 236 | if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) { |
| 237 | 237 | if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360; |
| 238 | 238 | if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude']; |
| 239 | - 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') { |
|
| 239 | + 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') { |
|
| 240 | 240 | $this->all_tracked[$id]['livedb_longitude'] = $line['longitude']; |
| 241 | 241 | $dataFound = true; |
| 242 | 242 | $this->all_tracked[$id]['time_last_coord'] = time(); |
| 243 | 243 | } |
| 244 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('longitude' => $line['longitude'])); |
|
| 244 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('longitude' => $line['longitude'])); |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | } else if ($globalDebug && $timediff > 20) { |
| 248 | 248 | $this->tmd = $this->tmd + 1; |
| 249 | 249 | echo '!!! Too much distance in short time... for '.$this->all_tracked[$id]['ident']."\n"; |
| 250 | - echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')."m -"; |
|
| 251 | - echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')/$timediff)*3.6)." km/h - "; |
|
| 250 | + echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm')."m -"; |
|
| 251 | + echo 'Speed : '.(($Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm')/$timediff)*3.6)." km/h - "; |
|
| 252 | 252 | echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_tracked[$id]['latitude'].' - prev long : '.$this->all_tracked[$id]['longitude']." \n"; |
| 253 | 253 | } |
| 254 | 254 | } |
| 255 | 255 | if (isset($line['last_update']) && $line['last_update'] != '') { |
| 256 | 256 | if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true; |
| 257 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update'])); |
|
| 257 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('last_update' => $line['last_update'])); |
|
| 258 | 258 | } |
| 259 | 259 | if (isset($line['format_source']) && $line['format_source'] != '') { |
| 260 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source'])); |
|
| 260 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('format_source' => $line['format_source'])); |
|
| 261 | 261 | } |
| 262 | 262 | if (isset($line['source_name']) && $line['source_name'] != '') { |
| 263 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name'])); |
|
| 263 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('source_name' => $line['source_name'])); |
|
| 264 | 264 | } |
| 265 | 265 | if (isset($line['status']) && $line['status'] != '') { |
| 266 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status' => $line['status'])); |
|
| 266 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('status' => $line['status'])); |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | if (isset($line['noarchive']) && $line['noarchive'] === true) { |
| 270 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true)); |
|
| 270 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('noarchive' => true)); |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | if (isset($line['heading']) && $line['heading'] != '') { |
| 274 | - if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true; |
|
| 275 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading']))); |
|
| 276 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true)); |
|
| 274 | + if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading'] - round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true; |
|
| 275 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('heading' => round($line['heading']))); |
|
| 276 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('heading_fromsrc' => true)); |
|
| 277 | 277 | //$dataFound = true; |
| 278 | 278 | } 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']) { |
| 279 | - $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']); |
|
| 280 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading))); |
|
| 281 | - if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true; |
|
| 279 | + $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']); |
|
| 280 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('heading' => round($heading))); |
|
| 281 | + if (abs($this->all_tracked[$id]['heading'] - round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true; |
|
| 282 | 282 | if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n"; |
| 283 | 283 | } |
| 284 | 284 | //if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false; |
| 285 | 285 | |
| 286 | 286 | if (isset($line['datetime'])) { |
| 287 | 287 | if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) { |
| 288 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime'])); |
|
| 288 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('datetime' => $line['datetime'])); |
|
| 289 | 289 | } else { |
| 290 | 290 | 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"; |
| 291 | 291 | 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"; |
@@ -293,14 +293,14 @@ discard block |
||
| 293 | 293 | } |
| 294 | 294 | } else { |
| 295 | 295 | date_default_timezone_set('UTC'); |
| 296 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => date('Y-m-d H:i:s'))); |
|
| 296 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('datetime' => date('Y-m-d H:i:s'))); |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | |
| 300 | 300 | if ($dataFound === true && isset($this->all_tracked[$id]['mmsi'])) { |
| 301 | 301 | $this->all_tracked[$id]['lastupdate'] = time(); |
| 302 | 302 | if ($this->all_tracked[$id]['addedMarine'] == 0) { |
| 303 | - 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'])) { |
|
| 303 | + 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'])) { |
|
| 304 | 304 | if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) { |
| 305 | 305 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 306 | 306 | if ($globalDebug) echo "Check if aircraft is already in DB..."; |
@@ -308,37 +308,37 @@ discard block |
||
| 308 | 308 | $MarineLive = new MarineLive($this->db); |
| 309 | 309 | if (isset($line['id'])) { |
| 310 | 310 | $recent_ident = $MarineLive->checkIdRecent($line['id']); |
| 311 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 311 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
| 312 | 312 | } elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') { |
| 313 | 313 | $recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']); |
| 314 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 314 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
| 315 | 315 | } elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') { |
| 316 | 316 | $recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']); |
| 317 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 317 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
| 318 | 318 | } else $recent_ident = ''; |
| 319 | - $MarineLive->db=null; |
|
| 319 | + $MarineLive->db = null; |
|
| 320 | 320 | if ($globalDebug && $recent_ident == '') echo " Not in DB.\n"; |
| 321 | 321 | elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n"; |
| 322 | 322 | } else $recent_ident = ''; |
| 323 | 323 | } else { |
| 324 | 324 | $recent_ident = ''; |
| 325 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0)); |
|
| 325 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('forcenew' => 0)); |
|
| 326 | 326 | } |
| 327 | 327 | //if there was no aircraft with the same callsign within the last hour and go post it into the archive |
| 328 | - if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') |
|
| 328 | + if ($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') |
|
| 329 | 329 | { |
| 330 | 330 | if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : "; |
| 331 | 331 | //adds the spotter data for the archive |
| 332 | 332 | $highlight = ''; |
| 333 | - 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'))); |
|
| 333 | + 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'))); |
|
| 334 | 334 | if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
| 335 | 335 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 336 | 336 | $timeelapsed = microtime(true); |
| 337 | 337 | $Marine = new Marine($this->db); |
| 338 | - $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]['format_source'],$this->all_tracked[$id]['source_name']); |
|
| 338 | + $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]['format_source'], $this->all_tracked[$id]['source_name']); |
|
| 339 | 339 | $Marine->db = null; |
| 340 | 340 | if ($globalDebug && isset($result)) echo $result."\n"; |
| 341 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 341 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
| 342 | 342 | } |
| 343 | 343 | } |
| 344 | 344 | /* |
@@ -378,7 +378,7 @@ discard block |
||
| 378 | 378 | if (!isset($globaNoDB) || $globalNoDB !== TRUE) { |
| 379 | 379 | $MarineLive = new MarineLive($this->db); |
| 380 | 380 | $MarineLive->deleteLiveMarineData(); |
| 381 | - $MarineLive->db=null; |
|
| 381 | + $MarineLive->db = null; |
|
| 382 | 382 | if ($globalDebug) echo " Done\n"; |
| 383 | 383 | } |
| 384 | 384 | $this->last_delete = time(); |
@@ -389,7 +389,7 @@ discard block |
||
| 389 | 389 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 390 | 390 | if (isset($globalDaemon) && !$globalDaemon) { |
| 391 | 391 | $Marine = new Marine($this->db); |
| 392 | - $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']); |
|
| 392 | + $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']); |
|
| 393 | 393 | $Marine->db = null; |
| 394 | 394 | } |
| 395 | 395 | } |
@@ -404,22 +404,22 @@ discard block |
||
| 404 | 404 | $ignoreImport = false; |
| 405 | 405 | |
| 406 | 406 | if (!$ignoreImport) { |
| 407 | - 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'])) { |
|
| 407 | + 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'])) { |
|
| 408 | 408 | if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : "; |
| 409 | 409 | if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
| 410 | 410 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 411 | 411 | $timeelapsed = microtime(true); |
| 412 | 412 | $MarineLive = new MarineLive($this->db); |
| 413 | - $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]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country']); |
|
| 413 | + $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]['noarchive'], $this->all_tracked[$id]['format_source'], $this->all_tracked[$id]['source_name'], $this->all_tracked[$id]['over_country']); |
|
| 414 | 414 | $MarineLive->db = null; |
| 415 | 415 | if ($globalDebug) echo $result."\n"; |
| 416 | 416 | } |
| 417 | 417 | } |
| 418 | 418 | if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_flights[$id]['putinarchive']) { |
| 419 | - $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]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country']); |
|
| 419 | + $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]['noarchive'], $this->all_tracked[$id]['format_source'], $this->all_tracked[$id]['source_name'], $this->all_tracked[$id]['over_country']); |
|
| 420 | 420 | } |
| 421 | 421 | $this->all_tracked[$id]['putinarchive'] = false; |
| 422 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 422 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
| 423 | 423 | |
| 424 | 424 | // Put statistics in $this->stats variable |
| 425 | 425 | /* |
@@ -477,7 +477,7 @@ discard block |
||
| 477 | 477 | |
| 478 | 478 | $this->all_tracked[$id]['lastupdate'] = time(); |
| 479 | 479 | if ($this->all_tracked[$id]['putinarchive']) $send = true; |
| 480 | - } 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"; |
|
| 480 | + } 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"; |
|
| 481 | 481 | //$this->del(); |
| 482 | 482 | |
| 483 | 483 | |
@@ -53,7 +53,9 @@ discard block |
||
| 53 | 53 | |
| 54 | 54 | public function checkAll() { |
| 55 | 55 | global $globalDebug; |
| 56 | - if ($globalDebug) echo "Update last seen tracked data...\n"; |
|
| 56 | + if ($globalDebug) { |
|
| 57 | + echo "Update last seen tracked data...\n"; |
|
| 58 | + } |
|
| 57 | 59 | foreach ($this->all_tracked as $key => $flight) { |
| 58 | 60 | if (isset($this->all_tracked[$key]['id'])) { |
| 59 | 61 | //echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].' '.$this->all_tracked[$key]['longitude']."\n"; |
@@ -66,12 +68,16 @@ discard block |
||
| 66 | 68 | public function del() { |
| 67 | 69 | global $globalDebug; |
| 68 | 70 | // Delete old infos |
| 69 | - if ($globalDebug) echo 'Delete old values and update latest data...'."\n"; |
|
| 71 | + if ($globalDebug) { |
|
| 72 | + echo 'Delete old values and update latest data...'."\n"; |
|
| 73 | + } |
|
| 70 | 74 | foreach ($this->all_tracked as $key => $flight) { |
| 71 | 75 | if (isset($flight['lastupdate'])) { |
| 72 | 76 | if ($flight['lastupdate'] < (time()-3000)) { |
| 73 | 77 | if (isset($this->all_tracked[$key]['id'])) { |
| 74 | - if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n"; |
|
| 78 | + if ($globalDebug) { |
|
| 79 | + echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n"; |
|
| 80 | + } |
|
| 75 | 81 | /* |
| 76 | 82 | $MarineLive = new MarineLive(); |
| 77 | 83 | $MarineLive->deleteLiveMarineDataById($this->all_tracked[$key]['id']); |
@@ -81,7 +87,9 @@ discard block |
||
| 81 | 87 | $Marine = new Marine($this->db); |
| 82 | 88 | if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') { |
| 83 | 89 | $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']); |
| 84 | - if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
|
| 90 | + if ($globalDebug && $result != 'success') { |
|
| 91 | + echo '!!! ERROR : '.$result."\n"; |
|
| 92 | + } |
|
| 85 | 93 | } |
| 86 | 94 | // Put in archive |
| 87 | 95 | // $Marine->db = null; |
@@ -94,7 +102,9 @@ discard block |
||
| 94 | 102 | |
| 95 | 103 | public function add($line) { |
| 96 | 104 | global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked, $globalNoImport, $globalNoDB; |
| 97 | - if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02'; |
|
| 105 | + if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') { |
|
| 106 | + $globalCoordMinChange = '0.02'; |
|
| 107 | + } |
|
| 98 | 108 | date_default_timezone_set('UTC'); |
| 99 | 109 | $dataFound = false; |
| 100 | 110 | $send = false; |
@@ -119,8 +129,11 @@ discard block |
||
| 119 | 129 | |
| 120 | 130 | $Common = new Common(); |
| 121 | 131 | $AIS = new AIS(); |
| 122 | - if (!isset($line['id'])) $id = trim($line['mmsi']); |
|
| 123 | - else $id = trim($line['id']); |
|
| 132 | + if (!isset($line['id'])) { |
|
| 133 | + $id = trim($line['mmsi']); |
|
| 134 | + } else { |
|
| 135 | + $id = trim($line['id']); |
|
| 136 | + } |
|
| 124 | 137 | |
| 125 | 138 | if (!isset($this->all_tracked[$id])) { |
| 126 | 139 | $this->all_tracked[$id] = array(); |
@@ -128,10 +141,16 @@ discard block |
||
| 128 | 141 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','typeid' => '','noarchive' => false,'putinarchive' => true,'over_country' => '','mmsi' => '','status' => '','imo' => '','callsign' => '','arrival_code' => '','arrival_date' => '')); |
| 129 | 142 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time())); |
| 130 | 143 | if (!isset($line['id'])) { |
| 131 | - if (!isset($globalDaemon)) $globalDaemon = TRUE; |
|
| 144 | + if (!isset($globalDaemon)) { |
|
| 145 | + $globalDaemon = TRUE; |
|
| 146 | + } |
|
| 132 | 147 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $id.'-'.date('YmdHi'))); |
| 133 | - } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id'])); |
|
| 134 | - if ($globalAllTracked !== FALSE) $dataFound = true; |
|
| 148 | + } else { |
|
| 149 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id'])); |
|
| 150 | + } |
|
| 151 | + if ($globalAllTracked !== FALSE) { |
|
| 152 | + $dataFound = true; |
|
| 153 | + } |
|
| 135 | 154 | } |
| 136 | 155 | |
| 137 | 156 | if (isset($line['mmsi']) && $line['mmsi'] != '' && $line['mmsi'] != $this->all_tracked[$id]['mmsi']) { |
@@ -178,13 +197,19 @@ discard block |
||
| 178 | 197 | $Marine = new Marine($this->db); |
| 179 | 198 | $fromsource = NULL; |
| 180 | 199 | $result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource); |
| 181 | - if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
|
| 200 | + if ($globalDebug && $result != 'success') { |
|
| 201 | + echo '!!! ERROR : '.$result."\n"; |
|
| 202 | + } |
|
| 182 | 203 | $Marine->db = null; |
| 183 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 204 | + if ($globalDebugTimeElapsed) { |
|
| 205 | + echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 206 | + } |
|
| 184 | 207 | } |
| 185 | 208 | } |
| 186 | 209 | } |
| 187 | - if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident'])); |
|
| 210 | + if (!isset($this->all_tracked[$id]['id'])) { |
|
| 211 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident'])); |
|
| 212 | + } |
|
| 188 | 213 | } |
| 189 | 214 | |
| 190 | 215 | if (isset($line['speed']) && $line['speed'] != '') { |
@@ -195,14 +220,21 @@ discard block |
||
| 195 | 220 | if ($distance > 1000 && $distance < 10000) { |
| 196 | 221 | $speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']); |
| 197 | 222 | $speed = $speed*3.6; |
| 198 | - if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed))); |
|
| 199 | - if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n"; |
|
| 223 | + if ($speed < 1000) { |
|
| 224 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed))); |
|
| 225 | + } |
|
| 226 | + if ($globalDebug) { |
|
| 227 | + echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n"; |
|
| 228 | + } |
|
| 200 | 229 | } |
| 201 | 230 | } |
| 202 | 231 | |
| 203 | 232 | if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) { |
| 204 | - if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']); |
|
| 205 | - else unset($timediff); |
|
| 233 | + if (isset($this->all_tracked[$id]['time_last_coord'])) { |
|
| 234 | + $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']); |
|
| 235 | + } else { |
|
| 236 | + unset($timediff); |
|
| 237 | + } |
|
| 206 | 238 | 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')))) { |
| 207 | 239 | 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'])) { |
| 208 | 240 | 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'])) { |
@@ -210,22 +242,32 @@ discard block |
||
| 210 | 242 | $this->all_tracked[$id]['archive_longitude'] = $line['longitude']; |
| 211 | 243 | $this->all_tracked[$id]['putinarchive'] = true; |
| 212 | 244 | |
| 213 | - if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... '; |
|
| 245 | + if ($globalDebug) { |
|
| 246 | + echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... '; |
|
| 247 | + } |
|
| 214 | 248 | $timeelapsed = microtime(true); |
| 215 | 249 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 216 | 250 | $Marine = new Marine($this->db); |
| 217 | 251 | $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']); |
| 218 | - if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2']; |
|
| 252 | + if (!empty($all_country)) { |
|
| 253 | + $this->all_tracked[$id]['over_country'] = $all_country['iso2']; |
|
| 254 | + } |
|
| 219 | 255 | $Marine->db = null; |
| 220 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 256 | + if ($globalDebugTimeElapsed) { |
|
| 257 | + echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 258 | + } |
|
| 221 | 259 | } |
| 222 | 260 | $this->tmd = 0; |
| 223 | - if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n"; |
|
| 261 | + if ($globalDebug) { |
|
| 262 | + echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n"; |
|
| 263 | + } |
|
| 224 | 264 | } |
| 225 | 265 | } |
| 226 | 266 | |
| 227 | 267 | if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) { |
| 228 | - if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude']; |
|
| 268 | + if (!isset($this->all_tracked[$id]['archive_latitude'])) { |
|
| 269 | + $this->all_tracked[$id]['archive_latitude'] = $line['latitude']; |
|
| 270 | + } |
|
| 229 | 271 | 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') { |
| 230 | 272 | $this->all_tracked[$id]['livedb_latitude'] = $line['latitude']; |
| 231 | 273 | $dataFound = true; |
@@ -234,8 +276,12 @@ discard block |
||
| 234 | 276 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude'])); |
| 235 | 277 | } |
| 236 | 278 | if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) { |
| 237 | - if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360; |
|
| 238 | - if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude']; |
|
| 279 | + if ($line['longitude'] > 180) { |
|
| 280 | + $line['longitude'] = $line['longitude'] - 360; |
|
| 281 | + } |
|
| 282 | + if (!isset($this->all_tracked[$id]['archive_longitude'])) { |
|
| 283 | + $this->all_tracked[$id]['archive_longitude'] = $line['longitude']; |
|
| 284 | + } |
|
| 239 | 285 | 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') { |
| 240 | 286 | $this->all_tracked[$id]['livedb_longitude'] = $line['longitude']; |
| 241 | 287 | $dataFound = true; |
@@ -253,7 +299,9 @@ discard block |
||
| 253 | 299 | } |
| 254 | 300 | } |
| 255 | 301 | if (isset($line['last_update']) && $line['last_update'] != '') { |
| 256 | - if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true; |
|
| 302 | + if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) { |
|
| 303 | + $dataFound = true; |
|
| 304 | + } |
|
| 257 | 305 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update'])); |
| 258 | 306 | } |
| 259 | 307 | if (isset($line['format_source']) && $line['format_source'] != '') { |
@@ -271,15 +319,21 @@ discard block |
||
| 271 | 319 | } |
| 272 | 320 | |
| 273 | 321 | if (isset($line['heading']) && $line['heading'] != '') { |
| 274 | - if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true; |
|
| 322 | + if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) { |
|
| 323 | + $this->all_tracked[$id]['putinarchive'] = true; |
|
| 324 | + } |
|
| 275 | 325 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading']))); |
| 276 | 326 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true)); |
| 277 | 327 | //$dataFound = true; |
| 278 | 328 | } 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']) { |
| 279 | 329 | $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']); |
| 280 | 330 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading))); |
| 281 | - if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true; |
|
| 282 | - if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n"; |
|
| 331 | + if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) { |
|
| 332 | + $this->all_tracked[$id]['putinarchive'] = true; |
|
| 333 | + } |
|
| 334 | + if ($globalDebug) { |
|
| 335 | + echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n"; |
|
| 336 | + } |
|
| 283 | 337 | } |
| 284 | 338 | //if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false; |
| 285 | 339 | |
@@ -287,8 +341,11 @@ discard block |
||
| 287 | 341 | if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) { |
| 288 | 342 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime'])); |
| 289 | 343 | } else { |
| 290 | - 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"; |
|
| 291 | - 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"; |
|
| 344 | + if (strtotime($line['datetime']) == strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) { |
|
| 345 | + echo "!!! Date is the same as previous data for ".$this->all_tracked[$id]['mmsi']."\n"; |
|
| 346 | + } elseif (strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) { |
|
| 347 | + echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_tracked[$id]['datetime'].") !!! for ".$this->all_tracked[$id]['hex']." - format : ".$line['format_source']."\n"; |
|
| 348 | + } |
|
| 292 | 349 | return ''; |
| 293 | 350 | } |
| 294 | 351 | } else { |
@@ -303,23 +360,38 @@ discard block |
||
| 303 | 360 | 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'])) { |
| 304 | 361 | if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) { |
| 305 | 362 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 306 | - if ($globalDebug) echo "Check if aircraft is already in DB..."; |
|
| 363 | + if ($globalDebug) { |
|
| 364 | + echo "Check if aircraft is already in DB..."; |
|
| 365 | + } |
|
| 307 | 366 | $timeelapsed = microtime(true); |
| 308 | 367 | $MarineLive = new MarineLive($this->db); |
| 309 | 368 | if (isset($line['id'])) { |
| 310 | 369 | $recent_ident = $MarineLive->checkIdRecent($line['id']); |
| 311 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 370 | + if ($globalDebugTimeElapsed) { |
|
| 371 | + echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 372 | + } |
|
| 312 | 373 | } elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') { |
| 313 | 374 | $recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']); |
| 314 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 375 | + if ($globalDebugTimeElapsed) { |
|
| 376 | + echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 377 | + } |
|
| 315 | 378 | } elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') { |
| 316 | 379 | $recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']); |
| 317 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 318 | - } else $recent_ident = ''; |
|
| 380 | + if ($globalDebugTimeElapsed) { |
|
| 381 | + echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 382 | + } |
|
| 383 | + } else { |
|
| 384 | + $recent_ident = ''; |
|
| 385 | + } |
|
| 319 | 386 | $MarineLive->db=null; |
| 320 | - if ($globalDebug && $recent_ident == '') echo " Not in DB.\n"; |
|
| 321 | - elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n"; |
|
| 322 | - } else $recent_ident = ''; |
|
| 387 | + if ($globalDebug && $recent_ident == '') { |
|
| 388 | + echo " Not in DB.\n"; |
|
| 389 | + } elseif ($globalDebug && $recent_ident != '') { |
|
| 390 | + echo " Already in DB.\n"; |
|
| 391 | + } |
|
| 392 | + } else { |
|
| 393 | + $recent_ident = ''; |
|
| 394 | + } |
|
| 323 | 395 | } else { |
| 324 | 396 | $recent_ident = ''; |
| 325 | 397 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0)); |
@@ -327,18 +399,26 @@ discard block |
||
| 327 | 399 | //if there was no aircraft with the same callsign within the last hour and go post it into the archive |
| 328 | 400 | if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') |
| 329 | 401 | { |
| 330 | - if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : "; |
|
| 402 | + if ($globalDebug) { |
|
| 403 | + echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : "; |
|
| 404 | + } |
|
| 331 | 405 | //adds the spotter data for the archive |
| 332 | 406 | $highlight = ''; |
| 333 | - 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'))); |
|
| 407 | + if (!isset($this->all_tracked[$id]['id'])) { |
|
| 408 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi'))); |
|
| 409 | + } |
|
| 334 | 410 | if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
| 335 | 411 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 336 | 412 | $timeelapsed = microtime(true); |
| 337 | 413 | $Marine = new Marine($this->db); |
| 338 | 414 | $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]['format_source'],$this->all_tracked[$id]['source_name']); |
| 339 | 415 | $Marine->db = null; |
| 340 | - if ($globalDebug && isset($result)) echo $result."\n"; |
|
| 341 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 416 | + if ($globalDebug && isset($result)) { |
|
| 417 | + echo $result."\n"; |
|
| 418 | + } |
|
| 419 | + if ($globalDebugTimeElapsed) { |
|
| 420 | + echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 421 | + } |
|
| 342 | 422 | } |
| 343 | 423 | } |
| 344 | 424 | /* |
@@ -373,13 +453,17 @@ discard block |
||
| 373 | 453 | $this->all_tracked[$id]['addedMarine'] = 1; |
| 374 | 454 | //print_r($this->all_tracked[$id]); |
| 375 | 455 | if ($this->last_delete == 0 || time() - $this->last_delete > 1800) { |
| 376 | - if ($globalDebug) echo "---- Deleting Live Marine data older than 9 hours..."; |
|
| 456 | + if ($globalDebug) { |
|
| 457 | + echo "---- Deleting Live Marine data older than 9 hours..."; |
|
| 458 | + } |
|
| 377 | 459 | //MarineLive->deleteLiveMarineDataNotUpdated(); |
| 378 | 460 | if (!isset($globaNoDB) || $globalNoDB !== TRUE) { |
| 379 | 461 | $MarineLive = new MarineLive($this->db); |
| 380 | 462 | $MarineLive->deleteLiveMarineData(); |
| 381 | 463 | $MarineLive->db=null; |
| 382 | - if ($globalDebug) echo " Done\n"; |
|
| 464 | + if ($globalDebug) { |
|
| 465 | + echo " Done\n"; |
|
| 466 | + } |
|
| 383 | 467 | } |
| 384 | 468 | $this->last_delete = time(); |
| 385 | 469 | } |
@@ -405,21 +489,27 @@ discard block |
||
| 405 | 489 | |
| 406 | 490 | if (!$ignoreImport) { |
| 407 | 491 | 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'])) { |
| 408 | - if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : "; |
|
| 492 | + if ($globalDebug) { |
|
| 493 | + echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : "; |
|
| 494 | + } |
|
| 409 | 495 | if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
| 410 | 496 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 411 | 497 | $timeelapsed = microtime(true); |
| 412 | 498 | $MarineLive = new MarineLive($this->db); |
| 413 | 499 | $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]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country']); |
| 414 | 500 | $MarineLive->db = null; |
| 415 | - if ($globalDebug) echo $result."\n"; |
|
| 501 | + if ($globalDebug) { |
|
| 502 | + echo $result."\n"; |
|
| 503 | + } |
|
| 416 | 504 | } |
| 417 | 505 | } |
| 418 | 506 | if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_flights[$id]['putinarchive']) { |
| 419 | 507 | $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]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country']); |
| 420 | 508 | } |
| 421 | 509 | $this->all_tracked[$id]['putinarchive'] = false; |
| 422 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 510 | + if ($globalDebugTimeElapsed) { |
|
| 511 | + echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 512 | + } |
|
| 423 | 513 | |
| 424 | 514 | // Put statistics in $this->stats variable |
| 425 | 515 | /* |
@@ -476,19 +566,27 @@ discard block |
||
| 476 | 566 | */ |
| 477 | 567 | |
| 478 | 568 | $this->all_tracked[$id]['lastupdate'] = time(); |
| 479 | - if ($this->all_tracked[$id]['putinarchive']) $send = true; |
|
| 480 | - } 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"; |
|
| 569 | + if ($this->all_tracked[$id]['putinarchive']) { |
|
| 570 | + $send = true; |
|
| 571 | + } |
|
| 572 | + } elseif (isset($this->all_tracked[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) { |
|
| 573 | + echo "!! Too far -> Distance : ".$Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n"; |
|
| 574 | + } |
|
| 481 | 575 | //$this->del(); |
| 482 | 576 | |
| 483 | 577 | |
| 484 | 578 | if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) { |
| 485 | 579 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 486 | - if ($globalDebug) echo "---- Deleting Live Marine data Not updated since 2 hour..."; |
|
| 580 | + if ($globalDebug) { |
|
| 581 | + echo "---- Deleting Live Marine data Not updated since 2 hour..."; |
|
| 582 | + } |
|
| 487 | 583 | $MarineLive = new MarineLive($this->db); |
| 488 | 584 | $MarineLive->deleteLiveMarineDataNotUpdated(); |
| 489 | 585 | $MarineLive->db = null; |
| 490 | 586 | //MarineLive->deleteLiveMarineData(); |
| 491 | - if ($globalDebug) echo " Done\n"; |
|
| 587 | + if ($globalDebug) { |
|
| 588 | + echo " Done\n"; |
|
| 589 | + } |
|
| 492 | 590 | } |
| 493 | 591 | $this->last_delete_hourly = time(); |
| 494 | 592 | } |
@@ -497,7 +595,9 @@ discard block |
||
| 497 | 595 | //$ignoreImport = false; |
| 498 | 596 | } |
| 499 | 597 | //if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN); |
| 500 | - if ($send) return $this->all_tracked[$id]; |
|
| 598 | + if ($send) { |
|
| 599 | + return $this->all_tracked[$id]; |
|
| 600 | + } |
|
| 501 | 601 | } |
| 502 | 602 | } |
| 503 | 603 | } |