Completed
Push — master ( cc50d0...0f8c33 )
by Yannick
09:46
created

MarineImport::add()   F

Complexity

Conditions 165
Paths 0

Size

Total Lines 364
Code Lines 193

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 165
eloc 193
nc 0
nop 1
dl 0
loc 364
rs 2
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
require_once(dirname(__FILE__).'/class.Connection.php');
3
require_once(dirname(__FILE__).'/class.Marine.php');
4
require_once(dirname(__FILE__).'/class.MarineLive.php');
5
//require_once(dirname(__FILE__).'/class.MarineArchive.php');
6
require_once(dirname(__FILE__).'/class.Scheduler.php');
7
require_once(dirname(__FILE__).'/class.Translation.php');
8
require_once(dirname(__FILE__).'/class.Stats.php');
9
require_once(dirname(__FILE__).'/class.Source.php');
10
11
class MarineImport {
12
    private $all_tracked = array();
13
    private $last_delete_hourly = 0;
14
    private $last_delete = 0;
15
    private $stats = array();
0 ignored issues
show
Unused Code introduced by
The property $stats is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
16
    private $tmd = 0;
17
    private $source_location = array();
0 ignored issues
show
Unused Code introduced by
The property $source_location is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
18
    public $db = null;
19
    public $nb = 0;
20
21
    public function __construct($dbc = null) {
22
	global $globalBeta;
23
	$Connection = new Connection($dbc);
24
	$this->db = $Connection->db();
25
	date_default_timezone_set('UTC');
26
27
	// Get previous source stats
28
	/*
29
	$Stats = new Stats($dbc);
30
	$currentdate = date('Y-m-d');
31
	$sourcestat = $Stats->getStatsSource($currentdate);
32
	if (!empty($sourcestat)) {
33
	    foreach($sourcestat as $srcst) {
34
	    	$type = $srcst['stats_type'];
35
		if ($type == 'polar' || $type == 'hist') {
36
		    $source = $srcst['source_name'];
37
		    $data = $srcst['source_data'];
38
		    $this->stats[$currentdate][$source][$type] = json_decode($data,true);
39
	        }
40
	    }
41
	}
42
	*/
43
    }
44
45
    public function checkAll() {
46
	global $globalDebug;
47
	if ($globalDebug) echo "Update last seen tracked data...\n";
48
	foreach ($this->all_tracked as $key => $flight) {
49
	    if (isset($this->all_tracked[$key]['id'])) {
50
		//echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].'  '.$this->all_tracked[$key]['longitude']."\n";
51
    		$Marine = new Marine($this->db);
52
        	$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']);
53
            }
54
	}
55
    }
56
57
    public function del() {
58
	global $globalDebug;
59
	// Delete old infos
60
	if ($globalDebug) echo 'Delete old values and update latest data...'."\n";
61
	foreach ($this->all_tracked as $key => $flight) {
62
    	    if (isset($flight['lastupdate'])) {
63
        	if ($flight['lastupdate'] < (time()-3000)) {
64
            	    if (isset($this->all_tracked[$key]['id'])) {
65
            		if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n";
66
			/*
67
			$MarineLive = new MarineLive();
68
            		$MarineLive->deleteLiveMarineDataById($this->all_tracked[$key]['id']);
69
			$MarineLive->db = null;
70
			*/
71
            		//$real_arrival = $this->arrival($key);
72
            		$Marine = new Marine($this->db);
73
            		if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') {
74
				$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']);
75
				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
76
			}
77
			// Put in archive
78
//			$Marine->db = null;
79
            	    }
80
            	    unset($this->all_tracked[$key]);
81
    	        }
82
	    }
83
        }
84
    }
