|
@@ -42,7 +42,9 @@ discard block |
|
|
block discarded – undo |
|
42
|
42
|
|
|
43
|
43
|
public function checkAll() { |
|
44
|
44
|
global $globalDebug; |
|
45
|
|
- if ($globalDebug) echo "Update last seen tracked data...\n"; |
|
|
45
|
+ if ($globalDebug) { |
|
|
46
|
+ echo "Update last seen tracked data...\n"; |
|
|
47
|
+ } |
|
46
|
48
|
foreach ($this->all_tracked as $key => $flight) { |
|
47
|
49
|
if (isset($this->all_tracked[$key]['id'])) { |
|
48
|
50
|
//echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].' '.$this->all_tracked[$key]['longitude']."\n"; |
|
@@ -55,12 +57,16 @@ discard block |
|
|
block discarded – undo |
|
55
|
57
|
public function del() { |
|
56
|
58
|
global $globalDebug; |
|
57
|
59
|
// Delete old infos |
|
58
|
|
- if ($globalDebug) echo 'Delete old values and update latest data...'."\n"; |
|
|
60
|
+ if ($globalDebug) { |
|
|
61
|
+ echo 'Delete old values and update latest data...'."\n"; |
|
|
62
|
+ } |
|
59
|
63
|
foreach ($this->all_tracked as $key => $flight) { |
|
60
|
64
|
if (isset($flight['lastupdate'])) { |
|
61
|
65
|
if ($flight['lastupdate'] < (time()-3000)) { |
|
62
|
66
|
if (isset($this->all_tracked[$key]['id'])) { |
|
63
|
|
- if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n"; |
|
|
67
|
+ if ($globalDebug) { |
|
|
68
|
+ echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n"; |
|
|
69
|
+ } |
|
64
|
70
|
/* |
|
65
|
71
|
$TrackerLive = new TrackerLive(); |
|
66
|
72
|
$TrackerLive->deleteLiveTrackerDataById($this->all_tracked[$key]['id']); |
|
@@ -70,7 +76,9 @@ discard block |
|
|
block discarded – undo |
|
70
|
76
|
$Tracker = new Tracker($this->db); |
|
71
|
77
|
if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') { |
|
72
|
78
|
$result = $Tracker->updateLatestTrackerData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['altitude'],$this->all_tracked[$key]['speed']); |
|
73
|
|
- if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
|
|
79
|
+ if ($globalDebug && $result != 'success') { |
|
|
80
|
+ echo '!!! ERROR : '.$result."\n"; |
|
|
81
|
+ } |
|
74
|
82
|
} |
|
75
|
83
|
// Put in archive |
|
76
|
84
|
// $Tracker->db = null; |
|
@@ -83,7 +91,9 @@ discard block |
|
|
block discarded – undo |
|
83
|
91
|
|
|
84
|
92
|
public function add($line) { |
|
85
|
93
|
global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChangeTracker, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked; |
|
86
|
|
- if (!isset($globalCoordMinChangeTracker) || $globalCoordMinChangeTracker == '') $globalCoordMinChangeTracker = '0.015'; |
|
|
94
|
+ if (!isset($globalCoordMinChangeTracker) || $globalCoordMinChangeTracker == '') { |
|
|
95
|
+ $globalCoordMinChangeTracker = '0.015'; |
|
|
96
|
+ } |
|
87
|
97
|
date_default_timezone_set('UTC'); |
|
88
|
98
|
$dataFound = false; |
|
89
|
99
|
$send = false; |
|
@@ -97,19 +107,29 @@ discard block |
|
|
block discarded – undo |
|
97
|
107
|
// Increment message number |
|
98
|
108
|
if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE) { |
|
99
|
109
|
$current_date = date('Y-m-d'); |
|
100
|
|
- if (isset($line['source_name'])) $source = $line['source_name']; |
|
101
|
|
- else $source = ''; |
|
102
|
|
- if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source']; |
|
|
110
|
+ if (isset($line['source_name'])) { |
|
|
111
|
+ $source = $line['source_name']; |
|
|
112
|
+ } else { |
|
|
113
|
+ $source = ''; |
|
|
114
|
+ } |
|
|
115
|
+ if ($source == '' || $line['format_source'] == 'aprs') { |
|
|
116
|
+ $source = $line['format_source']; |
|
|
117
|
+ } |
|
103
|
118
|
if (!isset($this->stats[$current_date][$source]['msg'])) { |
|
104
|
119
|
$this->stats[$current_date][$source]['msg']['date'] = time(); |
|
105
|
120
|
$this->stats[$current_date][$source]['msg']['nb'] = 1; |
|
106
|
|
- } else $this->stats[$current_date][$source]['msg']['nb'] += 1; |
|
|
121
|
+ } else { |
|
|
122
|
+ $this->stats[$current_date][$source]['msg']['nb'] += 1; |
|
|
123
|
+ } |
|
107
|
124
|
} |
|
108
|
125
|
|
|
109
|
126
|
|
|
110
|
127
|
$Common = new Common(); |
|
111
|
|
- if (!isset($line['id'])) $id = trim($line['ident']); |
|
112
|
|
- else $id = trim($line['id']); |
|
|
128
|
+ if (!isset($line['id'])) { |
|
|
129
|
+ $id = trim($line['ident']); |
|
|
130
|
+ } else { |
|
|
131
|
+ $id = trim($line['id']); |
|
|
132
|
+ } |
|
113
|
133
|
|
|
114
|
134
|
if (!isset($this->all_tracked[$id])) { |
|
115
|
135
|
$this->all_tracked[$id] = array(); |
|
@@ -117,31 +137,46 @@ discard block |
|
|
block discarded – undo |
|
117
|
137
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','noarchive' => false,'putinarchive' => true,'over_country' => '')); |
|
118
|
138
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time())); |
|
119
|
139
|
if (!isset($line['id'])) { |
|
120
|
|
- if (!isset($globalDaemon)) $globalDaemon = TRUE; |
|
|
140
|
+ if (!isset($globalDaemon)) { |
|
|
141
|
+ $globalDaemon = TRUE; |
|
|
142
|
+ } |
|
121
|
143
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $id.'-'.date('YmdHi'))); |
|
122
|
|
- } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id'])); |
|
123
|
|
- if ($globalAllTracked !== FALSE) $dataFound = true; |
|
|
144
|
+ } else { |
|
|
145
|
+ $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id'])); |
|
|
146
|
+ } |
|
|
147
|
+ if ($globalAllTracked !== FALSE) { |
|
|
148
|
+ $dataFound = true; |
|
|
149
|
+ } |
|
124
|
150
|
} |
|
125
|
151
|
|
|
126
|
152
|
if (isset($line['datetime']) && strtotime($line['datetime']) > time()-20*60 && strtotime($line['datetime']) < time()+20*60) { |
|
127
|
153
|
if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_tracked[$id]['datetime'])) { |
|
128
|
154
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime'])); |
|
129
|
155
|
} else { |
|
130
|
|
- if (strtotime($line['datetime']) == strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_tracked[$id]['ident']." - format : ".$line['format_source']."\n"; |
|
131
|
|
- 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]['ident']." - format : ".$line['format_source']."\n"; |
|
|
156
|
+ if (strtotime($line['datetime']) == strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) { |
|
|
157
|
+ echo "!!! Date is the same as previous data for ".$this->all_tracked[$id]['ident']." - format : ".$line['format_source']."\n"; |
|
|
158
|
+ } elseif (strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) { |
|
|
159
|
+ echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_tracked[$id]['datetime'].") !!! for ".$this->all_tracked[$id]['ident']." - format : ".$line['format_source']."\n"; |
|
|
160
|
+ } |
|
132
|
161
|
return ''; |
|
133
|
162
|
} |
|
134
|
163
|
} elseif (isset($line['datetime']) && strtotime($line['datetime']) < time()-20*60) { |
|
135
|
|
- if ($globalDebug) echo "!!! Date is too old ".$this->all_tracked[$id]['ident']." - format : ".$line['format_source']."!!!\n"; |
|
|
164
|
+ if ($globalDebug) { |
|
|
165
|
+ echo "!!! Date is too old ".$this->all_tracked[$id]['ident']." - format : ".$line['format_source']."!!!\n"; |
|
|
166
|
+ } |
|
136
|
167
|
return ''; |
|
137
|
168
|
} elseif (isset($line['datetime']) && strtotime($line['datetime']) > time()+20*60) { |
|
138
|
|
- if ($globalDebug) echo "!!! Date is in the future ".$this->all_tracked[$id]['ident']." - format : ".$line['format_source']."!!!\n"; |
|
|
169
|
+ if ($globalDebug) { |
|
|
170
|
+ echo "!!! Date is in the future ".$this->all_tracked[$id]['ident']." - format : ".$line['format_source']."!!!\n"; |
|
|
171
|
+ } |
|
139
|
172
|
return ''; |
|
140
|
173
|
} elseif (!isset($line['datetime'])) { |
|
141
|
174
|
date_default_timezone_set('UTC'); |
|
142
|
175
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => date('Y-m-d H:i:s'))); |
|
143
|
176
|
} else { |
|
144
|
|
- if ($globalDebug) echo "!!! Unknow date error ".$this->all_tracked[$id]['ident']." - format : ".$line['format_source']."!!!\n"; |
|
|
177
|
+ if ($globalDebug) { |
|
|
178
|
+ echo "!!! Unknow date error ".$this->all_tracked[$id]['ident']." - format : ".$line['format_source']."!!!\n"; |
|
|
179
|
+ } |
|
145
|
180
|
return ''; |
|
146
|
181
|
} |
|
147
|
182
|
|
|
@@ -153,11 +188,17 @@ discard block |
|
|
block discarded – undo |
|
153
|
188
|
$Tracker = new Tracker($this->db); |
|
154
|
189
|
$fromsource = NULL; |
|
155
|
190
|
$result = $Tracker->updateIdentTrackerData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource); |
|
156
|
|
- if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
|
|
191
|
+ if ($globalDebug && $result != 'success') { |
|
|
192
|
+ echo '!!! ERROR : '.$result."\n"; |
|
|
193
|
+ } |
|
157
|
194
|
$Tracker->db = null; |
|
158
|
|
- if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
|
195
|
+ if ($globalDebugTimeElapsed) { |
|
|
196
|
+ echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
|
197
|
+ } |
|
|
198
|
+ } |
|
|
199
|
+ if (!isset($this->all_tracked[$id]['id'])) { |
|
|
200
|
+ $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident'])); |
|
159
|
201
|
} |
|
160
|
|
- if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident'])); |
|
161
|
202
|
} |
|
162
|
203
|
|
|
163
|
204
|
if (isset($line['speed']) && $line['speed'] != '') { |
|
@@ -168,14 +209,21 @@ discard block |
|
|
block discarded – undo |
|
168
|
209
|
if ($distance > 100 && $distance < 10000) { |
|
169
|
210
|
$speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']); |
|
170
|
211
|
$speed = $speed*3.6; |
|
171
|
|
- if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed))); |
|
172
|
|
- if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['ident']." : ".$speed." - distance : ".$distance."\n"; |
|
|
212
|
+ if ($speed < 1000) { |
|
|
213
|
+ $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed))); |
|
|
214
|
+ } |
|
|
215
|
+ if ($globalDebug) { |
|
|
216
|
+ echo "ø Calculated Speed for ".$this->all_tracked[$id]['ident']." : ".$speed." - distance : ".$distance."\n"; |
|
|
217
|
+ } |
|
173
|
218
|
} |
|
174
|
219
|
} |
|
175
|
220
|
|
|
176
|
221
|
if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) { |
|
177
|
|
- if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']); |
|
178
|
|
- else unset($timediff); |
|
|
222
|
+ if (isset($this->all_tracked[$id]['time_last_coord'])) { |
|
|
223
|
+ $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']); |
|
|
224
|
+ } else { |
|
|
225
|
+ unset($timediff); |
|
|
226
|
+ } |
|
179
|
227
|
if ($this->tmd > 5 || !isset($timediff) || $timediff > 100 || ($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')))) { |
|
180
|
228
|
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'])) { |
|
181
|
229
|
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'],0.1)) { |
|
@@ -183,20 +231,30 @@ discard block |
|
|
block discarded – undo |
|
183
|
231
|
$this->all_tracked[$id]['archive_longitude'] = $line['longitude']; |
|
184
|
232
|
$this->all_tracked[$id]['putinarchive'] = true; |
|
185
|
233
|
|
|
186
|
|
- if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... '; |
|
|
234
|
+ if ($globalDebug) { |
|
|
235
|
+ echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... '; |
|
|
236
|
+ } |
|
187
|
237
|
$timeelapsed = microtime(true); |
|
188
|
238
|
$Tracker = new Tracker($this->db); |
|
189
|
239
|
$all_country = $Tracker->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']); |
|
190
|
|
- if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2']; |
|
|
240
|
+ if (!empty($all_country)) { |
|
|
241
|
+ $this->all_tracked[$id]['over_country'] = $all_country['iso2']; |
|
|
242
|
+ } |
|
191
|
243
|
$Tracker->db = null; |
|
192
|
|
- if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
|
244
|
+ if ($globalDebugTimeElapsed) { |
|
|
245
|
+ echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
|
246
|
+ } |
|
193
|
247
|
$this->tmd = 0; |
|
194
|
|
- if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n"; |
|
|
248
|
+ if ($globalDebug) { |
|
|
249
|
+ echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n"; |
|
|
250
|
+ } |
|
195
|
251
|
} |
|
196
|
252
|
} |
|
197
|
253
|
|
|
198
|
254
|
if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) { |
|
199
|
|
- if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude']; |
|
|
255
|
+ if (!isset($this->all_tracked[$id]['archive_latitude'])) { |
|
|
256
|
+ $this->all_tracked[$id]['archive_latitude'] = $line['latitude']; |
|
|
257
|
+ } |
|
200
|
258
|
if (!isset($this->all_tracked[$id]['livedb_latitude']) || abs($this->all_tracked[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChangeTracker || $this->all_tracked[$id]['format_source'] == 'aprs') { |
|
201
|
259
|
$this->all_tracked[$id]['livedb_latitude'] = $line['latitude']; |
|
202
|
260
|
$dataFound = true; |
|
@@ -205,8 +263,12 @@ discard block |
|
|
block discarded – undo |
|
205
|
263
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude'])); |
|
206
|
264
|
} |
|
207
|
265
|
if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) { |
|
208
|
|
- if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360; |
|
209
|
|
- if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude']; |
|
|
266
|
+ if ($line['longitude'] > 180) { |
|
|
267
|
+ $line['longitude'] = $line['longitude'] - 360; |
|
|
268
|
+ } |
|
|
269
|
+ if (!isset($this->all_tracked[$id]['archive_longitude'])) { |
|
|
270
|
+ $this->all_tracked[$id]['archive_longitude'] = $line['longitude']; |
|
|
271
|
+ } |
|
210
|
272
|
if (!isset($this->all_tracked[$id]['livedb_longitude']) || abs($this->all_tracked[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChangeTracker || $this->all_tracked[$id]['format_source'] == 'aprs') { |
|
211
|
273
|
$this->all_tracked[$id]['livedb_longitude'] = $line['longitude']; |
|
212
|
274
|
$dataFound = true; |
|
@@ -226,7 +288,9 @@ discard block |
|
|
block discarded – undo |
|
226
|
288
|
} |
|
227
|
289
|
} |
|
228
|
290
|
if (isset($line['last_update']) && $line['last_update'] != '') { |
|
229
|
|
- if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true; |
|
|
291
|
+ if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) { |
|
|
292
|
+ $dataFound = true; |
|
|
293
|
+ } |
|
230
|
294
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update'])); |
|
231
|
295
|
} |
|
232
|
296
|
if (isset($line['format_source']) && $line['format_source'] != '') { |
|
@@ -246,7 +310,9 @@ discard block |
|
|
block discarded – undo |
|
246
|
310
|
|
|
247
|
311
|
if (isset($line['altitude']) && $line['altitude'] != '') { |
|
248
|
312
|
//if (!isset($this->all_tracked[$id]['altitude']) || $this->all_tracked[$id]['altitude'] == '' || ($this->all_tracked[$id]['altitude'] > 0 && $line['altitude'] != 0)) { |
|
249
|
|
- if (is_int($this->all_tracked[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_tracked[$id]['altitude']) > 3) $this->all_tracked[$id]['putinarchive'] = true; |
|
|
313
|
+ if (is_int($this->all_tracked[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_tracked[$id]['altitude']) > 3) { |
|
|
314
|
+ $this->all_tracked[$id]['putinarchive'] = true; |
|
|
315
|
+ } |
|
250
|
316
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('altitude' => $line['altitude'])); |
|
251
|
317
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('altitude_real' => $line['altitude'])); |
|
252
|
318
|
//$dataFound = true; |
|
@@ -258,15 +324,21 @@ discard block |
|
|
block discarded – undo |
|
258
|
324
|
} |
|
259
|
325
|
|
|
260
|
326
|
if (isset($line['heading']) && $line['heading'] != '') { |
|
261
|
|
- if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true; |
|
|
327
|
+ if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) { |
|
|
328
|
+ $this->all_tracked[$id]['putinarchive'] = true; |
|
|
329
|
+ } |
|
262
|
330
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading']))); |
|
263
|
331
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true)); |
|
264
|
332
|
//$dataFound = true; |
|
265
|
333
|
} 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']) { |
|
266
|
334
|
$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']); |
|
267
|
335
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading))); |
|
268
|
|
- if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true; |
|
269
|
|
- if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n"; |
|
|
336
|
+ if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) { |
|
|
337
|
+ $this->all_tracked[$id]['putinarchive'] = true; |
|
|
338
|
+ } |
|
|
339
|
+ if ($globalDebug) { |
|
|
340
|
+ echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n"; |
|
|
341
|
+ } |
|
270
|
342
|
} |
|
271
|
343
|
//if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false; |
|
272
|
344
|
|
|
@@ -275,20 +347,31 @@ discard block |
|
|
block discarded – undo |
|
275
|
347
|
if ($this->all_tracked[$id]['addedTracker'] == 0) { |
|
276
|
348
|
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'])) { |
|
277
|
349
|
if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) { |
|
278
|
|
- if ($globalDebug) echo "Check if aircraft is already in DB..."; |
|
|
350
|
+ if ($globalDebug) { |
|
|
351
|
+ echo "Check if aircraft is already in DB..."; |
|
|
352
|
+ } |
|
279
|
353
|
$timeelapsed = microtime(true); |
|
280
|
354
|
$TrackerLive = new TrackerLive($this->db); |
|
281
|
355
|
if (isset($line['id'])) { |
|
282
|
356
|
$recent_ident = $TrackerLive->checkIdRecent($line['id']); |
|
283
|
|
- if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
|
357
|
+ if ($globalDebugTimeElapsed) { |
|
|
358
|
+ echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
|
359
|
+ } |
|
284
|
360
|
} elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') { |
|
285
|
361
|
$recent_ident = $TrackerLive->checkIdentRecent($this->all_tracked[$id]['ident']); |
|
286
|
|
- if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
287
|
|
- } else $recent_ident = ''; |
|
|
362
|
+ if ($globalDebugTimeElapsed) { |
|
|
363
|
+ echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
|
364
|
+ } |
|
|
365
|
+ } else { |
|
|
366
|
+ $recent_ident = ''; |
|
|
367
|
+ } |
|
288
|
368
|
$TrackerLive->db=null; |
|
289
|
369
|
|
|
290
|
|
- if ($globalDebug && $recent_ident == '') echo " Not in DB.\n"; |
|
291
|
|
- elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n"; |
|
|
370
|
+ if ($globalDebug && $recent_ident == '') { |
|
|
371
|
+ echo " Not in DB.\n"; |
|
|
372
|
+ } elseif ($globalDebug && $recent_ident != '') { |
|
|
373
|
+ echo " Already in DB.\n"; |
|
|
374
|
+ } |
|
292
|
375
|
} else { |
|
293
|
376
|
$recent_ident = ''; |
|
294
|
377
|
$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0)); |
|
@@ -296,27 +379,41 @@ discard block |
|
|
block discarded – undo |
|
296
|
379
|
//if there was no aircraft with the same callsign within the last hour and go post it into the archive |
|
297
|
380
|
if($recent_ident == "") |
|
298
|
381
|
{ |
|
299
|
|
- if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." in archive DB : "; |
|
|
382
|
+ if ($globalDebug) { |
|
|
383
|
+ echo "\o/ Add ".$this->all_tracked[$id]['ident']." in archive DB : "; |
|
|
384
|
+ } |
|
300
|
385
|
//adds the spotter data for the archive |
|
301
|
386
|
$highlight = ''; |
|
302
|
|
- if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident'].'-'.date('YmdHi'))); |
|
|
387
|
+ if (!isset($this->all_tracked[$id]['id'])) { |
|
|
388
|
+ $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident'].'-'.date('YmdHi'))); |
|
|
389
|
+ } |
|
303
|
390
|
$timeelapsed = microtime(true); |
|
304
|
391
|
$Tracker = new Tracker($this->db); |
|
305
|
392
|
$result = $Tracker->addTrackerData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['altitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['comment'],$this->all_tracked[$id]['type'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name']); |
|
306
|
393
|
$Tracker->db = null; |
|
307
|
|
- if ($globalDebug && isset($result)) echo $result."\n"; |
|
308
|
|
- if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
|
394
|
+ if ($globalDebug && isset($result)) { |
|
|
395
|
+ echo $result."\n"; |
|
|
396
|
+ } |
|
|
397
|
+ if ($globalDebugTimeElapsed) { |
|
|
398
|
+ echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
|
399
|
+ } |
|
309
|
400
|
|
|
310
|
401
|
|
|
311
|
402
|
// Add source stat in DB |
|
312
|
403
|
$Stats = new Stats($this->db); |
|
313
|
404
|
if (!empty($this->stats)) { |
|
314
|
|
- if ($globalDebug) echo 'Add source stats : '; |
|
|
405
|
+ if ($globalDebug) { |
|
|
406
|
+ echo 'Add source stats : '; |
|
|
407
|
+ } |
|
315
|
408
|
foreach($this->stats as $date => $data) { |
|
316
|
409
|
foreach($data as $source => $sourced) { |
|
317
|
410
|
//print_r($sourced); |
|
318
|
|
- if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar_tracker',$date); |
|
319
|
|
- if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist_tracker',$date); |
|
|
411
|
+ if (isset($sourced['polar'])) { |
|
|
412
|
+ echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar_tracker',$date); |
|
|
413
|
+ } |
|
|
414
|
+ if (isset($sourced['hist'])) { |
|
|
415
|
+ echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist_tracker',$date); |
|
|
416
|
+ } |
|
320
|
417
|
if (isset($sourced['msg'])) { |
|
321
|
418
|
if (time() - $sourced['msg']['date'] > 10) { |
|
322
|
419
|
$nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date'])); |
|
@@ -329,7 +426,9 @@ discard block |
|
|
block discarded – undo |
|
329
|
426
|
unset($this->stats[$date]); |
|
330
|
427
|
} |
|
331
|
428
|
} |
|
332
|
|
- if ($globalDebug) echo 'Done'."\n"; |
|
|
429
|
+ if ($globalDebug) { |
|
|
430
|
+ echo 'Done'."\n"; |
|
|
431
|
+ } |
|
333
|
432
|
|
|
334
|
433
|
} |
|
335
|
434
|
$Stats->db = null; |
|
@@ -339,12 +438,16 @@ discard block |
|
|
block discarded – undo |
|
339
|
438
|
$this->all_tracked[$id]['addedTracker'] = 1; |
|
340
|
439
|
//print_r($this->all_tracked[$id]); |
|
341
|
440
|
if ($this->last_delete == 0 || time() - $this->last_delete > 1800) { |
|
342
|
|
- if ($globalDebug) echo "---- Deleting Live Tracker data older than 9 hours..."; |
|
|
441
|
+ if ($globalDebug) { |
|
|
442
|
+ echo "---- Deleting Live Tracker data older than 9 hours..."; |
|
|
443
|
+ } |
|
343
|
444
|
//TrackerLive->deleteLiveTrackerDataNotUpdated(); |
|
344
|
445
|
$TrackerLive = new TrackerLive($this->db); |
|
345
|
446
|
$TrackerLive->deleteLiveTrackerData(); |
|
346
|
447
|
$TrackerLive->db=null; |
|
347
|
|
- if ($globalDebug) echo " Done\n"; |
|
|
448
|
+ if ($globalDebug) { |
|
|
449
|
+ echo " Done\n"; |
|
|
450
|
+ } |
|
348
|
451
|
$this->last_delete = time(); |
|
349
|
452
|
} |
|
350
|
453
|
} else { |
|
@@ -367,19 +470,25 @@ discard block |
|
|
block discarded – undo |
|
367
|
470
|
|
|
368
|
471
|
if (!$ignoreImport) { |
|
369
|
472
|
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'])) { |
|
370
|
|
- if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : "; |
|
|
473
|
+ if ($globalDebug) { |
|
|
474
|
+ echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : "; |
|
|
475
|
+ } |
|
371
|
476
|
$timeelapsed = microtime(true); |
|
372
|
477
|
$TrackerLive = new TrackerLive($this->db); |
|
373
|
478
|
$result = $TrackerLive->addLiveTrackerData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['altitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'],$this->all_tracked[$id]['comment'],$this->all_tracked[$id]['type'],$this->all_tracked[$id]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country']); |
|
374
|
479
|
$TrackerLive->db = null; |
|
375
|
480
|
$this->all_tracked[$id]['putinarchive'] = false; |
|
376
|
|
- if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
|
481
|
+ if ($globalDebugTimeElapsed) { |
|
|
482
|
+ echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
|
483
|
+ } |
|
377
|
484
|
|
|
378
|
485
|
// Put statistics in $this->stats variable |
|
379
|
486
|
|
|
380
|
487
|
if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') { |
|
381
|
488
|
$source = $this->all_tracked[$id]['source_name']; |
|
382
|
|
- if ($source == '') $source = $this->all_tracked[$id]['format_source']; |
|
|
489
|
+ if ($source == '') { |
|
|
490
|
+ $source = $this->all_tracked[$id]['format_source']; |
|
|
491
|
+ } |
|
383
|
492
|
if (!isset($this->source_location[$source])) { |
|
384
|
493
|
$Location = new Source(); |
|
385
|
494
|
$coord = $Location->getLocationInfobySourceName($source); |
|
@@ -400,7 +509,9 @@ discard block |
|
|
block discarded – undo |
|
400
|
509
|
$stats_heading = round($stats_heading/22.5); |
|
401
|
510
|
$stats_distance = $Common->distance($latitude,$longitude,$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']); |
|
402
|
511
|
$current_date = date('Y-m-d'); |
|
403
|
|
- if ($stats_heading == 16) $stats_heading = 0; |
|
|
512
|
+ if ($stats_heading == 16) { |
|
|
513
|
+ $stats_heading = 0; |
|
|
514
|
+ } |
|
404
|
515
|
if (!isset($this->stats[$current_date][$source]['polar'][1])) { |
|
405
|
516
|
for ($i=0;$i<=15;$i++) { |
|
406
|
517
|
$this->stats[$current_date][$source]['polar'][$i] = 0; |
|
@@ -418,7 +529,9 @@ discard block |
|
|
block discarded – undo |
|
418
|
529
|
if (isset($this->stats[$current_date][$source]['hist'][0])) { |
|
419
|
530
|
end($this->stats[$current_date][$source]['hist']); |
|
420
|
531
|
$mini = key($this->stats[$current_date][$source]['hist'])+10; |
|
421
|
|
- } else $mini = 0; |
|
|
532
|
+ } else { |
|
|
533
|
+ $mini = 0; |
|
|
534
|
+ } |
|
422
|
535
|
for ($i=$mini;$i<=$distance;$i+=10) { |
|
423
|
536
|
$this->stats[$current_date][$source]['hist'][$i] = 0; |
|
424
|
537
|
} |
|
@@ -429,19 +542,29 @@ discard block |
|
|
block discarded – undo |
|
429
|
542
|
} |
|
430
|
543
|
|
|
431
|
544
|
$this->all_tracked[$id]['lastupdate'] = time(); |
|
432
|
|
- if ($this->all_tracked[$id]['putinarchive']) $send = true; |
|
433
|
|
- if ($globalDebug) echo $result."\n"; |
|
434
|
|
- } 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"; |
|
|
545
|
+ if ($this->all_tracked[$id]['putinarchive']) { |
|
|
546
|
+ $send = true; |
|
|
547
|
+ } |
|
|
548
|
+ if ($globalDebug) { |
|
|
549
|
+ echo $result."\n"; |
|
|
550
|
+ } |
|
|
551
|
+ } elseif (isset($this->all_tracked[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) { |
|
|
552
|
+ echo "!! Too far -> Distance : ".$Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n"; |
|
|
553
|
+ } |
|
435
|
554
|
//$this->del(); |
|
436
|
555
|
|
|
437
|
556
|
|
|
438
|
557
|
if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) { |
|
439
|
|
- if ($globalDebug) echo "---- Deleting Live Tracker data Not updated since 2 hour..."; |
|
|
558
|
+ if ($globalDebug) { |
|
|
559
|
+ echo "---- Deleting Live Tracker data Not updated since 2 hour..."; |
|
|
560
|
+ } |
|
440
|
561
|
$TrackerLive = new TrackerLive($this->db); |
|
441
|
562
|
$TrackerLive->deleteLiveTrackerDataNotUpdated(); |
|
442
|
563
|
$TrackerLive->db = null; |
|
443
|
564
|
//TrackerLive->deleteLiveTrackerData(); |
|
444
|
|
- if ($globalDebug) echo " Done\n"; |
|
|
565
|
+ if ($globalDebug) { |
|
|
566
|
+ echo " Done\n"; |
|
|
567
|
+ } |
|
445
|
568
|
$this->last_delete_hourly = time(); |
|
446
|
569
|
} |
|
447
|
570
|
|
|
@@ -449,7 +572,9 @@ discard block |
|
|
block discarded – undo |
|
449
|
572
|
//$ignoreImport = false; |
|
450
|
573
|
} |
|
451
|
574
|
//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN); |
|
452
|
|
- if ($send) return $this->all_tracked[$id]; |
|
|
575
|
+ if ($send) { |
|
|
576
|
+ return $this->all_tracked[$id]; |
|
|
577
|
+ } |
|
453
|
578
|
} |
|
454
|
579
|
} |
|
455
|
580
|
} |