85
86
    public function add($line) {
87
	global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked;
88
	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
89
	date_default_timezone_set('UTC');
90
	$dataFound = false;
91
	$send = false;
92
	
93
	// SBS format is CSV format
94
	if(is_array($line) && isset($line['mmsi'])) {
95
	    //print_r($line);
96
  	    if (isset($line['mmsi'])) {
97
98
		/*
99
		// Increment message number
100
		if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE) {
101
		    $current_date = date('Y-m-d');
102
		    $source = $line['source_name'];
103
		    if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
104
		    if (!isset($this->stats[$current_date][$source]['msg'])) {
105
		    	$this->stats[$current_date][$source]['msg']['date'] = time();
106
		    	$this->stats[$current_date][$source]['msg']['nb'] = 1;
107
		    } else $this->stats[$current_date][$source]['msg']['nb'] += 1;
108
		}
109
		*/
110
		
111
		$Common = new Common();
112
	        if (!isset($line['id'])) $id = trim($line['mmsi']);
113
	        else $id = trim($line['id']);
114
		
115
		if (!isset($this->all_tracked[$id])) {
116
		    $this->all_tracked[$id] = array();
117
		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('addedMarine' => 0));
118
		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','noarchive' => false,'putinarchive' => true,'over_country' => '','mmsi' => '','type' => '','status' => ''));
119
		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time()));
120
		    if (!isset($line['id'])) {
121
			if (!isset($globalDaemon)) $globalDaemon = TRUE;
122
			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $id.'-'.date('YmdHi')));
123
		     } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id']));
124
		    if ($globalAllTracked !== FALSE) $dataFound = true;
125
		}
126
		
127
		if (isset($line['mmsi']) && $line['mmsi'] != '' && $line['mmsi'] != $this->all_tracked[$id]['mmsi']) {
128
		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi' => $line['mmsi']));
129
		    $Marine = new Marine($this->db);
130
		    $identity = $Marine->getIdentity($line['mmsi']);
131
		    if (!empty($identity)) {
132
			$this->all_tracked[$id]['ident'] = $identity['ship_name'];
133
			$this->all_tracked[$id]['type'] = $identity['type'];
134
		    }
135
		    //print_r($identity);
136
		    unset($Marine);
137
		    //$dataFound = true;
138
		}
139
140
141
		//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'])) {
142
		if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_tracked[$id]['ident'] != trim($line['ident']))) {
143
		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident'])));
144
		    if ($this->all_tracked[$id]['addedMarine'] == 1) {
145
			$timeelapsed = microtime(true);
146
            		$Marine = new Marine($this->db);
147
            		$fromsource = NULL;
148
            		$result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource);
149
			if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
150
			$Marine->db = null;
151
			if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
152
		    }
153
		    if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident']));
154
		}
155
156
		if (isset($line['speed']) && $line['speed'] != '') {
157
		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed'])));
158
		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true));
159
		} 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'])) {
160
		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m');
161
		    if ($distance > 1000 && $distance < 10000) {
162
			$speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']);
163
			$speed = $speed*3.6;
164
			if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed)));
165
  			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
166
		    }
167
		}
168
169
	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
170
	    	    if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']);
171
	    	    else unset($timediff);
172
	    	    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')))) {
173
			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'])) {
174
			    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'])) {
175
				$this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
176
				$this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
177
				$this->all_tracked[$id]['putinarchive'] = true;
178
				
179
				if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... ';
180
				$timeelapsed = microtime(true);
181
				$Marine = new Marine($this->db);
182
				$all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
183
				if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2'];
184
				$Marine->db = null;
185
				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
186
				$this->tmd = 0;
187
				if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n";
188
			    }
189
			}
190
191
			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
192
				if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude'];
193
				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') {
194
				    $this->all_tracked[$id]['livedb_latitude'] = $line['latitude'];
195
				    $dataFound = true;
196
				    $this->all_tracked[$id]['time_last_coord'] = time();
197
				}
198
				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude']));
199
			}
200
			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
201
			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
202
				if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude'];
203
				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') {
204
				    $this->all_tracked[$id]['livedb_longitude'] = $line['longitude'];
205
				    $dataFound = true;
206
				    $this->all_tracked[$id]['time_last_coord'] = time();
207
				}
208
				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('longitude' => $line['longitude']));
209
			}
210
211
		    } else if ($globalDebug && $timediff > 20) {
212
			$this->tmd = $this->tmd + 1;
213
			echo '!!! Too much distance in short time... for '.$this->all_tracked[$id]['ident']."\n";
214
			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')."m -";
215
			echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
216
			echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_tracked[$id]['latitude'].' - prev long : '.$this->all_tracked[$id]['longitude']." \n";
217
		    }
218
		}
219
		if (isset($line['last_update']) && $line['last_update'] != '') {
220
		    if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true;
221
		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update']));
222
		}
223
		if (isset($line['format_source']) && $line['format_source'] != '') {
224
		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source']));
225
		}
226
		if (isset($line['source_name']) && $line['source_name'] != '') {
227
		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name']));
228
		}
229
		if (isset($line['status']) && $line['status'] != '') {
230
		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status' => $line['status']));
231
		}
232
233
		if (isset($line['noarchive']) && $line['noarchive'] === true) {
234
		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true));
235
		}
236
		
237
		if (isset($line['heading']) && $line['heading'] != '') {
238
		    if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true;
239
		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading'])));
240
		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true));
241
		    //$dataFound = true;
242
  		} 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']) {
243
  		    $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']);
244
		    $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading)));
245
		    if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true;
246
  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n";
247
  		}
248
		//if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
249
250
		if (isset($line['datetime'])) {
251
		    if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) {
252
			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime']));
253
		    } else {
254
				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";
255
				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";
256
				return '';
257
		    }
258
		} else {
259
			date_default_timezone_set('UTC');
260
			$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => date('Y-m-d H:i:s')));
261
		}
262
263
264
		if ($dataFound === true && isset($this->all_tracked[$id]['mmsi'])) {
265
		    $this->all_tracked[$id]['lastupdate'] = time();
266
		    if ($this->all_tracked[$id]['addedMarine'] == 0) {
267
		        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'])) {
268
			    if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) {
269
				if ($globalDebug) echo "Check if aircraft is already in DB...";
270
				$timeelapsed = microtime(true);
271
				$MarineLive = new MarineLive($this->db);
272
				if (isset($line['id'])) {
273
				    $recent_ident = $MarineLive->checkIdRecent($line['id']);
274
				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
275
				} elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') {
276
				    $recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']);
277
				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
278
				} elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') {
279
				    $recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']);
280
				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
281
				} else $recent_ident = '';
282
				$MarineLive->db=null;
283
				if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
284
				elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
285
			    } else {
286
				$recent_ident = '';
287
				$this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0));
288
			    }
289
			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
290
			    if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '')
291
			    {
292
				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : ";
293
				//adds the spotter data for the archive
294
				    $highlight = '';
0 ignored issues
show
Unused Code introduced by
$highlight is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
295
				    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')));
296
				    $timeelapsed = microtime(true);
297
				    $Marine = new Marine($this->db);
298
				    $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]['status'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name']);
299
				    $Marine->db = null;
300
				    if ($globalDebug && isset($result)) echo $result."\n";
301
				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
302
				    
303
				    /*
304
				    // Add source stat in DB
305
				    $Stats = new Stats($this->db);
306
				    if (!empty($this->stats)) {
307
					if ($globalDebug) echo 'Add source stats : ';
308
				        foreach($this->stats as $date => $data) {
309
					    foreach($data as $source => $sourced) {
310
					        //print_r($sourced);
311
				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
312
				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
313
				    		if (isset($sourced['msg'])) {
314
				    		    if (time() - $sourced['msg']['date'] > 10) {
315
				    		        $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
316
				    		        echo $Stats->addStatSource($nbmsg,$source,'msg',$date);
317
			    			        unset($this->stats[$date][$source]['msg']);
318
			    			    }
319
			    			}
320
			    		    }
321
			    		    if ($date != date('Y-m-d')) {
322
			    			unset($this->stats[$date]);
323
			    		    }
324
				    	}
325
				    	if ($globalDebug) echo 'Done'."\n";
326
327
				    }
328
				    $Stats->db = null;
329
				    */
330
				    $this->del();
331
				//$ignoreImport = false;
332
				$this->all_tracked[$id]['addedMarine'] = 1;
333
				//print_r($this->all_tracked[$id]);
334
				if ($this->last_delete == 0 || time() - $this->last_delete > 1800) {
335
				    if ($globalDebug) echo "---- Deleting Live Marine data older than 9 hours...";
336
				    //MarineLive->deleteLiveMarineDataNotUpdated();
337
				    $MarineLive = new MarineLive($this->db);
338
				    $MarineLive->deleteLiveMarineData();
339
				    $MarineLive->db=null;
340
				    if ($globalDebug) echo " Done\n";
341
				    $this->last_delete = time();
342
				}
343
			    } elseif ($recent_ident != '') {
344
				$this->all_tracked[$id]['id'] = $recent_ident;
345
				$this->all_tracked[$id]['addedMarine'] = 1;
346
				if (isset($globalDaemon) && !$globalDaemon) {
347
					$Marine = new Marine($this->db);
348
					$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']);
349
					$Marine->db = null;
350
				}
351
				
352
			    }
353
			}
354
		    }
355
		    //adds the spotter LIVE data
356
		    if ($globalDebug) {
357
			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";
358
		    }
359
		    $ignoreImport = false;
360
361
		    if (!$ignoreImport) {
362
			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'])) {
363
				if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : ";
364
				$timeelapsed = microtime(true);
365
				$MarineLive = new MarineLive($this->db);
366
				$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]['status'],$this->all_tracked[$id]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country']);
0 ignored issues
show
Documentation introduced by
$this->all_tracked[$id]['putinarchive'] is of type integer|double|string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$this->all_tracked[$id]['noarchive'] is of type integer|double|string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
367
				$MarineLive->db = null;
368
				$this->all_tracked[$id]['putinarchive'] = false;
369
				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
370
371
				// Put statistics in $this->stats variable
372
				/*
373
				if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $line['format_source'] != 'aprs' && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') {
374
					$source = $this->all_tracked[$id]['source_name'];
375
					if ($source == '') $source = $this->all_tracked[$id]['format_source'];
376
					if (!isset($this->source_location[$source])) {
377
						$Location = new Source();
378
						$coord = $Location->getLocationInfobySourceName($source);
379
						if (count($coord) > 0) {
380
							$latitude = $coord[0]['latitude'];
381
							$longitude = $coord[0]['longitude'];
382
						} else {
383
							$latitude = $globalCenterLatitude;
384
							$longitude = $globalCenterLongitude;
385
						}
386
						$this->source_location[$source] = array('latitude' => $latitude,'longitude' => $longitude);
387
					} else {
388
						$latitude = $this->source_location[$source]['latitude'];
389
						$longitude = $this->source_location[$source]['longitude'];
390
					}
391
					$stats_heading = $Common->getHeading($latitude,$longitude,$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']);
392
					//$stats_heading = $stats_heading%22.5;
393
					$stats_heading = round($stats_heading/22.5);
394
					$stats_distance = $Common->distance($latitude,$longitude,$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']);
395
					$current_date = date('Y-m-d');
396
					if ($stats_heading == 16) $stats_heading = 0;
397
					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
398
						for ($i=0;$i<=15;$i++) {
399
						    $this->stats[$current_date][$source]['polar'][$i] = 0;
400
						}
401
						$this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance;
402
					} else {
403
						if ($this->stats[$current_date][$source]['polar'][$stats_heading] < $stats_distance) {
404
							$this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance;
405
						}
406
					}
407
					$distance = (round($stats_distance/10)*10);
408
					//echo '$$$$$$$$$$ DISTANCE : '.$distance.' - '.$source."\n";
409
					//var_dump($this->stats);
410
					if (!isset($this->stats[$current_date][$source]['hist'][$distance])) {
411
						if (isset($this->stats[$current_date][$source]['hist'][0])) {
412
						    end($this->stats[$current_date][$source]['hist']);
413
						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
414
						} else $mini = 0;
415
						for ($i=$mini;$i<=$distance;$i+=10) {
416
						    $this->stats[$current_date][$source]['hist'][$i] = 0;
417
						}
418
						$this->stats[$current_date][$source]['hist'][$distance] = 1;
419
					} else {
420
						$this->stats[$current_date][$source]['hist'][$distance] += 1;
421
					}
422
				}
423
				*/
424
425
				$this->all_tracked[$id]['lastupdate'] = time();
426
				if ($this->all_tracked[$id]['putinarchive']) $send = true;
427
				if ($globalDebug) echo $result."\n";
428
			} 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";
429
			//$this->del();
430
			
431
			
432
			if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) {
433
			    if ($globalDebug) echo "---- Deleting Live Marine data Not updated since 2 hour...";
434
			    $MarineLive = new MarineLive($this->db);
435
			    $MarineLive->deleteLiveMarineDataNotUpdated();
436
			    $MarineLive->db = null;
437
			    //MarineLive->deleteLiveMarineData();
438
			    if ($globalDebug) echo " Done\n";
439
			    $this->last_delete_hourly = time();
440
			}
441
			
442
		    }
443
		    //$ignoreImport = false;
444
		}
445
		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
446
		if ($send) return $this->all_tracked[$id];
447
	    }
448
	}
449
    }
450
}
451
?>
452