|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This class save stats older than a year and $globalArchiveMonths |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
require_once(dirname(__FILE__).'/class.Spotter.php'); |
|
7
|
|
|
require_once(dirname(__FILE__).'/class.SpotterArchive.php'); |
|
8
|
|
|
require_once(dirname(__FILE__).'/class.Common.php'); |
|
9
|
|
|
class Stats { |
|
10
|
|
|
public $db; |
|
11
|
|
|
public function __construct($dbc = null) { |
|
12
|
|
|
$Connection = new Connection($dbc); |
|
13
|
|
|
$this->db = $Connection->db(); |
|
14
|
|
|
} |
|
15
|
|
|
|
|
16
|
|
|
public function addLastStatsUpdate($type,$stats_date) { |
|
17
|
|
|
$query = "DELETE FROM config WHERE name = :type; |
|
18
|
|
|
INSERT INTO config (name,value) VALUES (:type,:stats_date);"; |
|
19
|
|
|
$query_values = array('type' => $type,':stats_date' => $stats_date); |
|
20
|
|
|
try { |
|
21
|
|
|
$sth = $this->db->prepare($query); |
|
22
|
|
|
$sth->execute($query_values); |
|
23
|
|
|
} catch(PDOException $e) { |
|
24
|
|
|
return "error : ".$e->getMessage(); |
|
25
|
|
|
} |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function getLastStatsUpdate($type = 'last_update_stats') { |
|
29
|
|
|
$query = "SELECT value FROM config WHERE name = :type"; |
|
30
|
|
|
try { |
|
31
|
|
|
$sth = $this->db->prepare($query); |
|
32
|
|
|
$sth->execute(array(':type' => $type)); |
|
33
|
|
|
} catch(PDOException $e) { |
|
34
|
|
|
echo "error : ".$e->getMessage(); |
|
35
|
|
|
} |
|
36
|
|
|
$all = $sth->fetchAll(PDO::FETCH_ASSOC); |
|
37
|
|
|
return $all; |
|
38
|
|
|
} |
|
39
|
|
|
public function getAllAirlineNames($filter_name = '') { |
|
40
|
|
|
$query = "SELECT * FROM stats_airline WHERE filter_name = :filter_name ORDER BY airline_name ASC"; |
|
41
|
|
|
try { |
|
42
|
|
|
$sth = $this->db->prepare($query); |
|
43
|
|
|
$sth->execute(array(':filter_name' => $filter_name)); |
|
44
|
|
|
} catch(PDOException $e) { |
|
45
|
|
|
echo "error : ".$e->getMessage(); |
|
46
|
|
|
} |
|
47
|
|
|
$all = $sth->fetchAll(PDO::FETCH_ASSOC); |
|
48
|
|
|
return $all; |
|
49
|
|
|
} |
|
50
|
|
|
public function getAllAircraftTypes($stats_airline = '',$filter_name = '') { |
|
51
|
|
|
$query = "SELECT * FROM stats_aircraft WHERE stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY aircraft_manufacturer ASC"; |
|
52
|
|
|
try { |
|
53
|
|
|
$sth = $this->db->prepare($query); |
|
54
|
|
|
$sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name)); |
|
55
|
|
|
} catch(PDOException $e) { |
|
56
|
|
|
echo "error : ".$e->getMessage(); |
|
57
|
|
|
} |
|
58
|
|
|
$all = $sth->fetchAll(PDO::FETCH_ASSOC); |
|
59
|
|
|
return $all; |
|
60
|
|
|
} |
|
61
|
|
|
public function getAllAirportNames($stats_airline = '',$filter_name = '') { |
|
62
|
|
|
$query = "SELECT airport_icao, airport_name,airport_city,airport_country FROM stats_airport WHERE stats_airline = :stats_airline AND filter_name = :filter_name GROUP BY airport_icao,airport_name,airport_city,airport_country ORDER BY airport_city ASC"; |
|
63
|
|
|
try { |
|
64
|
|
|
$sth = $this->db->prepare($query); |
|
65
|
|
|
$sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name)); |
|
66
|
|
|
} catch(PDOException $e) { |
|
67
|
|
|
echo "error : ".$e->getMessage(); |
|
68
|
|
|
} |
|
69
|
|
|
$all = $sth->fetchAll(PDO::FETCH_ASSOC); |
|
70
|
|
|
return $all; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
|
|
74
|
|
|
public function countAllAircraftTypes($limit = true, $stats_airline = '', $filter_name = '') { |
|
75
|
|
|
global $globalStatsFilters; |
|
76
|
|
|
if ($limit) $query = "SELECT aircraft_icao, cnt AS aircraft_icao_count, aircraft_name FROM stats_aircraft WHERE aircraft_name <> '' AND aircraft_icao <> '' AND stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY aircraft_icao_count DESC LIMIT 10 OFFSET 0"; |
|
77
|
|
|
else $query = "SELECT aircraft_icao, cnt AS aircraft_icao_count, aircraft_name FROM stats_aircraft WHERE aircraft_name <> '' AND aircraft_icao <> '' AND stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY aircraft_icao_count DESC"; |
|
78
|
|
|
try { |
|
79
|
|
|
$sth = $this->db->prepare($query); |
|
80
|
|
|
$sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name)); |
|
81
|
|
|
} catch(PDOException $e) { |
|
82
|
|
|
echo "error : ".$e->getMessage(); |
|
83
|
|
|
} |
|
84
|
|
|
$all = $sth->fetchAll(PDO::FETCH_ASSOC); |
|
85
|
|
|
if (empty($all)) { |
|
86
|
|
|
$filters = array('airlines' => array($stats_airline)); |
|
87
|
|
|
if ($filter_name != '') { |
|
88
|
|
|
$filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
|
89
|
|
|
} |
|
90
|
|
|
$Spotter = new Spotter($this->db); |
|
91
|
|
|
$all = $Spotter->countAllAircraftTypes($limit,0,'',$filters); |
|
92
|
|
|
} |
|
93
|
|
|
return $all; |
|
94
|
|
|
} |
|
95
|
|
|
public function countAllAirlineCountries($limit = true,$filter_name = '') { |
|
96
|
|
|
global $globalStatsFilters; |
|
97
|
|
|
if ($limit) $query = "SELECT airlines.country AS airline_country, SUM(stats_airline.cnt) as airline_country_count FROM stats_airline,airlines WHERE stats_airline.airline_icao=airlines.icao AND filter_name = :filter_name GROUP BY airline_country ORDER BY airline_country_count DESC LIMIT 10 OFFSET 0"; |
|
98
|
|
|
else $query = "SELECT airlines.country AS airline_country, SUM(stats_airline.cnt) as airline_country_count FROM stats_airline,airlines WHERE stats_airline.airline_icao=airlines.icao AND filter_name = :filter_name GROUP BY airline_country ORDER BY airline_country_count DESC"; |
|
99
|
|
|
try { |
|
100
|
|
|
$sth = $this->db->prepare($query); |
|
101
|
|
|
$sth->execute(array(':filter_name' => $filter_name)); |
|
102
|
|
|
} catch(PDOException $e) { |
|
103
|
|
|
echo "error : ".$e->getMessage(); |
|
104
|
|
|
} |
|
105
|
|
|
$all = $sth->fetchAll(PDO::FETCH_ASSOC); |
|
106
|
|
|
if (empty($all)) { |
|
107
|
|
|
$Spotter = new Spotter($this->db); |
|
108
|
|
|
$filters = array(); |
|
109
|
|
|
if ($filter_name != '') { |
|
110
|
|
|
$filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
|
111
|
|
|
} |
|
112
|
|
|
$all = $Spotter->countAllAirlineCountries($limit,$filters); |
|
113
|
|
|
} |
|
114
|
|
|
return $all; |
|
115
|
|
|
} |
|
116
|
|
|
public function countAllAircraftManufacturers($limit = true,$stats_airline = '', $filter_name = '') { |
|
117
|
|
|
global $globalStatsFilters; |
|
118
|
|
|
if ($limit) $query = "SELECT aircraft_manufacturer, SUM(stats_aircraft.cnt) as aircraft_manufacturer_count FROM stats_aircraft WHERE stats_airline = :stats_airline AND filter_name = :filter_name GROUP BY aircraft_manufacturer ORDER BY aircraft_manufacturer_count DESC LIMIT 10 OFFSET 0"; |
|
119
|
|
|
else $query = "SELECT aircraft_manufacturer, SUM(stats_aircraft.cnt) as aircraft_manufacturer_count FROM stats_aircraft WHERE stats_airline = :stats_airline AND filter_name = :filter_name GROUP BY aircraft_manufacturer ORDER BY aircraft_manufacturer_count DESC"; |
|
120
|
|
|
try { |
|
121
|
|
|
$sth = $this->db->prepare($query); |
|
122
|
|
|
$sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name)); |
|
123
|
|
|
} catch(PDOException $e) { |
|
124
|
|
|
echo "error : ".$e->getMessage(); |
|
125
|
|
|
} |
|
126
|
|
|
$all = $sth->fetchAll(PDO::FETCH_ASSOC); |
|
127
|
|
|
if (empty($all)) { |
|
128
|
|
|
$filters = array('airlines' => array($stats_airline)); |
|
129
|
|
|
if ($filter_name != '') { |
|
130
|
|
|
$filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
|
131
|
|
|
} |
|
132
|
|
|
$Spotter = new Spotter($this->db); |
|
133
|
|
|
$all = $Spotter->countAllAircraftManufacturers($filters); |
|
134
|
|
|
} |
|
135
|
|
|
return $all; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
public function countAllArrivalCountries($limit = true, $stats_airline = '', $filter_name = '') { |
|
139
|
|
|
global $globalStatsFilters; |
|
140
|
|
|
if ($limit) $query = "SELECT airport_country AS airport_arrival_country, SUM(arrival) as airport_arrival_country_count FROM stats_airport WHERE stats_type = 'yearly' AND stats_airline = :stats_airline AND filter_name = :filter_name GROUP BY airport_arrival_country ORDER BY airport_arrival_country_count DESC LIMIT 10 OFFSET 0"; |
|
141
|
|
|
else $query = "SELECT airport_country AS airport_arrival_country, SUM(arrival) as airport_arrival_country_count FROM stats_airport WHERE stats_type = 'yearly' AND stats_airline = :stats_airline AND filter_name = :filter_name GROUP BY airport_arrival_country ORDER BY airport_arrival_country_count DESC"; |
|
142
|
|
|
try { |
|
143
|
|
|
$sth = $this->db->prepare($query); |
|
144
|
|
|
$sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name)); |
|
145
|
|
|
} catch(PDOException $e) { |
|
146
|
|
|
echo "error : ".$e->getMessage(); |
|
147
|
|
|
} |
|
148
|
|
|
$all = $sth->fetchAll(PDO::FETCH_ASSOC); |
|
149
|
|
|
if (empty($all)) { |
|
150
|
|
|
$filters = array('airlines' => array($stats_airline)); |
|
151
|
|
|
if ($filter_name != '') { |
|
152
|
|
|
$filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
|
153
|
|
|
} |
|
154
|
|
|
$Spotter = new Spotter($this->db); |
|
155
|
|
|
$all = $Spotter->countAllArrivalCountries($limit,$filters); |
|
156
|
|
|
} |
|
157
|
|
|
return $all; |
|
158
|
|
|
} |
|
159
|
|
|
public function countAllDepartureCountries($limit = true, $stats_airline = '', $filter_name = '') { |
|
160
|
|
|
global $globalStatsFilters; |
|
161
|
|
|
if ($limit) $query = "SELECT airport_country AS airport_departure_country, SUM(departure) as airport_departure_country_count FROM stats_airport WHERE stats_type = 'yearly' AND stats_airline = :stats_airline AND filter_name = :filter_name GROUP BY airport_departure_country ORDER BY airport_departure_country_count DESC LIMIT 10 OFFSET 0"; |
|
162
|
|
|
else $query = "SELECT airport_country AS airport_departure_country, SUM(departure) as airport_departure_country_count FROM stats_airport WHERE stats_type = 'yearly' AND stats_airline = :stats_airline AND filter_name = :filter_name GROUP BY airport_departure_country ORDER BY airport_departure_country_count DESC"; |
|
163
|
|
|
try { |
|
164
|
|
|
$sth = $this->db->prepare($query); |
|
165
|
|
|
$sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name)); |
|
166
|
|
|
} catch(PDOException $e) { |
|
167
|
|
|
echo "error : ".$e->getMessage(); |
|
168
|
|
|
} |
|
169
|
|
|
$all = $sth->fetchAll(PDO::FETCH_ASSOC); |
|
170
|
|
|
if (empty($all)) { |
|
171
|
|
|
$filters = array('airlines' => array($stats_airline)); |
|
172
|
|
|
if ($filter_name != '') { |
|
173
|
|
|
$filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
|
174
|
|
|
} |
|
175
|
|
|
$Spotter = new Spotter($this->db); |
|
176
|
|
|
$all = $Spotter->countAllDepartureCountries($filters); |
|
177
|
|
|
} |
|
178
|
|
|
return $all; |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
public function countAllAirlines($limit = true,$filter_name = '') { |
|
182
|
|
|
global $globalStatsFilters; |
|
183
|
|
|
if ($limit) $query = "SELECT DISTINCT stats_airline.airline_icao, stats_airline.cnt AS airline_count, stats_airline.airline_name, airlines.country as airline_country FROM stats_airline, airlines WHERE stats_airline.airline_name <> '' AND stats_airline.airline_icao <> '' AND airlines.icao = stats_airline.airline_icao AND filter_name = :filter_name ORDER BY airline_count DESC LIMIT 10 OFFSET 0"; |
|
184
|
|
|
else $query = "SELECT DISTINCT stats_airline.airline_icao, stats_airline.cnt AS airline_count, stats_airline.airline_name, airlines.country as airline_country FROM stats_airline, airlines WHERE stats_airline.airline_name <> '' AND stats_airline.airline_icao <> '' AND airlines.icao = stats_airline.airline_icao AND filter_name = :filter_name ORDER BY airline_count DESC"; |
|
185
|
|
|
try { |
|
186
|
|
|
$sth = $this->db->prepare($query); |
|
187
|
|
|
$sth->execute(array(':filter_name' => $filter_name)); |
|
188
|
|
|
} catch(PDOException $e) { |
|
189
|
|
|
echo "error : ".$e->getMessage(); |
|
190
|
|
|
} |
|
191
|
|
|
$all = $sth->fetchAll(PDO::FETCH_ASSOC); |
|
192
|
|
|
if (empty($all)) { |
|
193
|
|
|
$Spotter = new Spotter($this->db); |
|
194
|
|
|
$filters = array(); |
|
195
|
|
|
if ($filter_name != '') { |
|
196
|
|
|
$filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
$all = $Spotter->countAllAirlines($limit,0,'',$filters); |
|
|
|
|
|
|
200
|
|
|
} |
|
201
|
|
|
return $all; |
|
202
|
|
|
} |
|
203
|
|
|
public function countAllAircraftRegistrations($limit = true,$stats_airline = '',$filter_name = '') { |
|
204
|
|
|
global $globalStatsFilters; |
|
205
|
|
|
if ($limit) $query = "SELECT s.aircraft_icao, s.cnt AS aircraft_registration_count, a.type AS aircraft_name, s.registration FROM stats_registration s, aircraft a WHERE s.registration <> '' AND a.icao = s.aircraft_icao AND s.stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY aircraft_registration_count DESC LIMIT 10 OFFSET 0"; |
|
206
|
|
|
else $query = "SELECT s.aircraft_icao, s.cnt AS aircraft_registration_count, a.type AS aircraft_name FROM stats_registration s, aircraft a WHERE s.registration <> '' AND a.icao = s.aircraft_icao AND s.stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY aircraft_registration_count DESC"; |
|
207
|
|
|
try { |
|
208
|
|
|
$sth = $this->db->prepare($query); |
|
209
|
|
|
$sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name)); |
|
210
|
|
|
} catch(PDOException $e) { |
|
211
|
|
|
echo "error : ".$e->getMessage(); |
|
212
|
|
|
} |
|
213
|
|
|
$all = $sth->fetchAll(PDO::FETCH_ASSOC); |
|
214
|
|
|
if (empty($all)) { |
|
215
|
|
|
$filters = array('airlines' => array($stats_airline)); |
|
216
|
|
|
if ($filter_name != '') { |
|
217
|
|
|
$filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
|
218
|
|
|
} |
|
219
|
|
|
$Spotter = new Spotter($this->db); |
|
220
|
|
|
$all = $Spotter->countAllAircraftRegistrations($limit,0,'',$filters); |
|
221
|
|
|
} |
|
222
|
|
|
return $all; |
|
223
|
|
|
} |
|
224
|
|
|
public function countAllCallsigns($limit = true,$stats_airline = '',$filter_name = '') { |
|
225
|
|
|
global $globalStatsFilters; |
|
226
|
|
|
if ($limit) $query = "SELECT s.callsign_icao, s.cnt AS callsign_icao_count, a.name AS airline_name, a.icao as airline_icao FROM stats_callsign s, airlines a WHERE s.callsign_icao <> '' AND a.icao = s.airline_icao AND s.airline_icao = :stats_airline AND filter_name = :filter_name ORDER BY callsign_icao_count DESC LIMIT 10 OFFSET 0"; |
|
227
|
|
|
else $query = "SELECT s.callsign_icao, s.cnt AS callsign_icao_count, a.name AS airline_name, a.icao as airline_icao FROM stats_callsign s, airlines a WHERE s.callsign_icao <> '' AND a.icao = s.airline_icao AND s.airline_icao = :stats_airline AND filter_name = :filter_name ORDER BY callsign_icao_count DESC"; |
|
228
|
|
|
try { |
|
229
|
|
|
$sth = $this->db->prepare($query); |
|
230
|
|
|
$sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name)); |
|
231
|
|
|
} catch(PDOException $e) { |
|
232
|
|
|
echo "error : ".$e->getMessage(); |
|
233
|
|
|
} |
|
234
|
|
|
$all = $sth->fetchAll(PDO::FETCH_ASSOC); |
|
235
|
|
|
if (empty($all)) { |
|
236
|
|
|
$filters = array('airlines' => array($stats_airline)); |
|
237
|
|
|
if ($filter_name != '') { |
|
238
|
|
|
$filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
|
239
|
|
|
} |
|
240
|
|
|
$Spotter = new Spotter($this->db); |
|
241
|
|
|
$all = $Spotter->countAllCallsigns($limit,0,'',$filters); |
|
242
|
|
|
} |
|
243
|
|
|
return $all; |
|
244
|
|
|
} |
|
245
|
|
|
public function countAllFlightOverCountries($limit = true, $stats_airline = '',$filter_name = '') { |
|
246
|
|
|
$Connection = new Connection(); |
|
247
|
|
|
if ($Connection->tableExists('countries')) { |
|
248
|
|
|
if ($limit) $query = "SELECT countries.iso3 as flight_country_iso3, countries.iso2 as flight_country_iso2, countries.name as flight_country, cnt as flight_count, lat as flight_country_latitude, lon as flight_country_longitude FROM stats_country, countries WHERE stats_country.iso2 = countries.iso2 AND stats_country.stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY flight_count DESC LIMIT 20 OFFSET 0"; |
|
249
|
|
|
else $query = "SELECT countries.iso3 as flight_country_iso3, countries.iso2 as flight_country_iso2, countries.name as flight_country, cnt as flight_count, lat as flight_country_latitude, lon as flight_country_longitude FROM stats_country, countries WHERE stats_country.iso2 = countries.iso2 AND stats_country.stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY flight_count DESC"; |
|
250
|
|
|
try { |
|
251
|
|
|
$sth = $this->db->prepare($query); |
|
252
|
|
|
$sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name)); |
|
253
|
|
|
} catch(PDOException $e) { |
|
254
|
|
|
echo "error : ".$e->getMessage(); |
|
255
|
|
|
} |
|
256
|
|
|
$all = $sth->fetchAll(PDO::FETCH_ASSOC); |
|
257
|
|
|
/* |
|
258
|
|
|
if (empty($all)) { |
|
259
|
|
|
$Spotter = new Spotter($this->db); |
|
260
|
|
|
$all = $Spotter->countAllFlightOverCountries($limit); |
|
261
|
|
|
} |
|
262
|
|
|
*/ |
|
263
|
|
|
return $all; |
|
264
|
|
|
} else { |
|
265
|
|
|
return array(); |
|
266
|
|
|
} |
|
267
|
|
|
} |
|
268
|
|
|
public function countAllPilots($limit = true,$stats_airline = '',$filter_name = '') { |
|
269
|
|
|
global $globalStatsFilters; |
|
270
|
|
|
if ($limit) $query = "SELECT pilot_id, cnt AS pilot_count, pilot_name FROM stats_pilot WHERE stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY pilot_count DESC LIMIT 10 OFFSET 0"; |
|
271
|
|
|
else $query = "SELECT pilot_id, cnt AS pilot_count, pilot_name FROM stats_pilot WHERE stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY pilot_count DESC"; |
|
272
|
|
|
try { |
|
273
|
|
|
$sth = $this->db->prepare($query); |
|
274
|
|
|
$sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name)); |
|
275
|
|
|
} catch(PDOException $e) { |
|
276
|
|
|
echo "error : ".$e->getMessage(); |
|
277
|
|
|
} |
|
278
|
|
|
$all = $sth->fetchAll(PDO::FETCH_ASSOC); |
|
279
|
|
|
if (empty($all)) { |
|
280
|
|
|
$filters = array('airlines' => array($stats_airline)); |
|
281
|
|
|
if ($filter_name != '') { |
|
282
|
|
|
$filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
|
283
|
|
|
} |
|
284
|
|
|
$Spotter = new Spotter($this->db); |
|
285
|
|
|
$all = $Spotter->countAllPilots($limit,0,'',$filters); |
|
286
|
|
|
} |
|
287
|
|
|
return $all; |
|
288
|
|
|
} |
|
289
|
|
|
public function countAllOwners($limit = true,$stats_airline = '', $filter_name = '') { |
|
290
|
|
|
global $globalStatsFilters; |
|
291
|
|
|
if ($limit) $query = "SELECT owner_name, cnt AS owner_count FROM stats_owner WHERE stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY owner_count DESC LIMIT 10 OFFSET 0"; |
|
292
|
|
|
else $query = "SELECT owner_name, cnt AS owner_count FROM stats_owner WHERE stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY owner_count DESC"; |
|
293
|
|
|
try { |
|
294
|
|
|
$sth = $this->db->prepare($query); |
|
295
|
|
|
$sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name)); |
|
296
|
|
|
} catch(PDOException $e) { |
|
297
|
|
|
echo "error : ".$e->getMessage(); |
|
298
|
|
|
} |
|
299
|
|
|
$all = $sth->fetchAll(PDO::FETCH_ASSOC); |
|
300
|
|
|
if (empty($all)) { |
|
301
|
|
|
$filters = array('airlines' => array($stats_airline)); |
|
302
|
|
|
if ($filter_name != '') { |
|
303
|
|
|
$filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
|
304
|
|
|
} |
|
305
|
|
|
$Spotter = new Spotter($this->db); |
|
306
|
|
|
$all = $Spotter->countAllOwners($limit,0,'',$filters); |
|
307
|
|
|
} |
|
308
|
|
|
return $all; |
|
309
|
|
|
} |
|
310
|
|
|
public function countAllDepartureAirports($limit = true,$stats_airline = '',$filter_name = '') { |
|
311
|
|
|
global $globalStatsFilters; |
|
312
|
|
|
if ($limit) $query = "SELECT DISTINCT airport_icao AS airport_departure_icao,airport_city AS airport_departure_city,airport_country AS airport_departure_country,departure AS airport_departure_icao_count FROM stats_airport WHERE stats_type = 'yearly' AND stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY airport_departure_icao_count DESC LIMIT 10 OFFSET 0"; |
|
313
|
|
|
else $query = "SELECT DISTINCT airport_icao AS airport_departure_icao,airport_city AS airport_departure_city,airport_country AS airport_departure_country,departure AS airport_departure_icao_count FROM stats_airport WHERE stats_type = 'yearly' AND stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY airport_departure_icao_count DESC"; |
|
314
|
|
|
try { |
|
315
|
|
|
$sth = $this->db->prepare($query); |
|
316
|
|
|
$sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name)); |
|
317
|
|
|
} catch(PDOException $e) { |
|
318
|
|
|
echo "error : ".$e->getMessage(); |
|
319
|
|
|
} |
|
320
|
|
|
$all = $sth->fetchAll(PDO::FETCH_ASSOC); |
|
321
|
|
|
if (empty($all)) { |
|
322
|
|
|
$filters = array('airlines' => array($stats_airline)); |
|
323
|
|
|
if ($filter_name != '') { |
|
324
|
|
|
$filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
|
325
|
|
|
} |
|
326
|
|
|
$Spotter = new Spotter($this->db); |
|
327
|
|
|
$pall = $Spotter->countAllDepartureAirports($limit,0,'',$filters); |
|
328
|
|
|
$dall = $Spotter->countAllDetectedDepartureAirports($limit,0,'',$filters); |
|
329
|
|
|
$all = array(); |
|
330
|
|
|
foreach ($pall as $value) { |
|
331
|
|
|
$icao = $value['airport_departure_icao']; |
|
332
|
|
|
$all[$icao] = $value; |
|
333
|
|
|
} |
|
334
|
|
|
|
|
335
|
|
|
foreach ($dall as $value) { |
|
336
|
|
|
$icao = $value['airport_departure_icao']; |
|
337
|
|
|
if (isset($all[$icao])) { |
|
338
|
|
|
$all[$icao]['airport_departure_icao_count'] = $all[$icao]['airport_departure_icao_count'] + $value['airport_departure_icao_count']; |
|
339
|
|
|
} else $all[$icao] = $value; |
|
340
|
|
|
} |
|
341
|
|
|
$count = array(); |
|
342
|
|
|
foreach ($all as $key => $row) { |
|
343
|
|
|
$count[$key] = $row['airport_departure_icao_count']; |
|
344
|
|
|
} |
|
345
|
|
|
array_multisort($count,SORT_DESC,$all); |
|
346
|
|
|
} |
|
347
|
|
|
return $all; |
|
348
|
|
|
} |
|
349
|
|
|
public function countAllArrivalAirports($limit = true,$stats_airline = '',$filter_name = '') { |
|
350
|
|
|
global $globalStatsFilters; |
|
351
|
|
|
if ($limit) $query = "SELECT DISTINCT airport_icao AS airport_arrival_icao,airport_city AS airport_arrival_city,airport_country AS airport_arrival_country,arrival AS airport_arrival_icao_count FROM stats_airport WHERE stats_type = 'yearly' AND stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY airport_arrival_icao_count DESC LIMIT 10 OFFSET 0"; |
|
352
|
|
|
else $query = "SELECT DISTINCT airport_icao AS airport_arrival_icao,airport_city AS airport_arrival_city,airport_country AS airport_arrival_country,arrival AS airport_arrival_icao_count FROM stats_airport WHERE stats_type = 'yearly' AND stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY airport_arrival_icao_count DESC"; |
|
353
|
|
|
try { |
|
354
|
|
|
$sth = $this->db->prepare($query); |
|
355
|
|
|
$sth->execute(array(':stats_airline' => $stats_airline,':filter_name' => $filter_name)); |
|
356
|
|
|
} catch(PDOException $e) { |
|
357
|
|
|
echo "error : ".$e->getMessage(); |
|
358
|
|
|
} |
|
359
|
|
|
$all = $sth->fetchAll(PDO::FETCH_ASSOC); |
|
360
|
|
|
if (empty($all)) { |
|
361
|
|
|
$filters = array('airlines' => array($stats_airline)); |
|
362
|
|
|
if ($filter_name != '') { |
|
363
|
|
|
$filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
|
364
|
|
|
} |
|
365
|
|
|
$Spotter = new Spotter($this->db); |
|
366
|
|
|
$pall = $Spotter->countAllArrivalAirports($limit,0,'',false,$filters); |
|
367
|
|
|
$dall = $Spotter->countAllDetectedArrivalAirports($limit,0,'',false,$filters); |
|
368
|
|
|
$all = array(); |
|
369
|
|
|
foreach ($pall as $value) { |
|
370
|
|
|
$icao = $value['airport_arrival_icao']; |
|
371
|
|
|
$all[$icao] = $value; |
|
372
|
|
|
} |
|
373
|
|
|
|
|
374
|
|
|
foreach ($dall as $value) { |
|
375
|
|
|
$icao = $value['airport_arrival_icao']; |
|
376
|
|
|
if (isset($all[$icao])) { |
|
377
|
|
|
$all[$icao]['airport_arrival_icao_count'] = $all[$icao]['airport_arrival_icao_count'] + $value['airport_arrival_icao_count']; |
|
378
|
|
|
} else $all[$icao] = $value; |
|
379
|
|
|
} |
|
380
|
|
|
$count = array(); |
|
381
|
|
|
foreach ($all as $key => $row) { |
|
382
|
|
|
$count[$key] = $row['airport_arrival_icao_count']; |
|
383
|
|
|
} |
|
384
|
|
|
array_multisort($count,SORT_DESC,$all); |
|
385
|
|
|
} |
|
386
|
|
|
|
|
387
|
|
|
return $all; |
|
388
|
|
|
} |
|
389
|
|
|
public function countAllMonthsLastYear($limit = true,$stats_airline = '',$filter_name = '') { |
|
390
|
|
|
global $globalDBdriver, $globalStatsFilters; |
|
391
|
|
|
if ($globalDBdriver == 'mysql') { |
|
392
|
|
|
if ($limit) $query = "SELECT MONTH(stats_date) as month_name, YEAR(stats_date) as year_name, cnt as date_count FROM stats WHERE stats_type = 'flights_bymonth' AND stats_date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 12 MONTH) AND stats_airline = :stats_airline AND filter_name = :filter_name"; |
|
393
|
|
|
else $query = "SELECT MONTH(stats_date) as month_name, YEAR(stats_date) as year_name, cnt as date_count FROM stats WHERE stats_type = 'flights_bymonth' AND stats_airline = :stats_airline AND filter_name = :filter_name"; |
|
394
|
|
|
} else { |
|
395
|
|
|
if ($limit) $query = "SELECT EXTRACT(MONTH FROM stats_date) as month_name, EXTRACT(YEAR FROM stats_date) as year_name, cnt as date_count FROM stats WHERE stats_type = 'flights_bymonth' AND stats_date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '12 MONTHS' AND stats_airline = :stats_airline AND filter_name = :filter_name"; |
|
396
|
|
|
else $query = "SELECT EXTRACT(MONTH FROM stats_date) as month_name, EXTRACT(YEAR FROM stats_date) as year_name, cnt as date_count FROM stats WHERE stats_type = 'flights_bymonth' AND stats_airline = :stats_airline AND filter_name = :filter_name"; |
|
397
|
|
|
} |
|
398
|
|
|
$query_data = array(':stats_airline' => $stats_airline,':filter_name' => $filter_name); |
|
399
|
|
|
try { |
|
400
|
|
|
$sth = $this->db->prepare($query); |
|
401
|
|
|
$sth->execute($query_data); |
|
402
|
|
|
} catch(PDOException $e) { |
|
403
|
|
|
echo "error : ".$e->getMessage(); |
|
404
|
|
|
} |
|
405
|
|
|
$all = $sth->fetchAll(PDO::FETCH_ASSOC); |
|
406
|
|
|
if (empty($all)) { |
|
407
|
|
|
$filters = array('airlines' => array($stats_airline)); |
|
408
|
|
|
if ($filter_name != '') { |
|
409
|
|
|
$filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
|
410
|
|
|
} |
|
411
|
|
|
$Spotter = new Spotter($this->db); |
|
412
|
|
|
$all = $Spotter->countAllMonthsLastYear($filters); |
|
413
|
|
|
} |
|
414
|
|
|
|
|
415
|
|
|
return $all; |
|
416
|
|
|
} |
|
417
|
|
|
|
|
418
|
|
|
public function countAllDatesLastMonth($stats_airline = '',$filter_name = '') { |
|
419
|
|
|
global $globalStatsFilters; |
|
420
|
|
|
$query = "SELECT flight_date as date_name, cnt as date_count FROM stats_flight WHERE stats_type = 'month' AND stats_airline = :stats_airline AND filter_name = :filter_name"; |
|
421
|
|
|
$query_data = array(':stats_airline' => $stats_airline,':filter_name' => $filter_name); |
|
422
|
|
|
try { |
|
423
|
|
|
$sth = $this->db->prepare($query); |
|
424
|
|
|
$sth->execute($query_data); |
|
425
|
|
|
} catch(PDOException $e) { |
|
426
|
|
|
echo "error : ".$e->getMessage(); |
|
427
|
|
|
} |
|
428
|
|
|
$all = $sth->fetchAll(PDO::FETCH_ASSOC); |
|
429
|
|
|
if (empty($all)) { |
|
430
|
|
|
$filters = array('airlines' => array($stats_airline)); |
|
431
|
|
|
if ($filter_name != '') { |
|
432
|
|
|
$filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
|
433
|
|
|
} |
|
434
|
|
|
$Spotter = new Spotter($this->db); |
|
435
|
|
|
$all = $Spotter->countAllDatesLastMonth($filters); |
|
436
|
|
|
} |
|
437
|
|
|
return $all; |
|
438
|
|
|
} |
|
439
|
|
|
public function countAllDatesLast7Days($stats_airline = '',$filter_name = '') { |
|
440
|
|
|
global $globalDBdriver, $globalStatsFilters; |
|
441
|
|
|
if ($globalDBdriver == 'mysql') { |
|
442
|
|
|
$query = "SELECT flight_date as date_name, cnt as date_count FROM stats_flight WHERE stats_type = 'month' AND flight_date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 7 DAY) AND stats_airline = :stats_airline AND filter_name = :filter_name"; |
|
443
|
|
|
} else { |
|
444
|
|
|
$query = "SELECT flight_date as date_name, cnt as date_count FROM stats_flight WHERE stats_type = 'month' AND flight_date::timestamp >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '7 DAYS' AND stats_airline = :stats_airline AND filter_name = :filter_name"; |
|
445
|
|
|
} |
|
446
|
|
|
$query_data = array(':stats_airline' => $stats_airline,':filter_name' => $filter_name); |
|
447
|
|
|
try { |
|
448
|
|
|
$sth = $this->db->prepare($query); |
|
449
|
|
|
$sth->execute($query_data); |
|
450
|
|
|
} catch(PDOException $e) { |
|
451
|
|
|
echo "error : ".$e->getMessage(); |
|
452
|
|
|
} |
|
453
|
|
|
$all = $sth->fetchAll(PDO::FETCH_ASSOC); |
|
454
|
|
|
if (empty($all)) { |
|
455
|
|
|
$filters = array('airlines' => array($stats_airline)); |
|
456
|
|
|
if ($filter_name != '') { |
|
457
|
|
|
$filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
|
458
|
|
|
} |
|
459
|
|
|
$Spotter = new Spotter($this->db); |
|
460
|
|
|
$all = $Spotter->countAllDatesLast7Days($filters); |
|
461
|
|
|
} |
|
462
|
|
|
return $all; |
|
463
|
|
|
} |
|
464
|
|
|
public function countAllDates($stats_airline = '',$filter_name = '') { |
|
465
|
|
|
global $globalStatsFilters; |
|
466
|
|
|
$query = "SELECT flight_date as date_name, cnt as date_count FROM stats_flight WHERE stats_type = 'date' AND stats_airline = :stats_airline AND filter_name = :filter_name"; |
|
467
|
|
|
$query_data = array(':stats_airline' => $stats_airline,':filter_name' => $filter_name); |
|
468
|
|
|
try { |
|
469
|
|
|
$sth = $this->db->prepare($query); |
|
470
|
|
|
$sth->execute($query_data); |
|
471
|
|
|
} catch(PDOException $e) { |
|
472
|
|
|
echo "error : ".$e->getMessage(); |
|
473
|
|
|
} |
|
474
|
|
|
$all = $sth->fetchAll(PDO::FETCH_ASSOC); |
|
475
|
|
|
if (empty($all)) { |
|
476
|
|
|
$filters = array('airlines' => array($stats_airline)); |
|
477
|
|
|
if ($filter_name != '') { |
|
478
|
|
|
$filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
|
479
|
|
|
} |
|
480
|
|
|
$Spotter = new Spotter($this->db); |
|
481
|
|
|
$all = $Spotter->countAllDates($filters); |
|
482
|
|
|
} |
|
483
|
|
|
return $all; |
|
484
|
|
|
} |
|
485
|
|
|
public function countAllDatesByAirlines($filter_name = '') { |
|
486
|
|
|
$query = "SELECT stats_airline as airline_icao, flight_date as date_name, cnt as date_count FROM stats_flight WHERE stats_type = 'date' AND filter_name = :filter_name"; |
|
487
|
|
|
$query_data = array('filter_name' => $filter_name); |
|
488
|
|
|
try { |
|
489
|
|
|
$sth = $this->db->prepare($query); |
|
490
|
|
|
$sth->execute($query_data); |
|
491
|
|
|
} catch(PDOException $e) { |
|
492
|
|
|
echo "error : ".$e->getMessage(); |
|
493
|
|
|
} |
|
494
|
|
|
$all = $sth->fetchAll(PDO::FETCH_ASSOC); |
|
495
|
|
|
if (empty($all)) { |
|
496
|
|
|
$filters = array(); |
|
497
|
|
|
if ($filter_name != '') { |
|
498
|
|
|
$filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
|
|
|
|
|
|
499
|
|
|
} |
|
500
|
|
|
$Spotter = new Spotter($this->db); |
|
501
|
|
|
$all = $Spotter->countAllDatesByAirlines($filters); |
|
502
|
|
|
} |
|
503
|
|
|
return $all; |
|
504
|
|
|
} |
|
505
|
|
|
public function countAllMonths($stats_airline = '',$filter_name = '') { |
|
506
|
|
|
global $globalStatsFilters; |
|
507
|
|
|
$query = "SELECT YEAR(stats_date) AS year_name,MONTH(stats_date) AS month_name, cnt as date_count FROM stats WHERE stats_type = 'flights_bymonth' AND stats_airline = :stats_airline AND filter_name = :filter_name"; |
|
508
|
|
|
try { |
|
509
|
|
|
$sth = $this->db->prepare($query); |
|
510
|
|
|
$sth->execute(array(':stats_airline' => $stats_airline, ':filter_name' => $filter_name)); |
|
511
|
|
|
} catch(PDOException $e) { |
|
512
|
|
|
echo "error : ".$e->getMessage(); |
|
513
|
|
|
} |
|
514
|
|
|
$all = $sth->fetchAll(PDO::FETCH_ASSOC); |
|
515
|
|
|
if (empty($all)) { |
|
516
|
|
|
$filters = array('airlines' => array($stats_airline)); |
|
517
|
|
|
if ($filter_name != '') { |
|
518
|
|
|
$filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
|
519
|
|
|
} |
|
520
|
|
|
$Spotter = new Spotter($this->db); |
|
521
|
|
|
$all = $Spotter->countAllMonths($filters); |
|
522
|
|
|
} |
|
523
|
|
|
return $all; |
|
524
|
|
|
} |
|
525
|
|
|
public function countAllMilitaryMonths($filter_name = '') { |
|
526
|
|
|
global $globalStatsFilters; |
|
527
|
|
|
$query = "SELECT YEAR(stats_date) AS year_name,MONTH(stats_date) AS month_name, cnt as date_count FROM stats WHERE stats_type = 'military_flights_bymonth' AND filter_name = :filter_name"; |
|
528
|
|
|
try { |
|
529
|
|
|
$sth = $this->db->prepare($query); |
|
530
|
|
|
$sth->execute(array(':filter_name' => $filter_name)); |
|
531
|
|
|
} catch(PDOException $e) { |
|
532
|
|
|
echo "error : ".$e->getMessage(); |
|
533
|
|
|
} |
|
534
|
|
|
$all = $sth->fetchAll(PDO::FETCH_ASSOC); |
|
535
|
|
|
if (empty($all)) { |
|
536
|
|
|
$filters = array(); |
|
537
|
|
|
if ($filter_name != '') { |
|
538
|
|
|
$filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
|
539
|
|
|
} |
|
540
|
|
|
$Spotter = new Spotter($this->db); |
|
541
|
|
|
$all = $Spotter->countAllMilitaryMonths($filters); |
|
542
|
|
|
} |
|
543
|
|
|
return $all; |
|
544
|
|
|
} |
|
545
|
|
|
public function countAllHours($orderby = 'hour',$limit = true,$stats_airline = '',$filter_name = '') { |
|
546
|
|
|
global $globalTimezone, $globalDBdriver, $globalStatsFilters; |
|
547
|
|
|
|
|
548
|
|
|
if ($limit) $query = "SELECT flight_date as hour_name, cnt as hour_count FROM stats_flight WHERE stats_type = 'hour' AND stats_airline = :stats_airline AND filter_name = :filter_name"; |
|
549
|
|
|
else $query = "SELECT flight_date as hour_name, cnt as hour_count FROM stats_flight WHERE stats_type = 'hour' AND stats_airline = :stats_airline AND filter_name = :filter_name"; |
|
550
|
|
|
if ($orderby == 'hour') { |
|
551
|
|
|
if ($globalDBdriver == 'mysql') { |
|
552
|
|
|
$query .= " ORDER BY flight_date ASC"; |
|
553
|
|
|
} else { |
|
554
|
|
|
$query .= " ORDER BY CAST(flight_date AS integer) ASC"; |
|
555
|
|
|
} |
|
556
|
|
|
} |
|
557
|
|
|
if ($orderby == 'count') $query .= " ORDER BY hour_count DESC"; |
|
558
|
|
|
try { |
|
559
|
|
|
$sth = $this->db->prepare($query); |
|
560
|
|
|
$sth->execute(array(':stats_airline' => $stats_airline, ':filter_name' => $filter_name)); |
|
561
|
|
|
} catch(PDOException $e) { |
|
562
|
|
|
echo "error : ".$e->getMessage(); |
|
563
|
|
|
} |
|
564
|
|
|
$all = $sth->fetchAll(PDO::FETCH_ASSOC); |
|
565
|
|
|
if (empty($all)) { |
|
566
|
|
|
$filters = array('airlines' => array($stats_airline)); |
|
567
|
|
|
if ($filter_name != '') { |
|
568
|
|
|
$filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
|
569
|
|
|
} |
|
570
|
|
|
$Spotter = new Spotter($this->db); |
|
571
|
|
|
$all = $Spotter->countAllHours($orderby,$filters); |
|
572
|
|
|
} |
|
573
|
|
|
return $all; |
|
574
|
|
|
} |
|
575
|
|
|
|
|
576
|
|
|
public function countOverallFlights($stats_airline = '', $filter_name = '') { |
|
577
|
|
|
global $globalStatsFilters; |
|
578
|
|
|
$all = $this->getSumStats('flights_bymonth',date('Y'),$stats_airline,$filter_name); |
|
579
|
|
|
if (empty($all)) { |
|
580
|
|
|
$filters = array('airlines' => array($stats_airline)); |
|
581
|
|
|
if ($filter_name != '') { |
|
582
|
|
|
$filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
|
583
|
|
|
} |
|
584
|
|
|
$Spotter = new Spotter($this->db); |
|
585
|
|
|
$all = $Spotter->countOverallFlights($filters); |
|
586
|
|
|
} |
|
587
|
|
|
return $all; |
|
588
|
|
|
} |
|
589
|
|
|
public function countOverallMilitaryFlights($filter_name = '') { |
|
590
|
|
|
$all = $this->getSumStats('military_flights_bymonth',date('Y'),'',$filter_name); |
|
591
|
|
|
if (empty($all)) { |
|
592
|
|
|
$filters = array(); |
|
593
|
|
|
if ($filter_name != '') { |
|
594
|
|
|
$filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
|
|
|
|
|
|
595
|
|
|
} |
|
596
|
|
|
$Spotter = new Spotter($this->db); |
|
597
|
|
|
$all = $Spotter->countOverallMilitaryFlights($filters); |
|
598
|
|
|
} |
|
599
|
|
|
return $all; |
|
600
|
|
|
} |
|
601
|
|
|
public function countOverallArrival($stats_airline = '',$filter_name = '') { |
|
602
|
|
|
global $globalStatsFilters; |
|
603
|
|
|
$all = $this->getSumStats('realarrivals_bymonth',date('Y'),$stats_airline,$filter_name); |
|
604
|
|
|
if (empty($all)) { |
|
605
|
|
|
$filters = array('airlines' => array($stats_airline)); |
|
606
|
|
|
if ($filter_name != '') { |
|
607
|
|
|
$filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
|
608
|
|
|
} |
|
609
|
|
|
$Spotter = new Spotter($this->db); |
|
610
|
|
|
$all = $Spotter->countOverallArrival($filters); |
|
611
|
|
|
} |
|
612
|
|
|
return $all; |
|
613
|
|
|
} |
|
614
|
|
|
public function countOverallAircrafts($stats_airline = '',$filter_name = '') { |
|
615
|
|
|
global $globalStatsFilters; |
|
616
|
|
|
$all = $this->getSumStats('aircrafts_bymonth',date('Y'),$stats_airline,$filter_name); |
|
617
|
|
|
if (empty($all)) { |
|
618
|
|
|
$filters = array('airlines' => array($stats_airline)); |
|
619
|
|
|
if ($filter_name != '') { |
|
620
|
|
|
$filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
|
621
|
|
|
} |
|
622
|
|
|
$Spotter = new Spotter($this->db); |
|
623
|
|
|
$all = $Spotter->countOverallAircrafts($filters); |
|
624
|
|
|
} |
|
625
|
|
|
return $all; |
|
626
|
|
|
} |
|
627
|
|
|
public function countOverallAirlines($filter_name = '') { |
|
628
|
|
|
$query = "SELECT COUNT(*) AS nb_airline FROM stats_airline WHERE filter_name = :filter_name"; |
|
629
|
|
|
try { |
|
630
|
|
|
$sth = $this->db->prepare($query); |
|
631
|
|
|
$sth->execute(array(':filter_name' => $filter_name)); |
|
632
|
|
|
} catch(PDOException $e) { |
|
633
|
|
|
echo "error : ".$e->getMessage(); |
|
634
|
|
|
} |
|
635
|
|
|
$result = $sth->fetchAll(PDO::FETCH_ASSOC); |
|
636
|
|
|
$all = $result[0]['nb_airline']; |
|
637
|
|
|
//$all = $this->getSumStats('airlines_bymonth',date('Y')); |
|
638
|
|
|
if (empty($all)) { |
|
639
|
|
|
$filters = array(); |
|
640
|
|
|
if ($filter_name != '') { |
|
641
|
|
|
$filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
|
|
|
|
|
|
642
|
|
|
} |
|
643
|
|
|
$Spotter = new Spotter($this->db); |
|
644
|
|
|
$all = $Spotter->countOverallAirlines($filters); |
|
645
|
|
|
} |
|
646
|
|
|
return $all; |
|
647
|
|
|
} |
|
648
|
|
|
public function countOverallOwners($stats_airline = '',$filter_name = '') { |
|
649
|
|
|
global $globalStatsFilters; |
|
650
|
|
|
/* |
|
651
|
|
|
$query = "SELECT COUNT(*) AS nb_owner FROM stats_owner"; |
|
652
|
|
|
try { |
|
653
|
|
|
$sth = $this->db->prepare($query); |
|
654
|
|
|
$sth->execute(); |
|
655
|
|
|
} catch(PDOException $e) { |
|
656
|
|
|
echo "error : ".$e->getMessage(); |
|
657
|
|
|
} |
|
658
|
|
|
$result = $sth->fetchAll(PDO::FETCH_ASSOC); |
|
659
|
|
|
$all = $result[0]['nb_owner']; |
|
660
|
|
|
*/ |
|
661
|
|
|
$all = $this->getSumStats('owners_bymonth',date('Y'),$stats_airline,$filter_name); |
|
662
|
|
|
if (empty($all)) { |
|
663
|
|
|
$filters = array('airlines' => array($stats_airline)); |
|
664
|
|
|
if ($filter_name != '') { |
|
665
|
|
|
$filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
|
666
|
|
|
} |
|
667
|
|
|
$Spotter = new Spotter($this->db); |
|
668
|
|
|
$all = $Spotter->countOverallOwners($filters); |
|
669
|
|
|
} |
|
670
|
|
|
return $all; |
|
671
|
|
|
} |
|
672
|
|
|
public function countOverallPilots($stats_airline = '',$filter_name = '') { |
|
673
|
|
|
global $globalStatsFilters; |
|
674
|
|
|
$all = $this->getSumStats('pilots_bymonth',date('Y'),$stats_airline,$filter_name); |
|
675
|
|
|
if (empty($all)) { |
|
676
|
|
|
$filters = array('airlines' => array($stats_airline)); |
|
677
|
|
|
if ($filter_name != '') { |
|
678
|
|
|
$filters = array_merge($filters,$globalStatsFilters[$filter_name]); |
|
679
|
|
|
} |
|
680
|
|
|
$Spotter = new Spotter($this->db); |
|
681
|
|
|
$all = $Spotter->countOverallPilots($filters); |
|
682
|
|
|
} |
|
683
|
|
|
return $all; |
|
684
|
|
|
} |
|
685
|
|
|
|
|
686
|
|
|
public function getLast7DaysAirports($airport_icao = '', $stats_airline = '',$filter_name = '') { |
|
687
|
|
|
$query = "SELECT * FROM stats_airport WHERE stats_type = 'daily' AND airport_icao = :airport_icao AND stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY date"; |
|
688
|
|
|
$query_values = array(':airport_icao' => $airport_icao,':stats_airline' => $stats_airline, ':filter_name' => $filter_name); |
|
689
|
|
|
try { |
|
690
|
|
|
$sth = $this->db->prepare($query); |
|
691
|
|
|
$sth->execute($query_values); |
|
692
|
|
|
} catch(PDOException $e) { |
|
693
|
|
|
echo "error : ".$e->getMessage(); |
|
694
|
|
|
} |
|
695
|
|
|
$all = $sth->fetchAll(PDO::FETCH_ASSOC); |
|
696
|
|
|
return $all; |
|
697
|
|
|
} |
|
698
|
|
|
public function getStats($type,$stats_airline = '', $filter_name = '') { |
|
699
|
|
|
$query = "SELECT * FROM stats WHERE stats_type = :type AND stats_airline = :stats_airline AND filter_name = :filter_name ORDER BY stats_date"; |
|
700
|
|
|
$query_values = array(':type' => $type,':stats_airline' => $stats_airline,':filter_name' => $filter_name); |
|
701
|
|
|
try { |
|
702
|
|
|
$sth = $this->db->prepare($query); |
|
703
|
|
|
$sth->execute($query_values); |
|
704
|
|
|
} catch(PDOException $e) { |
|
705
|
|
|
echo "error : ".$e->getMessage(); |
|
706
|
|
|
} |
|
707
|
|
|
$all = $sth->fetchAll(PDO::FETCH_ASSOC); |
|
708
|
|
|
return $all; |
|
709
|
|
|
} |
|
710
|
|
|
public function getSumStats($type,$year,$stats_airline = '',$filter_name = '') { |
|
711
|
|
|
global $globalArchiveMonths, $globalDBdriver; |
|
712
|
|
|
if ($globalDBdriver == 'mysql') { |
|
713
|
|
|
$query = "SELECT SUM(cnt) as total FROM stats WHERE stats_type = :type AND YEAR(stats_date) = :year AND stats_airline = :stats_airline AND filter_name = :filter_name"; |
|
714
|
|
|
} else { |
|
715
|
|
|
$query = "SELECT SUM(cnt) as total FROM stats WHERE stats_type = :type AND EXTRACT(YEAR FROM stats_date) = :year AND stats_airline = :stats_airline AND filter_name = :filter_name"; |
|
716
|
|
|
} |
|
717
|
|
|
$query_values = array(':type' => $type, ':year' => $year, ':stats_airline' => $stats_airline,':filter_name' => $filter_name); |
|
718
|
|
|
try { |
|
719
|
|
|
$sth = $this->db->prepare($query); |
|
720
|
|
|
$sth->execute($query_values); |
|
721
|
|
|
} catch(PDOException $e) { |
|
722
|
|
|
echo "error : ".$e->getMessage(); |
|
723
|
|
|
} |
|
724
|
|
|
$all = $sth->fetchAll(PDO::FETCH_ASSOC); |
|
725
|
|
|
return $all[0]['total']; |
|
726
|
|
|
} |
|
727
|
|
|
public function getStatsTotal($type, $stats_airline = '', $filter_name = '') { |
|
728
|
|
|
global $globalArchiveMonths, $globalDBdriver; |
|
729
|
|
|
if ($globalDBdriver == 'mysql') { |
|
730
|
|
|
$query = "SELECT SUM(cnt) as total FROM stats WHERE stats_type = :type AND stats_date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL ".$globalArchiveMonths." MONTH) AND stats_airline = :stats_airline AND filter_name = :filter_name"; |
|
731
|
|
|
} else { |
|
732
|
|
|
$query = "SELECT SUM(cnt) as total FROM stats WHERE stats_type = :type AND stats_date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalArchiveMonths." MONTHS' AND stats_airline = :stats_airline AND filter_name = :filter_name"; |
|
733
|
|
|
} |
|
734
|
|
|
$query_values = array(':type' => $type, ':stats_airline' => $stats_airline, ':filter_name' => $filter_name); |
|
735
|
|
|
try { |
|
736
|
|
|
$sth = $this->db->prepare($query); |
|
737
|
|
|
$sth->execute($query_values); |
|
738
|
|
|
} catch(PDOException $e) { |
|
739
|
|
|
echo "error : ".$e->getMessage(); |
|
740
|
|
|
} |
|
741
|
|
|
$all = $sth->fetchAll(PDO::FETCH_ASSOC); |
|
742
|
|
|
return $all[0]['total']; |
|
743
|
|
|
} |
|
744
|
|
|
public function getStatsAircraftTotal($stats_airline = '', $filter_name = '') { |
|
745
|
|
|
global $globalArchiveMonths, $globalDBdriver; |
|
746
|
|
|
if ($globalDBdriver == 'mysql') { |
|
747
|
|
|
$query = "SELECT SUM(cnt) as total FROM stats_aircraft WHERE stats_airline = :stats_airline AND filter_name = :filter_name"; |
|
748
|
|
|
} else { |
|
749
|
|
|
$query = "SELECT SUM(cnt) as total FROM stats_aircraft WHERE stats_airline = :stats_airline AND filter_name = :filter_name"; |
|
750
|
|
|
} |
|
751
|
|
|
try { |
|
752
|
|
|
$sth = $this->db->prepare($query); |
|
753
|
|
|
$sth->execute(array(':stats_airline' => $stats_airline, ':filter_name' => $filter_name)); |
|
754
|
|
|
} catch(PDOException $e) { |
|
755
|
|
|
echo "error : ".$e->getMessage(); |
|
756
|
|
|
} |
|
757
|
|
|
$all = $sth->fetchAll(PDO::FETCH_ASSOC); |
|
758
|
|
|
return $all[0]['total']; |
|
759
|
|
|
} |
|
760
|
|
|
public function getStatsAirlineTotal($filter_name = '') { |
|
761
|
|
|
global $globalArchiveMonths, $globalDBdriver; |
|
762
|
|
|
if ($globalDBdriver == 'mysql') { |
|
763
|
|
|
$query = "SELECT SUM(cnt) as total FROM stats_airline WHERE filter_name = :filter_name"; |
|
764
|
|
|
} else { |
|
765
|
|
|
$query = "SELECT SUM(cnt) as total FROM stats_airline WHERE filter_name = :filter_name"; |
|
766
|
|
|
} |
|
767
|
|
|
try { |
|
768
|
|
|
$sth = $this->db->prepare($query); |
|
769
|
|
|
$sth->execute(array(':filter_name' => $filter_name)); |
|
770
|
|
|
} catch(PDOException $e) { |
|
771
|
|
|
echo "error : ".$e->getMessage(); |
|
772
|
|
|
} |
|
773
|
|
|
$all = $sth->fetchAll(PDO::FETCH_ASSOC); |
|
774
|
|
|
return $all[0]['total']; |
|
775
|
|
|
} |
|
776
|
|
|
public function getStatsOwnerTotal($filter_name = '') { |
|
777
|
|
|
global $globalArchiveMonths, $globalDBdriver; |
|
778
|
|
|
if ($globalDBdriver == 'mysql') { |
|
779
|
|
|
$query = "SELECT SUM(cnt) as total FROM stats_owner WHERE filter_name = :filter_name"; |
|
780
|
|
|
} else { |
|
781
|
|
|
$query = "SELECT SUM(cnt) as total FROM stats_owner WHERE filter_name = :filter_name"; |
|
782
|
|
|
} |
|
783
|
|
|
try { |
|
784
|
|
|
$sth = $this->db->prepare($query); |
|
785
|
|
|
$sth->execute(array(':filter_name' => $filter_name)); |
|
786
|
|
|
} catch(PDOException $e) { |
|
787
|
|
|
echo "error : ".$e->getMessage(); |
|
788
|
|
|
} |
|
789
|
|
|
$all = $sth->fetchAll(PDO::FETCH_ASSOC); |
|
790
|
|
|
return $all[0]['total']; |
|
791
|
|
|
} |
|
792
|
|
|
public function getStatsPilotTotal($filter_name = '') { |
|
793
|
|
|
global $globalArchiveMonths, $globalDBdriver; |
|
794
|
|
|
if ($globalDBdriver == 'mysql') { |
|
795
|
|
|
$query = "SELECT SUM(cnt) as total FROM stats_pilot WHERE filter_name = :filter_name"; |
|
796
|
|
|
} else { |
|
797
|
|
|
$query = "SELECT SUM(cnt) as total FROM stats_pilot WHERE filter_name = :filter_name"; |
|
798
|
|
|
} |
|
799
|
|
|
try { |
|
800
|
|
|
$sth = $this->db->prepare($query); |
|
801
|
|
|
$sth->execute(array(':filter_name' => $filter_name)); |
|
802
|
|
|
} catch(PDOException $e) { |
|
803
|
|
|
echo "error : ".$e->getMessage(); |
|
804
|
|
|
} |
|
805
|
|
|
$all = $sth->fetchAll(PDO::FETCH_ASSOC); |
|
806
|
|
|
return $all[0]['total']; |
|
807
|
|
|
} |
|
808
|
|
|
|
|
809
|
|
|
public function addStat($type,$cnt,$stats_date,$stats_airline = '',$filter_name = '') { |
|
810
|
|
|
global $globalDBdriver; |
|
811
|
|
|
if ($globalDBdriver == 'mysql') { |
|
812
|
|
|
$query = "INSERT INTO stats (stats_type,cnt,stats_date,stats_airline,filter_name) VALUES (:type,:cnt,:stats_date,:stats_airline,:filter_name) ON DUPLICATE KEY UPDATE cnt = :cnt"; |
|
813
|
|
|
} else { |
|
814
|
|
|
$query = "UPDATE stats SET cnt = :cnt WHERE stats_type = :type AND stats_date = :stats_date AND stats_airline = :stats_airline AND filter_name = :filter_name; INSERT INTO stats (stats_type,cnt,stats_date,stats_airline,filter_name) SELECT :type,:cnt,:stats_date,:stats_airline,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats WHERE stats_type = :type AND stats_date = :stats_date AND stats_airline = :stats_airline AND filter_name = :filter_name);"; |
|
815
|
|
|
} |
|
816
|
|
|
$query_values = array(':type' => $type,':cnt' => $cnt,':stats_date' => $stats_date, ':stats_airline' => $stats_airline,':filter_name' => $filter_name); |
|
817
|
|
|
try { |
|
818
|
|
|
$sth = $this->db->prepare($query); |
|
819
|
|
|
$sth->execute($query_values); |
|
820
|
|
|
} catch(PDOException $e) { |
|
821
|
|
|
return "error : ".$e->getMessage(); |
|
822
|
|
|
} |
|
823
|
|
|
} |
|
824
|
|
|
public function updateStat($type,$cnt,$stats_date,$stats_airline = '',$filter_name = '') { |
|
825
|
|
|
global $globalDBdriver; |
|
826
|
|
|
if ($globalDBdriver == 'mysql') { |
|
827
|
|
|
$query = "INSERT INTO stats (stats_type,cnt,stats_date,stats_airline,filter_name) VALUES (:type,:cnt,:stats_date,:stats_airline,:filter_name) ON DUPLICATE KEY UPDATE cnt = cnt+:cnt, stats_date = :date"; |
|
828
|
|
|
} else { |
|
829
|
|
|
//$query = "INSERT INTO stats (stats_type,cnt,stats_date) VALUES (:type,:cnt,:stats_date) ON DUPLICATE KEY UPDATE cnt = cnt+:cnt, stats_date = :date"; |
|
830
|
|
|
$query = "UPDATE stats SET cnt = cnt+:cnt WHERE stats_type = :type AND stats_date = :stats_date AND stats_airline = :stats_airline AND filter_name = :filter_name; INSERT INTO stats (stats_type,cnt,stats_date,stats_airline,filter_name) SELECT :type,:cnt,:stats_date,:stats_airline,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats WHERE stats_type = :type AND stats_date = :stats_date AND stats_airline = :stats_airline AND filter_name = :filter_name);"; |
|
831
|
|
|
} |
|
832
|
|
|
$query_values = array(':type' => $type,':cnt' => $cnt,':stats_date' => $stats_date,':stats_airline' => $stats_airline,':filter_name' => $filter_name); |
|
833
|
|
|
try { |
|
834
|
|
|
$sth = $this->db->prepare($query); |
|
835
|
|
|
$sth->execute($query_values); |
|
836
|
|
|
} catch(PDOException $e) { |
|
837
|
|
|
return "error : ".$e->getMessage(); |
|
838
|
|
|
} |
|
839
|
|
|
} |
|
840
|
|
|
public function getStatsSource($date,$stats_type = '') { |
|
841
|
|
|
if ($stats_type == '') { |
|
842
|
|
|
$query = "SELECT * FROM stats_source WHERE stats_date = :date ORDER BY source_name"; |
|
843
|
|
|
$query_values = array(':date' => $date); |
|
844
|
|
|
} else { |
|
845
|
|
|
$query = "SELECT * FROM stats_source WHERE stats_date = :date AND stats_type = :stats_type ORDER BY source_name"; |
|
846
|
|
|
$query_values = array(':date' => $date,':stats_type' => $stats_type); |
|
847
|
|
|
} |
|
848
|
|
|
try { |
|
849
|
|
|
$sth = $this->db->prepare($query); |
|
850
|
|
|
$sth->execute($query_values); |
|
851
|
|
|
} catch(PDOException $e) { |
|
852
|
|
|
echo "error : ".$e->getMessage(); |
|
853
|
|
|
} |
|
854
|
|
|
$all = $sth->fetchAll(PDO::FETCH_ASSOC); |
|
855
|
|
|
return $all; |
|
856
|
|
|
} |
|
857
|
|
|
|
|
858
|
|
|
public function addStatSource($data,$source_name,$stats_type,$date) { |
|
859
|
|
|
global $globalDBdriver; |
|
860
|
|
|
if ($globalDBdriver == 'mysql') { |
|
861
|
|
|
$query = "INSERT INTO stats_source (source_data,source_name,stats_type,stats_date) VALUES (:data,:source_name,:stats_type,:stats_date) ON DUPLICATE KEY UPDATE source_data = :data"; |
|
862
|
|
|
} else { |
|
863
|
|
|
$query = "UPDATE stats_source SET source_data = :data WHERE stats_date = :stats_date AND source_name = :source_name AND stats_type = :stats_type; INSERT INTO stats_source (source_data,source_name,stats_type,stats_date) SELECT :data,:source_name,:stats_type,:stats_date WHERE NOT EXISTS (SELECT 1 FROM stats_source WHERE stats_date = :stats_date AND source_name = :source_name AND stats_type = :stats_type);"; |
|
864
|
|
|
} |
|
865
|
|
|
$query_values = array(':data' => $data,':stats_date' => $date,':source_name' => $source_name,':stats_type' => $stats_type); |
|
866
|
|
|
try { |
|
867
|
|
|
$sth = $this->db->prepare($query); |
|
868
|
|
|
$sth->execute($query_values); |
|
869
|
|
|
} catch(PDOException $e) { |
|
870
|
|
|
return "error : ".$e->getMessage(); |
|
871
|
|
|
} |
|
872
|
|
|
} |
|
873
|
|
|
public function addStatFlight($type,$date_name,$cnt,$stats_airline = '',$filter_name = '') { |
|
874
|
|
|
$query = "INSERT INTO stats_flight (stats_type,flight_date,cnt,stats_airline,filter_name) VALUES (:type,:flight_date,:cnt,:stats_airline,:filter_name)"; |
|
875
|
|
|
$query_values = array(':type' => $type,':flight_date' => $date_name,':cnt' => $cnt, ':stats_airline' => $stats_airline,':filter_name' => $filter_name); |
|
876
|
|
|
try { |
|
877
|
|
|
$sth = $this->db->prepare($query); |
|
878
|
|
|
$sth->execute($query_values); |
|
879
|
|
|
} catch(PDOException $e) { |
|
880
|
|
|
return "error : ".$e->getMessage(); |
|
881
|
|
|
} |
|
882
|
|
|
} |
|
883
|
|
|
public function addStatAircraftRegistration($registration,$cnt,$aircraft_icao = '',$airline_icao = '',$filter_name = '') { |
|
884
|
|
|
global $globalDBdriver; |
|
885
|
|
|
if ($globalDBdriver == 'mysql') { |
|
886
|
|
|
$query = "INSERT INTO stats_registration (aircraft_icao,registration,cnt,stats_airline,filter_name) VALUES (:aircraft_icao,:registration,:cnt,:stats_airline,:filter_name) ON DUPLICATE KEY UPDATE cnt = cnt+:cnt"; |
|
887
|
|
|
} else { |
|
888
|
|
|
$query = "UPDATE stats_registration SET cnt = cnt+:cnt WHERE registration = :registration AND stats_airline = :stats_airline AND filter_name = :filter_name; INSERT INTO stats_registration (aircraft_icao,registration,cnt,stats_airline,filter_name) SELECT :aircraft_icao,:registration,:cnt,:stats_airline,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats_registration WHERE registration = :registration AND stats_airline = :stats_airline AND filter_name = :filter_name);"; |
|
889
|
|
|
} |
|
890
|
|
|
$query_values = array(':aircraft_icao' => $aircraft_icao,':registration' => $registration,':cnt' => $cnt,':stats_airline' => $airline_icao, ':filter_name' => $filter_name); |
|
891
|
|
|
try { |
|
892
|
|
|
$sth = $this->db->prepare($query); |
|
893
|
|
|
$sth->execute($query_values); |
|
894
|
|
|
} catch(PDOException $e) { |
|
895
|
|
|
return "error : ".$e->getMessage(); |
|
896
|
|
|
} |
|
897
|
|
|
} |
|
898
|
|
|
public function addStatCallsign($callsign_icao,$cnt,$airline_icao = '', $filter_name = '') { |
|
899
|
|
|
global $globalDBdriver; |
|
900
|
|
|
if ($globalDBdriver == 'mysql') { |
|
901
|
|
|
$query = "INSERT INTO stats_callsign (callsign_icao,airline_icao,cnt,filter_name) VALUES (:callsign_icao,:airline_icao,:cnt,:filter_name) ON DUPLICATE KEY UPDATE cnt = cnt+:cnt"; |
|
902
|
|
|
} else { |
|
903
|
|
|
$query = "UPDATE stats_callsign SET cnt = cnt+:cnt WHERE callsign_icao = :callsign_icao AND filter_name = :filter_name; INSERT INTO stats_callsign (callsign_icao,airline_icao,cnt,filter_name) SELECT :callsign_icao,:airline_icao,:cnt,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats_callsign WHERE callsign_icao = :callsign_icao AND filter_name = :filter_name);"; |
|
904
|
|
|
} |
|
905
|
|
|
$query_values = array(':callsign_icao' => $callsign_icao,':airline_icao' => $airline_icao,':cnt' => $cnt, ':filter_name' => $filter_name); |
|
906
|
|
|
try { |
|
907
|
|
|
$sth = $this->db->prepare($query); |
|
908
|
|
|
$sth->execute($query_values); |
|
909
|
|
|
} catch(PDOException $e) { |
|
910
|
|
|
return "error : ".$e->getMessage(); |
|
911
|
|
|
} |
|
912
|
|
|
} |
|
913
|
|
|
public function addStatCountry($iso2,$iso3,$name,$cnt,$filter_name = '') { |
|
914
|
|
|
global $globalDBdriver; |
|
915
|
|
|
if ($globalDBdriver == 'mysql') { |
|
916
|
|
|
$query = "INSERT INTO stats_country (iso2,iso3,name,cnt,filter_name) VALUES (:iso2,:iso3,:name,:cnt,:filter_name) ON DUPLICATE KEY UPDATE cnt = cnt+:cnt"; |
|
917
|
|
|
} else { |
|
918
|
|
|
$query = "UPDATE stats_country SET cnt = cnt+:cnt WHERE iso2 = :iso2 AND filter_name = :filter_name; INSERT INTO stats_country (iso2,iso3,name,cnt,filter_name) SELECT :iso2,:iso3,:name,:cnt,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats_country WHERE iso2 = :iso2 AND filter_name = :filter_name);"; |
|
919
|
|
|
} |
|
920
|
|
|
$query_values = array(':iso2' => $iso2,':iso3' => $iso3,':name' => $name,':cnt' => $cnt,':filter_name' => $filter_name); |
|
921
|
|
|
try { |
|
922
|
|
|
$sth = $this->db->prepare($query); |
|
923
|
|
|
$sth->execute($query_values); |
|
924
|
|
|
} catch(PDOException $e) { |
|
925
|
|
|
return "error : ".$e->getMessage(); |
|
926
|
|
|
} |
|
927
|
|
|
} |
|
928
|
|
|
public function addStatAircraft($aircraft_icao,$cnt,$aircraft_name = '',$aircraft_manufacturer = '', $airline_icao = '', $filter_name = '') { |
|
929
|
|
|
global $globalDBdriver; |
|
930
|
|
|
if ($globalDBdriver == 'mysql') { |
|
931
|
|
|
$query = "INSERT INTO stats_aircraft (aircraft_icao,aircraft_name,aircraft_manufacturer,cnt,stats_airline, filter_name) VALUES (:aircraft_icao,:aircraft_name,:aircraft_manufacturer,:cnt,:stats_airline,:filter_name) ON DUPLICATE KEY UPDATE cnt = cnt+:cnt, aircraft_name = :aircraft_name, aircraft_manufacturer = :aircraft_manufacturer, stats_airline = :stats_airline"; |
|
932
|
|
|
} else { |
|
933
|
|
|
$query = "UPDATE stats_aircraft SET cnt = cnt+:cnt, aircraft_name = :aircraft_name, aircraft_manufacturer = :aircraft_manufacturer, filter_name = :filter_name WHERE aircraft_icao = :aircraft_icao AND stats_airline = :stats_airline AND filter_name = :filter_name; INSERT INTO stats_aircraft (aircraft_icao,aircraft_name,aircraft_manufacturer,cnt,stats_airline,filter_name) SELECT :aircraft_icao,:aircraft_name,:aircraft_manufacturer,:cnt,:stats_airline,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats_aircraft WHERE aircraft_icao = :aircraft_icao AND stats_airline = :stats_airline AND filter_name = :filter_name);"; |
|
934
|
|
|
} |
|
935
|
|
|
$query_values = array(':aircraft_icao' => $aircraft_icao,':aircraft_name' => $aircraft_name,':cnt' => $cnt, ':aircraft_manufacturer' => $aircraft_manufacturer,':stats_airline' => $airline_icao, ':filter_name' => $filter_name); |
|
936
|
|
|
try { |
|
937
|
|
|
$sth = $this->db->prepare($query); |
|
938
|
|
|
$sth->execute($query_values); |
|
939
|
|
|
} catch(PDOException $e) { |
|
940
|
|
|
return "error : ".$e->getMessage(); |
|
941
|
|
|
} |
|
942
|
|
|
} |
|
943
|
|
|
public function addStatAirline($airline_icao,$cnt,$airline_name = '',$filter_name = '') { |
|
944
|
|
|
global $globalDBdriver; |
|
945
|
|
|
if ($globalDBdriver == 'mysql') { |
|
946
|
|
|
$query = "INSERT INTO stats_airline (airline_icao,airline_name,cnt,filter_name) VALUES (:airline_icao,:airline_name,:cnt,:filter_name) ON DUPLICATE KEY UPDATE cnt = cnt+:cnt,airline_name = :airline_name"; |
|
947
|
|
|
} else { |
|
948
|
|
|
$query = "UPDATE stats_airline SET cnt = cnt+:cnt WHERE airline_icao = :airline_icao AND filter_name = :filter_name; INSERT INTO stats_airline (airline_icao,airline_name,cnt,filter_name) SELECT :airline_icao,:airline_name,:cnt,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats_airline WHERE airline_icao = :airline_icao AND filter_name = :filter_name);"; |
|
949
|
|
|
} |
|
950
|
|
|
$query_values = array(':airline_icao' => $airline_icao,':airline_name' => $airline_name,':cnt' => $cnt,':filter_name' => $filter_name); |
|
951
|
|
|
try { |
|
952
|
|
|
$sth = $this->db->prepare($query); |
|
953
|
|
|
$sth->execute($query_values); |
|
954
|
|
|
} catch(PDOException $e) { |
|
955
|
|
|
return "error : ".$e->getMessage(); |
|
956
|
|
|
} |
|
957
|
|
|
} |
|
958
|
|
|
public function addStatOwner($owner_name,$cnt,$stats_airline = '', $filter_name = '') { |
|
959
|
|
|
global $globalDBdriver; |
|
960
|
|
|
if ($globalDBdriver == 'mysql') { |
|
961
|
|
|
$query = "INSERT INTO stats_owner (owner_name,cnt,stats_airline,filter_name) VALUES (:owner_name,:cnt,:stats_airline,:filter_name) ON DUPLICATE KEY UPDATE cnt = cnt+:cnt"; |
|
962
|
|
|
} else { |
|
963
|
|
|
$query = "UPDATE stats_owner SET cnt = cnt+:cnt WHERE owner_name = :owner_name AND stats_airline = :stats_airline AND filter_name = :filter_name; INSERT INTO stats_owner (owner_name,cnt,stats_airline,filter_name) SELECT :owner_name,:cnt,:stats_airline,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats_owner WHERE owner_name = :owner_name AND stats_airline = :stats_airline AND filter_name = :filter_name);"; |
|
964
|
|
|
} |
|
965
|
|
|
$query_values = array(':owner_name' => $owner_name,':cnt' => $cnt,':stats_airline' => $stats_airline,':filter_name' => $filter_name); |
|
966
|
|
|
try { |
|
967
|
|
|
$sth = $this->db->prepare($query); |
|
968
|
|
|
$sth->execute($query_values); |
|
969
|
|
|
} catch(PDOException $e) { |
|
970
|
|
|
return "error : ".$e->getMessage(); |
|
971
|
|
|
} |
|
972
|
|
|
} |
|
973
|
|
|
public function addStatPilot($pilot_id,$cnt,$pilot_name,$stats_airline = '',$filter_name = '') { |
|
974
|
|
|
global $globalDBdriver; |
|
975
|
|
|
if ($globalDBdriver == 'mysql') { |
|
976
|
|
|
$query = "INSERT INTO stats_pilot (pilot_id,cnt,pilot_name,stats_airline,filter_name) VALUES (:pilot_id,:cnt,:pilot_name,:stats_airline,:filter_name) ON DUPLICATE KEY UPDATE cnt = cnt+:cnt, pilot_name = :pilot_name"; |
|
977
|
|
|
} else { |
|
978
|
|
|
$query = "UPDATE stats_pilot SET cnt = cnt+:cnt, pilot_name = :pilot_name WHERE pilot_id = :pilot_id AND stats_airline = :stats_airline AND filter_name = :filter_name; INSERT INTO stats_pilot (pilot_id,cnt,pilot_name,stats_airline,filter_name) SELECT :pilot_id,:cnt,:pilot_name,:stats_airline,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats_pilot WHERE pilot_id = :pilot_id AND stats_airline = :stats_airline AND filter_name = :filter_name);"; |
|
979
|
|
|
} |
|
980
|
|
|
$query_values = array(':pilot_id' => $pilot_id,':cnt' => $cnt,':pilot_name' => $pilot_name,':stats_airline' => $stats_airline,':filter_name' => $filter_name); |
|
981
|
|
|
try { |
|
982
|
|
|
$sth = $this->db->prepare($query); |
|
983
|
|
|
$sth->execute($query_values); |
|
984
|
|
|
} catch(PDOException $e) { |
|
985
|
|
|
return "error : ".$e->getMessage(); |
|
986
|
|
|
} |
|
987
|
|
|
} |
|
988
|
|
|
public function addStatDepartureAirports($airport_icao,$airport_name,$airport_city,$airport_country,$departure,$airline_icao = '',$filter_name = '') { |
|
989
|
|
|
global $globalDBdriver; |
|
990
|
|
|
if ($globalDBdriver == 'mysql') { |
|
991
|
|
|
$query = "INSERT INTO stats_airport (airport_icao,airport_name,airport_city,airport_country,departure,stats_type,date,stats_airline,filter_name) VALUES (:airport_icao,:airport_name,:airport_city,:airport_country,:departure,'yearly',:date,:stats_airline,:filter_name) ON DUPLICATE KEY UPDATE departure = departure+:departure"; |
|
992
|
|
|
} else { |
|
993
|
|
|
$query = "UPDATE stats_airport SET departure = departure+:departure WHERE airport_icao = :airport_icao AND stats_type = 'yearly' AND stats_airline = :stats_airline AND date = :date AND filter_name = :filter_name; INSERT INTO stats_airport (airport_icao,airport_name,airport_city,airport_country,departure,stats_type,date,stats_airline,filter_name) SELECT :airport_icao,:airport_name,:airport_city,:airport_country,:departure,'yearly',:date,:stats_airline,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats_airport WHERE airport_icao = :airport_icao AND stats_type = 'yearly' AND stats_airline = :stats_airline AND date = :date AND filter_name = :filter_name);"; |
|
994
|
|
|
} |
|
995
|
|
|
$query_values = array(':airport_icao' => $airport_icao,':airport_name' => $airport_name,':airport_city' => $airport_city,':airport_country' => $airport_country,':departure' => $departure,':date' => date('Y').'-01-01 00:00:00', ':stats_airline' => $airline_icao,':filter_name' => $filter_name); |
|
996
|
|
|
try { |
|
997
|
|
|
$sth = $this->db->prepare($query); |
|
998
|
|
|
$sth->execute($query_values); |
|
999
|
|
|
} catch(PDOException $e) { |
|
1000
|
|
|
return "error : ".$e->getMessage(); |
|
1001
|
|
|
} |
|
1002
|
|
|
} |
|
1003
|
|
|
public function addStatDepartureAirportsDaily($date,$airport_icao,$airport_name,$airport_city,$airport_country,$departure,$airline_icao = '',$filter_name = '') { |
|
1004
|
|
|
global $globalDBdriver; |
|
1005
|
|
|
if ($globalDBdriver == 'mysql') { |
|
1006
|
|
|
$query = "INSERT INTO stats_airport (airport_icao,airport_name,airport_city,airport_country,departure,stats_type,date,stats_airline,filter_name) VALUES (:airport_icao,:airport_name,:airport_city,:airport_country,:departure,'daily',:date,:stats_airline,:filter_name) ON DUPLICATE KEY UPDATE departure = :departure"; |
|
1007
|
|
|
} else { |
|
1008
|
|
|
$query = "UPDATE stats_airport SET departure = departure+:departure WHERE airport_icao = :airport_icao AND stats_type = 'daily' AND date = :date AND stats_airline = :stats_airline AND filter_name = :filter_name; INSERT INTO stats_airport (airport_icao,airport_name,airport_city,airport_country,departure,stats_type,date,stats_airline,filter_name) SELECT :airport_icao,:airport_name,:airport_city,:airport_country,:departure,'daily',:date,:stats_airline,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats_airport WHERE airport_icao = :airport_icao AND stats_type = 'daily' AND date = :date AND stats_airline = :stats_airline AND filter_name = :filter_name);"; |
|
1009
|
|
|
} |
|
1010
|
|
|
$query_values = array(':airport_icao' => $airport_icao,':airport_name' => $airport_name,':airport_city' => $airport_city,':airport_country' => $airport_country,':departure' => $departure,':date' => $date,':stats_airline' => $airline_icao,':filter_name' => $filter_name); |
|
1011
|
|
|
try { |
|
1012
|
|
|
$sth = $this->db->prepare($query); |
|
1013
|
|
|
$sth->execute($query_values); |
|
1014
|
|
|
} catch(PDOException $e) { |
|
1015
|
|
|
return "error : ".$e->getMessage(); |
|
1016
|
|
|
} |
|
1017
|
|
|
} |
|
1018
|
|
|
public function addStatArrivalAirports($airport_icao,$airport_name,$airport_city,$airport_country,$arrival,$airline_icao = '',$filter_name = '') { |
|
1019
|
|
|
global $globalDBdriver; |
|
1020
|
|
|
if ($globalDBdriver == 'mysql') { |
|
1021
|
|
|
$query = "INSERT INTO stats_airport (airport_icao,airport_name,airport_city,airport_country,arrival,stats_type,date,stats_airline,filter_name) VALUES (:airport_icao,:airport_name,:airport_city,:airport_country,:arrival,'yearly',:date,:stats_airline,:filter_name) ON DUPLICATE KEY UPDATE arrival = arrival+:arrival"; |
|
1022
|
|
|
} else { |
|
1023
|
|
|
$query = "UPDATE stats_airport SET arrival = arrival+:arrival WHERE airport_icao = :airport_icao AND stats_type = 'yearly' AND stats_airline = :stats_airline AND date = :date AND filter_name = :filter_name; INSERT INTO stats_airport (airport_icao,airport_name,airport_city,airport_country,arrival,stats_type,date,stats_airline,filter_name) SELECT :airport_icao,:airport_name,:airport_city,:airport_country,:arrival,'yearly',:date,:stats_airline,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats_airport WHERE airport_icao = :airport_icao AND stats_type = 'yearly' AND stats_airline = :stats_airline AND date = :date AND filter_name = :filter_name);"; |
|
1024
|
|
|
} |
|
1025
|
|
|
$query_values = array(':airport_icao' => $airport_icao,':airport_name' => $airport_name,':airport_city' => $airport_city,':airport_country' => $airport_country,':arrival' => $arrival,':date' => date('Y').'-01-01 00:00:00',':stats_airline' => $airline_icao,':filter_name' => $filter_name); |
|
1026
|
|
|
try { |
|
1027
|
|
|
$sth = $this->db->prepare($query); |
|
1028
|
|
|
$sth->execute($query_values); |
|
1029
|
|
|
} catch(PDOException $e) { |
|
1030
|
|
|
return "error : ".$e->getMessage(); |
|
1031
|
|
|
} |
|
1032
|
|
|
} |
|
1033
|
|
|
public function addStatArrivalAirportsDaily($date,$airport_icao,$airport_name,$airport_city,$airport_country,$arrival,$airline_icao = '',$filter_name = '') { |
|
1034
|
|
|
global $globalDBdriver; |
|
1035
|
|
|
if ($globalDBdriver == 'mysql') { |
|
1036
|
|
|
$query = "INSERT INTO stats_airport (airport_icao,airport_name,airport_city,airport_country,arrival,stats_type,date,stats_airline,filter_name) VALUES (:airport_icao,:airport_name,:airport_city,:airport_country,:arrival,'daily',:date,:stats_airline,:filter_name) ON DUPLICATE KEY UPDATE arrival = :arrival"; |
|
1037
|
|
|
} else { |
|
1038
|
|
|
$query = "UPDATE stats_airport SET arrival = arrival+:arrival WHERE airport_icao = :airport_icao AND stats_type = 'daily' AND date = :date AND stats_airline = :stats_airline AND filter_name = :filter_name; INSERT INTO stats_airport (airport_icao,airport_name,airport_city,airport_country,arrival,stats_type,date,stats_airline,filter_name) SELECT :airport_icao,:airport_name,:airport_city,:airport_country,:arrival,'daily',:date,:stats_airline,:filter_name WHERE NOT EXISTS (SELECT 1 FROM stats_airport WHERE airport_icao = :airport_icao AND stats_type = 'daily' AND date = :date AND stats_airline = :stats_airline AND filter_name = :filter_name);"; |
|
1039
|
|
|
} |
|
1040
|
|
|
$query_values = array(':airport_icao' => $airport_icao,':airport_name' => $airport_name,':airport_city' => $airport_city,':airport_country' => $airport_country,':arrival' => $arrival, ':date' => $date,':stats_airline' => $airline_icao,':filter_name' => $filter_name); |
|
1041
|
|
|
try { |
|
1042
|
|
|
$sth = $this->db->prepare($query); |
|
1043
|
|
|
$sth->execute($query_values); |
|
1044
|
|
|
} catch(PDOException $e) { |
|
1045
|
|
|
return "error : ".$e->getMessage(); |
|
1046
|
|
|
} |
|
1047
|
|
|
} |
|
1048
|
|
|
|
|
1049
|
|
|
public function deleteStat($id) { |
|
1050
|
|
|
$query = "DELETE FROM stats WHERE stats_id = :id"; |
|
1051
|
|
|
$query_values = array(':id' => $id); |
|
1052
|
|
|
try { |
|
1053
|
|
|
$sth = $this->db->prepare($query); |
|
1054
|
|
|
$sth->execute($query_values); |
|
1055
|
|
|
} catch(PDOException $e) { |
|
1056
|
|
|
return "error : ".$e->getMessage(); |
|
1057
|
|
|
} |
|
1058
|
|
|
} |
|
1059
|
|
|
public function deleteStatFlight($type) { |
|
1060
|
|
|
$query = "DELETE FROM stats_flight WHERE stats_type = :type"; |
|
1061
|
|
|
$query_values = array(':type' => $type); |
|
1062
|
|
|
try { |
|
1063
|
|
|
$sth = $this->db->prepare($query); |
|
1064
|
|
|
$sth->execute($query_values); |
|
1065
|
|
|
} catch(PDOException $e) { |
|
1066
|
|
|
return "error : ".$e->getMessage(); |
|
1067
|
|
|
} |
|
1068
|
|
|
} |
|
1069
|
|
|
public function deleteStatAirport($type) { |
|
1070
|
|
|
$query = "DELETE FROM stats_airport WHERE stats_type = :type"; |
|
1071
|
|
|
$query_values = array(':type' => $type); |
|
1072
|
|
|
try { |
|
1073
|
|
|
$sth = $this->db->prepare($query); |
|
1074
|
|
|
$sth->execute($query_values); |
|
1075
|
|
|
} catch(PDOException $e) { |
|
1076
|
|
|
return "error : ".$e->getMessage(); |
|
1077
|
|
|
} |
|
1078
|
|
|
} |
|
1079
|
|
|
|
|
1080
|
|
|
public function addOldStats() { |
|
1081
|
|
|
global $globalArchiveMonths, $globalArchive, $globalArchiveYear, $globalDBdriver, $globalStatsFilters; |
|
1082
|
|
|
$Common = new Common(); |
|
1083
|
|
|
$Connection = new Connection(); |
|
1084
|
|
|
date_default_timezone_set('UTC'); |
|
1085
|
|
|
$last_update = $this->getLastStatsUpdate('last_update_stats'); |
|
1086
|
|
|
//print_r($last_update); |
|
1087
|
|
|
/* |
|
1088
|
|
|
$flightsbymonth = $this->getStats('flights_by_month'); |
|
1089
|
|
|
if (empty($last_update) && empty($flightsbymonth)) { |
|
1090
|
|
|
// Initial update |
|
1091
|
|
|
$Spotter = new Spotter($this->db); |
|
1092
|
|
|
$alldata = $Spotter->countAllMonths(); |
|
1093
|
|
|
$lastyear = false; |
|
1094
|
|
|
foreach ($alldata as $number) { |
|
1095
|
|
|
if ($number['year_name'] != date('Y')) $lastyear = true; |
|
1096
|
|
|
$this->addStat('flights_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name']))); |
|
1097
|
|
|
} |
|
1098
|
|
|
$alldata = $Spotter->countAllMilitaryMonths(); |
|
1099
|
|
|
//$lastyear = false; |
|
1100
|
|
|
foreach ($alldata as $number) { |
|
1101
|
|
|
if ($number['year_name'] != date('Y')) $lastyear = true; |
|
1102
|
|
|
$this->addStat('military_flights_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name']))); |
|
1103
|
|
|
} |
|
1104
|
|
|
$alldata = $Spotter->countAllMonthsOwners(); |
|
1105
|
|
|
foreach ($alldata as $number) { |
|
1106
|
|
|
$this->addStat('owners_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name']))); |
|
1107
|
|
|
} |
|
1108
|
|
|
$alldata = $Spotter->countAllMonthsPilots(); |
|
1109
|
|
|
foreach ($alldata as $number) { |
|
1110
|
|
|
$this->addStat('pilots_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name']))); |
|
1111
|
|
|
} |
|
1112
|
|
|
$alldata = $Spotter->countAllMonthsAirlines(); |
|
1113
|
|
|
foreach ($alldata as $number) { |
|
1114
|
|
|
$this->addStat('airlines_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name']))); |
|
1115
|
|
|
} |
|
1116
|
|
|
$alldata = $Spotter->countAllMonthsAircrafts(); |
|
1117
|
|
|
foreach ($alldata as $number) { |
|
1118
|
|
|
$this->addStat('aircrafts_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name']))); |
|
1119
|
|
|
} |
|
1120
|
|
|
$alldata = $Spotter->countAllMonthsRealArrivals(); |
|
1121
|
|
|
foreach ($alldata as $number) { |
|
1122
|
|
|
$this->addStat('realarrivals_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name']))); |
|
1123
|
|
|
} |
|
1124
|
|
|
$this->deleteStatFlight('month'); |
|
1125
|
|
|
$alldata = $Spotter->countAllDatesLastMonth(); |
|
1126
|
|
|
foreach ($alldata as $number) { |
|
1127
|
|
|
$this->addStatFlight('month',$number['date_name'],$number['date_count']); |
|
1128
|
|
|
} |
|
1129
|
|
|
$previousdata = $this->countAllDates(); |
|
1130
|
|
|
$this->deleteStatFlight('date'); |
|
1131
|
|
|
$alldata = $Common->array_merge_noappend($previousdata,$Spotter->countAllDates()); |
|
1132
|
|
|
$values = array(); |
|
1133
|
|
|
foreach ($alldata as $cnt) { |
|
1134
|
|
|
$values[] = $cnt['date_count']; |
|
1135
|
|
|
} |
|
1136
|
|
|
array_multisort($values,SORT_DESC,$alldata); |
|
1137
|
|
|
array_splice($alldata,11); |
|
1138
|
|
|
foreach ($alldata as $number) { |
|
1139
|
|
|
$this->addStatFlight('date',$number['date_name'],$number['date_count']); |
|
1140
|
|
|
} |
|
1141
|
|
|
$this->deleteStatFlight('hour'); |
|
1142
|
|
|
$alldata = $Spotter->countAllHours('hour'); |
|
1143
|
|
|
foreach ($alldata as $number) { |
|
1144
|
|
|
$this->addStatFlight('hour',$number['hour_name'],$number['hour_count']); |
|
1145
|
|
|
} |
|
1146
|
|
|
if ($lastyear) { |
|
1147
|
|
|
$monthsSinceLastYear = date('n'); |
|
1148
|
|
|
$alldata = $Spotter->countAllAircraftTypes(false,$monthsSinceLastYear); |
|
1149
|
|
|
foreach ($alldata as $number) { |
|
1150
|
|
|
$this->addStatAircraft($number['aircraft_icao'],$number['aircraft_icao_count'],$number['aircraft_name'],$number['aircraft_manufacturer']); |
|
1151
|
|
|
} |
|
1152
|
|
|
$alldata = $Spotter->countAllAirlines(false,$monthsSinceLastYear); |
|
1153
|
|
|
foreach ($alldata as $number) { |
|
1154
|
|
|
$this->addStatAirline($number['airline_icao'],$number['airline_count'],$number['airline_name']); |
|
1155
|
|
|
} |
|
1156
|
|
|
if ($Connection->tableExists('countries')) { |
|
1157
|
|
|
$alldata = $Spotter->countAllFlightOverCountries(false,$monthsSinceLastYear); |
|
1158
|
|
|
foreach ($alldata as $number) { |
|
1159
|
|
|
$this->addStatCountry($number['flight_country_iso2'],$number['flight_country_iso3'],$number['flight_country'],$number['flight_count']); |
|
1160
|
|
|
} |
|
1161
|
|
|
} |
|
1162
|
|
|
$alldata = $Spotter->countAllOwners(false,$monthsSinceLastYear); |
|
1163
|
|
|
foreach ($alldata as $number) { |
|
1164
|
|
|
$this->addStatOwner($number['owner_name'],$number['owner_count']); |
|
1165
|
|
|
} |
|
1166
|
|
|
$alldata = $Spotter->countAllPilots(false,$monthsSinceLastYear); |
|
1167
|
|
|
foreach ($alldata as $number) { |
|
1168
|
|
|
$this->addStatPilot($number['pilot_id'],$number['pilot_count'],$number['pilot_name']); |
|
1169
|
|
|
} |
|
1170
|
|
|
$previous_year = date('Y'); |
|
1171
|
|
|
$previous_year--; |
|
1172
|
|
|
$this->addStat('aircrafts_byyear',$this->getStatsAircraftTotal(),$previous_year.'-01-01 00:00:00'); |
|
1173
|
|
|
$this->addStat('airlines_byyear',$this->getStatsAirlineTotal(),$previous_year.'-01-01 00:00:00'); |
|
1174
|
|
|
$this->addStat('owner_byyear',$this->getStatsOwnerTotal(),$previous_year.'-01-01 00:00:00'); |
|
1175
|
|
|
$this->addStat('pilot_byyear',$this->getStatsPilotTotal(),$previous_year.'-01-01 00:00:00'); |
|
1176
|
|
|
|
|
1177
|
|
|
if (isset($globalArchiveYear) && $globalArchiveYear) { |
|
1178
|
|
|
if ($globalArchive) { |
|
1179
|
|
|
$query = "INSERT INTO spotter_archive_output SELECT * FROM spotter_output WHERE spotter_output.date < '".date('Y')."-01-01 00:00:00'"; |
|
1180
|
|
|
//echo $query; |
|
1181
|
|
|
try { |
|
1182
|
|
|
$sth = $this->db->prepare($query); |
|
1183
|
|
|
$sth->execute(); |
|
1184
|
|
|
} catch(PDOException $e) { |
|
1185
|
|
|
return "error : ".$e->getMessage().' - query : '.$query."\n"; |
|
1186
|
|
|
} |
|
1187
|
|
|
} |
|
1188
|
|
|
$query = "DELETE FROM spotter_output WHERE spotter_output.date < '".date('Y')."-01-01 00:00:00'"; |
|
1189
|
|
|
try { |
|
1190
|
|
|
$sth = $this->db->prepare($query); |
|
1191
|
|
|
$sth->execute(); |
|
1192
|
|
|
} catch(PDOException $e) { |
|
1193
|
|
|
return "error : ".$e->getMessage().' - query : '.$query."\n"; |
|
1194
|
|
|
} |
|
1195
|
|
|
} |
|
1196
|
|
|
} |
|
1197
|
|
|
if (!isset($globalArchiveMonths) || $globalArchiveMonths == '') $globalArchiveMonths = 2; |
|
1198
|
|
|
if ($globalArchiveMonths > 0) { |
|
1199
|
|
|
$alldata = $Spotter->countAllAircraftTypes(false,$globalArchiveMonths); |
|
1200
|
|
|
foreach ($alldata as $number) { |
|
1201
|
|
|
$this->addStatAircraft($number['aircraft_icao'],$number['aircraft_icao_count'],$number['aircraft_name'],$number['aircraft_manufacturer']); |
|
1202
|
|
|
} |
|
1203
|
|
|
$alldata = $Spotter->countAllAirlines(false,$globalArchiveMonths); |
|
1204
|
|
|
foreach ($alldata as $number) { |
|
1205
|
|
|
$this->addStatAirline($number['airline_icao'],$number['airline_count'],$number['airline_name']); |
|
1206
|
|
|
} |
|
1207
|
|
|
$alldata = $Spotter->countAllAircraftRegistrations(false,$globalArchiveMonths); |
|
1208
|
|
|
foreach ($alldata as $number) { |
|
1209
|
|
|
$this->addStatAircraftRegistration($number['registration'],$number['aircraft_registration_count'],$number['aircraft_icao']); |
|
1210
|
|
|
} |
|
1211
|
|
|
$alldata = $Spotter->countAllCallsigns(false,$globalArchiveMonths); |
|
1212
|
|
|
foreach ($alldata as $number) { |
|
1213
|
|
|
$this->addStatCallsign($number['callsign_icao'],$number['callsign_icao_count'],$number['airline_icao']); |
|
1214
|
|
|
} |
|
1215
|
|
|
$alldata = $Spotter->countAllOwners(false,$globalArchiveMonths); |
|
1216
|
|
|
foreach ($alldata as $number) { |
|
1217
|
|
|
$this->addStatOwner($number['owner_name'],$number['owner_count']); |
|
1218
|
|
|
} |
|
1219
|
|
|
if ($Connection->tableExists('countries')) { |
|
1220
|
|
|
$alldata = $Spotter->countAllFlightOverCountries(false,$globalArchiveMonths); |
|
1221
|
|
|
foreach ($alldata as $number) { |
|
1222
|
|
|
$this->addStatCountry($number['flight_country_iso2'],$number['flight_country_iso3'],$number['flight_country'],$number['flight_count']); |
|
1223
|
|
|
} |
|
1224
|
|
|
} |
|
1225
|
|
|
$alldata = $Spotter->countAllPilots(false,$globalArchiveMonths); |
|
1226
|
|
|
foreach ($alldata as $number) { |
|
1227
|
|
|
$this->addStatPilot($number['pilot_id'],$number['pilot_count'],$number['pilot_name']); |
|
1228
|
|
|
} |
|
1229
|
|
|
$pall = $Spotter->countAllDepartureAirports(false,$globalArchiveMonths); |
|
1230
|
|
|
$dall = $Spotter->countAllDetectedDepartureAirports(false,$globalArchiveMonths); |
|
1231
|
|
|
$alldata = array(); |
|
1232
|
|
|
foreach ($pall as $value) { |
|
1233
|
|
|
$icao = $value['airport_departure_icao']; |
|
1234
|
|
|
$alldata[$icao] = $value; |
|
1235
|
|
|
} |
|
1236
|
|
|
foreach ($dall as $value) { |
|
1237
|
|
|
$icao = $value['airport_departure_icao']; |
|
1238
|
|
|
if (isset($alldata[$icao])) { |
|
1239
|
|
|
$alldata[$icao]['airport_departure_icao_count'] = $alldata[$icao]['airport_departure_icao_count'] + $value['airport_departure_icao_count']; |
|
1240
|
|
|
} else $alldata[$icao] = $value; |
|
1241
|
|
|
} |
|
1242
|
|
|
$count = array(); |
|
1243
|
|
|
foreach ($alldata as $key => $row) { |
|
1244
|
|
|
$count[$key] = $row['airport_departure_icao_count']; |
|
1245
|
|
|
} |
|
1246
|
|
|
array_multisort($count,SORT_DESC,$alldata); |
|
1247
|
|
|
|
|
1248
|
|
|
//print_r($alldate); |
|
1249
|
|
|
foreach ($alldata as $number) { |
|
1250
|
|
|
$this->addStatDepartureAirports($number['airport_departure_icao'],$number['airport_departure_name'],$number['airport_departure_city'],$number['airport_departure_country'],$number['airport_departure_icao_count']); |
|
1251
|
|
|
} |
|
1252
|
|
|
$pdata = $Spotter->countAllArrivalAirports(false,$globalArchiveMonths); |
|
1253
|
|
|
$dall = $Spotter->countAllDetectedArrivalAirports(false,$globalArchiveMonths); |
|
1254
|
|
|
$alldata = array(); |
|
1255
|
|
|
foreach ($pdata as $value) { |
|
1256
|
|
|
$icao = $value['airport_arrival_icao']; |
|
1257
|
|
|
$alldata[$icao] = $value; |
|
1258
|
|
|
} |
|
1259
|
|
|
foreach ($dall as $value) { |
|
1260
|
|
|
$icao = $value['airport_arrival_icao']; |
|
1261
|
|
|
if (isset($alldata[$icao])) { |
|
1262
|
|
|
$alldata[$icao]['airport_arrival_icao_count'] = $alldata[$icao]['airport_arrival_icao_count'] + $value['airport_arrival_icao_count']; |
|
1263
|
|
|
} else $alldata[$icao] = $value; |
|
1264
|
|
|
} |
|
1265
|
|
|
$count = array(); |
|
1266
|
|
|
foreach ($alldata as $key => $row) { |
|
1267
|
|
|
$count[$key] = $row['airport_arrival_icao_count']; |
|
1268
|
|
|
} |
|
1269
|
|
|
array_multisort($count,SORT_DESC,$alldata); |
|
1270
|
|
|
foreach ($alldata as $number) { |
|
1271
|
|
|
$this->addStatArrivalAirports($number['airport_arrival_icao'],$number['airport_arrival_name'],$number['airport_arrival_city'],$number['airport_arrival_country'],$number['airport_arrival_icao_count']); |
|
1272
|
|
|
} |
|
1273
|
|
|
$this->addStat('aircrafts_byyear',$this->getStatsAircraftTotal(),date('Y').'-01-01 00:00:00'); |
|
1274
|
|
|
$this->addStat('airlines_byyear',$this->getStatsAirlineTotal(),date('Y').'-01-01 00:00:00'); |
|
1275
|
|
|
$this->addStat('owner_byyear',$this->getStatsOwnerTotal(),date('Y').'-01-01 00:00:00'); |
|
1276
|
|
|
$this->addStat('pilot_byyear',$this->getStatsPilotTotal(),date('Y').'-01-01 00:00:00'); |
|
1277
|
|
|
|
|
1278
|
|
|
if ($globalArchive) { |
|
1279
|
|
|
if ($globalDBdriver == 'mysql') { |
|
1280
|
|
|
$query = "INSERT INTO spotter_archive_output SELECT * FROM spotter_output WHERE spotter_output.date < DATE_FORMAT(UTC_TIMESTAMP() - INTERVAL ".$globalArchiveMonths." MONTH, '%Y/%m/01')"; |
|
1281
|
|
|
} else { |
|
1282
|
|
|
$query = "INSERT INTO spotter_archive_output SELECT * FROM spotter_output WHERE spotter_output.date < CAST(to_char(CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalArchiveMonths." MONTHS', 'YYYY/mm/01') AS TIMESTAMP)"; |
|
1283
|
|
|
} |
|
1284
|
|
|
try { |
|
1285
|
|
|
$sth = $this->db->prepare($query); |
|
1286
|
|
|
$sth->execute(); |
|
1287
|
|
|
} catch(PDOException $e) { |
|
1288
|
|
|
return "error : ".$e->getMessage().' - query : '.$query."\n"; |
|
1289
|
|
|
} |
|
1290
|
|
|
} |
|
1291
|
|
|
|
|
1292
|
|
|
//$query = 'DELETE FROM spotter_output WHERE spotter_output.date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$globalArchiveMonths.' MONTH)'; |
|
1293
|
|
|
if ($globalDBdriver == 'mysql') { |
|
1294
|
|
|
$query = "DELETE FROM spotter_output WHERE spotter_output.date < DATE_FORMAT(UTC_TIMESTAMP() - INTERVAL ".$globalArchiveMonths." MONTH, '%Y/%m/01')"; |
|
1295
|
|
|
} else { |
|
1296
|
|
|
$query = "DELETE FROM spotter_output WHERE spotter_output.date < CAST(to_char(CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalArchiveMonths." MONTHS, 'YYYY/mm/01') AS TIMESTAMP)"; |
|
1297
|
|
|
} |
|
1298
|
|
|
try { |
|
1299
|
|
|
$sth = $this->db->prepare($query); |
|
1300
|
|
|
$sth->execute(); |
|
1301
|
|
|
} catch(PDOException $e) { |
|
1302
|
|
|
return "error : ".$e->getMessage().' - query : '.$query."\n"; |
|
1303
|
|
|
} |
|
1304
|
|
|
} |
|
1305
|
|
|
$this->addLastStatsUpdate('last_update_stats',date('Y-m-d G:i:s')); |
|
1306
|
|
|
} else { |
|
1307
|
|
|
*/ |
|
1308
|
|
|
echo 'Update stats !'."\n"; |
|
1309
|
|
|
if (isset($last_update[0]['value'])) { |
|
1310
|
|
|
$last_update_day = $last_update[0]['value']; |
|
1311
|
|
|
} else $last_update_day = '2012-12-12 12:12:12'; |
|
1312
|
|
|
$Spotter = new Spotter($this->db); |
|
1313
|
|
|
$alldata = $Spotter->countAllAircraftTypes(false,0,$last_update_day); |
|
1314
|
|
|
foreach ($alldata as $number) { |
|
1315
|
|
|
$this->addStatAircraft($number['aircraft_icao'],$number['aircraft_icao_count'],$number['aircraft_name'],$number['aircraft_manufacturer']); |
|
1316
|
|
|
} |
|
1317
|
|
|
$alldata = $Spotter->countAllAirlines(false,0,$last_update_day); |
|
1318
|
|
|
foreach ($alldata as $number) { |
|
1319
|
|
|
$this->addStatAirline($number['airline_icao'],$number['airline_count'],$number['airline_name']); |
|
1320
|
|
|
} |
|
1321
|
|
|
$alldata = $Spotter->countAllAircraftRegistrations(false,0,$last_update_day); |
|
1322
|
|
|
foreach ($alldata as $number) { |
|
1323
|
|
|
$this->addStatAircraftRegistration($number['registration'],$number['aircraft_registration_count'],$number['aircraft_icao']); |
|
1324
|
|
|
} |
|
1325
|
|
|
$alldata = $Spotter->countAllCallsigns(false,0,$last_update_day); |
|
1326
|
|
|
foreach ($alldata as $number) { |
|
1327
|
|
|
$this->addStatCallsign($number['callsign_icao'],$number['callsign_icao_count'],$number['airline_icao']); |
|
1328
|
|
|
} |
|
1329
|
|
|
$alldata = $Spotter->countAllOwners(false,0,$last_update_day); |
|
1330
|
|
|
foreach ($alldata as $number) { |
|
1331
|
|
|
$this->addStatOwner($number['owner_name'],$number['owner_count']); |
|
1332
|
|
|
} |
|
1333
|
|
|
$alldata = $Spotter->countAllPilots(false,0,$last_update_day); |
|
1334
|
|
|
foreach ($alldata as $number) { |
|
1335
|
|
|
$this->addStatPilot($number['pilot_id'],$number['pilot_count'],$number['pilot_name']); |
|
1336
|
|
|
} |
|
1337
|
|
|
|
|
1338
|
|
|
$pall = $Spotter->countAllDepartureAirports(false,0,$last_update_day); |
|
1339
|
|
|
$dall = $Spotter->countAllDetectedDepartureAirports(false,0,$last_update_day); |
|
1340
|
|
|
$alldata = array(); |
|
1341
|
|
|
|
|
1342
|
|
|
foreach ($pall as $value) { |
|
1343
|
|
|
$icao = $value['airport_departure_icao']; |
|
1344
|
|
|
$alldata[$icao] = $value; |
|
1345
|
|
|
} |
|
1346
|
|
|
foreach ($dall as $value) { |
|
1347
|
|
|
$icao = $value['airport_departure_icao']; |
|
1348
|
|
|
if (isset($alldata[$icao])) { |
|
1349
|
|
|
$alldata[$icao]['airport_departure_icao_count'] = $alldata[$icao]['airport_departure_icao_count'] + $value['airport_departure_icao_count']; |
|
1350
|
|
|
} else $alldata[$icao] = $value; |
|
1351
|
|
|
} |
|
1352
|
|
|
$count = array(); |
|
1353
|
|
|
foreach ($alldata as $key => $row) { |
|
1354
|
|
|
$count[$key] = $row['airport_departure_icao_count']; |
|
1355
|
|
|
} |
|
1356
|
|
|
array_multisort($count,SORT_DESC,$alldata); |
|
1357
|
|
|
foreach ($alldata as $number) { |
|
1358
|
|
|
echo $this->addStatDepartureAirports($number['airport_departure_icao'],$number['airport_departure_name'],$number['airport_departure_city'],$number['airport_departure_country'],$number['airport_departure_icao_count']); |
|
1359
|
|
|
} |
|
1360
|
|
|
$pall = $Spotter->countAllArrivalAirports(false,0,$last_update_day); |
|
1361
|
|
|
$dall = $Spotter->countAllDetectedArrivalAirports(false,0,$last_update_day); |
|
1362
|
|
|
$alldata = array(); |
|
1363
|
|
|
foreach ($pall as $value) { |
|
1364
|
|
|
$icao = $value['airport_arrival_icao']; |
|
1365
|
|
|
$alldata[$icao] = $value; |
|
1366
|
|
|
} |
|
1367
|
|
|
foreach ($dall as $value) { |
|
1368
|
|
|
$icao = $value['airport_arrival_icao']; |
|
1369
|
|
|
if (isset($alldata[$icao])) { |
|
1370
|
|
|
$alldata[$icao]['airport_arrival_icao_count'] = $alldata[$icao]['airport_arrival_icao_count'] + $value['airport_arrival_icao_count']; |
|
1371
|
|
|
} else $alldata[$icao] = $value; |
|
1372
|
|
|
} |
|
1373
|
|
|
$count = array(); |
|
1374
|
|
|
foreach ($alldata as $key => $row) { |
|
1375
|
|
|
$count[$key] = $row['airport_arrival_icao_count']; |
|
1376
|
|
|
} |
|
1377
|
|
|
array_multisort($count,SORT_DESC,$alldata); |
|
1378
|
|
|
foreach ($alldata as $number) { |
|
1379
|
|
|
echo $this->addStatArrivalAirports($number['airport_arrival_icao'],$number['airport_arrival_name'],$number['airport_arrival_city'],$number['airport_arrival_country'],$number['airport_arrival_icao_count']); |
|
1380
|
|
|
} |
|
1381
|
|
|
if ($Connection->tableExists('countries')) { |
|
1382
|
|
|
$SpotterArchive = new SpotterArchive(); |
|
1383
|
|
|
$alldata = $SpotterArchive->countAllFlightOverCountries(false,0,$last_update_day); |
|
1384
|
|
|
foreach ($alldata as $number) { |
|
1385
|
|
|
$this->addStatCountry($number['flight_country_iso2'],$number['flight_country_iso3'],$number['flight_country'],$number['flight_count']); |
|
1386
|
|
|
} |
|
1387
|
|
|
} |
|
1388
|
|
|
|
|
1389
|
|
|
|
|
1390
|
|
|
// Add by month using getstat if month finish... |
|
1391
|
|
|
|
|
1392
|
|
|
//if (date('m',strtotime($last_update_day)) != date('m')) { |
|
1393
|
|
|
$Spotter = new Spotter($this->db); |
|
1394
|
|
|
$alldata = $Spotter->countAllMonths(); |
|
1395
|
|
|
$lastyear = false; |
|
|
|
|
|
|
1396
|
|
|
foreach ($alldata as $number) { |
|
1397
|
|
|
if ($number['year_name'] != date('Y')) $lastyear = true; |
|
|
|
|
|
|
1398
|
|
|
$this->addStat('flights_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name']))); |
|
1399
|
|
|
} |
|
1400
|
|
|
$alldata = $Spotter->countAllMilitaryMonths(); |
|
1401
|
|
|
foreach ($alldata as $number) { |
|
1402
|
|
|
$this->addStat('military_flights_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name']))); |
|
1403
|
|
|
} |
|
1404
|
|
|
$alldata = $Spotter->countAllMonthsOwners(); |
|
1405
|
|
|
foreach ($alldata as $number) { |
|
1406
|
|
|
$this->addStat('owners_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name']))); |
|
1407
|
|
|
} |
|
1408
|
|
|
$alldata = $Spotter->countAllMonthsPilots(); |
|
1409
|
|
|
foreach ($alldata as $number) { |
|
1410
|
|
|
$this->addStat('pilots_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name']))); |
|
1411
|
|
|
} |
|
1412
|
|
|
$alldata = $Spotter->countAllMonthsAirlines(); |
|
1413
|
|
|
foreach ($alldata as $number) { |
|
1414
|
|
|
$this->addStat('airlines_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name']))); |
|
1415
|
|
|
} |
|
1416
|
|
|
$alldata = $Spotter->countAllMonthsAircrafts(); |
|
1417
|
|
|
foreach ($alldata as $number) { |
|
1418
|
|
|
$this->addStat('aircrafts_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name']))); |
|
1419
|
|
|
} |
|
1420
|
|
|
$alldata = $Spotter->countAllMonthsRealArrivals(); |
|
1421
|
|
|
foreach ($alldata as $number) { |
|
1422
|
|
|
$this->addStat('realarrivals_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name']))); |
|
1423
|
|
|
} |
|
1424
|
|
|
echo 'Airports data...'."\n"; |
|
1425
|
|
|
echo '...Departure'."\n"; |
|
1426
|
|
|
$this->deleteStatAirport('daily'); |
|
1427
|
|
|
// $pall = $Spotter->getLast7DaysAirportsDeparture(); |
|
1428
|
|
|
// $dall = $Spotter->getLast7DaysDetectedAirportsDeparture(); |
|
1429
|
|
|
$pall = $Spotter->getLast7DaysAirportsDeparture(); |
|
1430
|
|
|
$dall = $Spotter->getLast7DaysDetectedAirportsDeparture(); |
|
1431
|
|
|
/* |
|
1432
|
|
|
$alldata = array(); |
|
1433
|
|
|
foreach ($pall as $value) { |
|
1434
|
|
|
$icao = $value['departure_airport_icao']; |
|
1435
|
|
|
$alldata[$icao] = $value; |
|
1436
|
|
|
} |
|
1437
|
|
|
foreach ($dall as $value) { |
|
1438
|
|
|
$icao = $value['departure_airport_icao']; |
|
1439
|
|
|
$ddate = $value['date']; |
|
1440
|
|
|
if (isset($alldata[$icao])) { |
|
1441
|
|
|
$alldata[$icao]['departure_airport_count'] = $alldata[$icao]['departure_airport_count'] + $value['departure_airport_count']; |
|
1442
|
|
|
} else $alldata[$icao] = $value; |
|
1443
|
|
|
} |
|
1444
|
|
|
$count = array(); |
|
1445
|
|
|
foreach ($alldata as $key => $row) { |
|
1446
|
|
|
$count[$key] = $row['departure_airport_count']; |
|
1447
|
|
|
} |
|
1448
|
|
|
array_multisort($count,SORT_DESC,$alldata); |
|
1449
|
|
|
*/ |
|
1450
|
|
|
foreach ($dall as $value) { |
|
1451
|
|
|
$icao = $value['departure_airport_icao']; |
|
1452
|
|
|
$ddate = $value['date']; |
|
1453
|
|
|
$find = false; |
|
1454
|
|
|
foreach ($pall as $pvalue) { |
|
1455
|
|
|
if ($pvalue['departure_airport_icao'] == $icao && $pvalue['date'] == $ddate) { |
|
1456
|
|
|
$pvalue['departure_airport_count'] = $pvalue['departure_airport_count'] + $value['departure_airport_count']; |
|
1457
|
|
|
$find = true; |
|
1458
|
|
|
break; |
|
1459
|
|
|
} |
|
1460
|
|
|
} |
|
1461
|
|
|
if ($find === false) { |
|
1462
|
|
|
$pall[] = $value; |
|
1463
|
|
|
} |
|
1464
|
|
|
} |
|
1465
|
|
|
$alldata = $pall; |
|
1466
|
|
|
foreach ($alldata as $number) { |
|
1467
|
|
|
$this->addStatDepartureAirportsDaily($number['date'],$number['departure_airport_icao'],$number['departure_airport_name'],$number['departure_airport_city'],$number['departure_airport_country'],$number['departure_airport_count']); |
|
1468
|
|
|
} |
|
1469
|
|
|
echo '...Arrival'."\n"; |
|
1470
|
|
|
$pall = $Spotter->getLast7DaysAirportsArrival(); |
|
1471
|
|
|
$dall = $Spotter->getLast7DaysDetectedAirportsArrival(); |
|
1472
|
|
|
/* |
|
1473
|
|
|
$alldata = array(); |
|
1474
|
|
|
foreach ($pall as $value) { |
|
1475
|
|
|
$icao = $value['arrival_airport_icao']; |
|
1476
|
|
|
$alldata[$icao] = $value; |
|
1477
|
|
|
} |
|
1478
|
|
|
foreach ($dall as $value) { |
|
1479
|
|
|
$icao = $value['arrival_airport_icao']; |
|
1480
|
|
|
if (isset($alldata[$icao])) { |
|
1481
|
|
|
$alldata[$icao]['arrival_airport_icao_count'] = $alldata[$icao]['arrival_airport_count'] + $value['arrival_airport_count']; |
|
1482
|
|
|
} else $alldata[$icao] = $value; |
|
1483
|
|
|
} |
|
1484
|
|
|
$count = array(); |
|
1485
|
|
|
foreach ($alldata as $key => $row) { |
|
1486
|
|
|
$count[$key] = $row['arrival_airport_count']; |
|
1487
|
|
|
} |
|
1488
|
|
|
array_multisort($count,SORT_DESC,$alldata); |
|
1489
|
|
|
*/ |
|
1490
|
|
|
|
|
1491
|
|
|
|
|
1492
|
|
|
foreach ($dall as $value) { |
|
1493
|
|
|
$icao = $value['arrival_airport_icao']; |
|
1494
|
|
|
$ddate = $value['date']; |
|
1495
|
|
|
$find = false; |
|
1496
|
|
|
foreach ($pall as $pvalue) { |
|
1497
|
|
|
if ($pvalue['arrival_airport_icao'] == $icao && $pvalue['date'] == $ddate) { |
|
1498
|
|
|
$pvalue['arrival_airport_count'] = $pvalue['arrival_airport_count'] + $value['arrival_airport_count']; |
|
1499
|
|
|
$find = true; |
|
1500
|
|
|
break; |
|
1501
|
|
|
} |
|
1502
|
|
|
} |
|
1503
|
|
|
if ($find === false) { |
|
1504
|
|
|
$pall[] = $value; |
|
1505
|
|
|
} |
|
1506
|
|
|
} |
|
1507
|
|
|
$alldata = $pall; |
|
1508
|
|
|
foreach ($alldata as $number) { |
|
1509
|
|
|
$this->addStatArrivalAirportsDaily($number['date'],$number['arrival_airport_icao'],$number['arrival_airport_name'],$number['arrival_airport_city'],$number['arrival_airport_country'],$number['arrival_airport_count']); |
|
1510
|
|
|
} |
|
1511
|
|
|
|
|
1512
|
|
|
echo 'Flights data...'."\n"; |
|
1513
|
|
|
$this->deleteStatFlight('month'); |
|
1514
|
|
|
echo '-> countAllDatesLastMonth...'."\n"; |
|
1515
|
|
|
$alldata = $Spotter->countAllDatesLastMonth(); |
|
1516
|
|
|
foreach ($alldata as $number) { |
|
1517
|
|
|
$this->addStatFlight('month',$number['date_name'],$number['date_count']); |
|
1518
|
|
|
} |
|
1519
|
|
|
echo '-> countAllDates...'."\n"; |
|
1520
|
|
|
$previousdata = $this->countAllDates(); |
|
1521
|
|
|
$this->deleteStatFlight('date'); |
|
1522
|
|
|
$alldata = $Common->array_merge_noappend($previousdata,$Spotter->countAllDates()); |
|
1523
|
|
|
$values = array(); |
|
1524
|
|
|
foreach ($alldata as $cnt) { |
|
1525
|
|
|
$values[] = $cnt['date_count']; |
|
1526
|
|
|
} |
|
1527
|
|
|
array_multisort($values,SORT_DESC,$alldata); |
|
1528
|
|
|
array_splice($alldata,11); |
|
1529
|
|
|
foreach ($alldata as $number) { |
|
1530
|
|
|
$this->addStatFlight('date',$number['date_name'],$number['date_count']); |
|
1531
|
|
|
} |
|
1532
|
|
|
|
|
1533
|
|
|
$this->deleteStatFlight('hour'); |
|
1534
|
|
|
echo '-> countAllHours...'."\n"; |
|
1535
|
|
|
$alldata = $Spotter->countAllHours('hour'); |
|
1536
|
|
|
foreach ($alldata as $number) { |
|
1537
|
|
|
$this->addStatFlight('hour',$number['hour_name'],$number['hour_count']); |
|
1538
|
|
|
} |
|
1539
|
|
|
|
|
1540
|
|
|
|
|
1541
|
|
|
|
|
1542
|
|
|
// Count by airlines |
|
1543
|
|
|
echo '--- Stats by airlines ---'."\n"; |
|
1544
|
|
|
$Spotter = new Spotter($this->db); |
|
1545
|
|
|
$alldata = $Spotter->countAllAircraftTypesByAirlines(false,0,$last_update_day); |
|
1546
|
|
|
foreach ($alldata as $number) { |
|
1547
|
|
|
$this->addStatAircraft($number['aircraft_icao'],$number['aircraft_icao_count'],$number['aircraft_name'],$number['aircraft_manufacturer'],$number['airline_icao']); |
|
1548
|
|
|
} |
|
1549
|
|
|
$alldata = $Spotter->countAllAircraftRegistrationsByAirlines(false,0,$last_update_day); |
|
1550
|
|
|
foreach ($alldata as $number) { |
|
1551
|
|
|
$this->addStatAircraftRegistration($number['registration'],$number['aircraft_registration_count'],$number['aircraft_icao'],$number['airline_icao']); |
|
1552
|
|
|
} |
|
1553
|
|
|
$alldata = $Spotter->countAllCallsignsByAirlines(false,0,$last_update_day); |
|
1554
|
|
|
foreach ($alldata as $number) { |
|
1555
|
|
|
$this->addStatCallsign($number['callsign_icao'],$number['callsign_icao_count'],$number['airline_icao']); |
|
1556
|
|
|
} |
|
1557
|
|
|
$alldata = $Spotter->countAllOwnersByAirlines(false,0,$last_update_day); |
|
1558
|
|
|
foreach ($alldata as $number) { |
|
1559
|
|
|
$this->addStatOwner($number['owner_name'],$number['owner_count'],$number['airline_icao']); |
|
1560
|
|
|
} |
|
1561
|
|
|
$alldata = $Spotter->countAllPilotsByAirlines(false,0,$last_update_day); |
|
1562
|
|
|
foreach ($alldata as $number) { |
|
1563
|
|
|
$this->addStatPilot($number['pilot_id'],$number['pilot_count'],$number['pilot_name'],$number['airline_icao']); |
|
1564
|
|
|
} |
|
1565
|
|
|
|
|
1566
|
|
|
$pall = $Spotter->countAllDepartureAirportsByAirlines(false,0,$last_update_day); |
|
1567
|
|
|
$dall = $Spotter->countAllDetectedDepartureAirportsByAirlines(false,0,$last_update_day); |
|
1568
|
|
|
//$alldata = array(); |
|
1569
|
|
|
foreach ($dall as $value) { |
|
1570
|
|
|
$icao = $value['airport_departure_icao']; |
|
1571
|
|
|
$dicao = $value['airline_icap']; |
|
1572
|
|
|
$find = false; |
|
1573
|
|
|
foreach ($pall as $pvalue) { |
|
1574
|
|
|
if ($pvalue['airport_departure_icao'] == $icao && $pvalue['airline_icao'] = $dicao) { |
|
1575
|
|
|
$pvalue['airport_departure_icao_count'] = $pvalue['airport_departure_icao_count'] + $value['airport_departure_icao_count']; |
|
1576
|
|
|
$find = true; |
|
1577
|
|
|
break; |
|
1578
|
|
|
} |
|
1579
|
|
|
} |
|
1580
|
|
|
if ($find === false) { |
|
1581
|
|
|
$pall[] = $value; |
|
1582
|
|
|
} |
|
1583
|
|
|
} |
|
1584
|
|
|
$alldata = $pall; |
|
1585
|
|
|
foreach ($alldata as $number) { |
|
1586
|
|
|
echo $this->addStatDepartureAirports($number['airport_departure_icao'],$number['airport_departure_name'],$number['airport_departure_city'],$number['airport_departure_country'],$number['airport_departure_icao_count'],$number['airline_icao']); |
|
1587
|
|
|
} |
|
1588
|
|
|
$pall = $Spotter->countAllArrivalAirportsByAirlines(false,0,$last_update_day); |
|
1589
|
|
|
$dall = $Spotter->countAllDetectedArrivalAirportsByAirlines(false,0,$last_update_day); |
|
1590
|
|
|
//$alldata = array(); |
|
1591
|
|
|
foreach ($dall as $value) { |
|
1592
|
|
|
$icao = $value['airport_arrival_icao']; |
|
1593
|
|
|
$dicao = $value['airline_icao']; |
|
1594
|
|
|
$find = false; |
|
1595
|
|
|
foreach ($pall as $pvalue) { |
|
1596
|
|
|
if ($pvalue['airport_arrival_icao'] == $icao && $pvalue['airline_icao'] = $dicao) { |
|
1597
|
|
|
$pvalue['airport_arrival_icao_count'] = $pvalue['airport_arrival_icao_count'] + $value['airport_arrival_icao_count']; |
|
1598
|
|
|
$find = true; |
|
1599
|
|
|
break; |
|
1600
|
|
|
} |
|
1601
|
|
|
} |
|
1602
|
|
|
if ($find === false) { |
|
1603
|
|
|
$pall[] = $value; |
|
1604
|
|
|
} |
|
1605
|
|
|
} |
|
1606
|
|
|
$alldata = $pall; |
|
1607
|
|
|
foreach ($alldata as $number) { |
|
1608
|
|
|
echo $this->addStatArrivalAirports($number['airport_arrival_icao'],$number['airport_arrival_name'],$number['airport_arrival_city'],$number['airport_arrival_country'],$number['airport_arrival_icao_count'],$number['airline_icao']); |
|
1609
|
|
|
} |
|
1610
|
|
|
$Spotter = new Spotter($this->db); |
|
1611
|
|
|
$alldata = $Spotter->countAllMonthsByAirlines(); |
|
1612
|
|
|
$lastyear = false; |
|
1613
|
|
|
foreach ($alldata as $number) { |
|
1614
|
|
|
if ($number['year_name'] != date('Y')) $lastyear = true; |
|
1615
|
|
|
$this->addStat('flights_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])),$number['airline_icao']); |
|
1616
|
|
|
} |
|
1617
|
|
|
$alldata = $Spotter->countAllMonthsOwnersByAirlines(); |
|
1618
|
|
|
foreach ($alldata as $number) { |
|
1619
|
|
|
$this->addStat('owners_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])),$number['airline_icao']); |
|
1620
|
|
|
} |
|
1621
|
|
|
$alldata = $Spotter->countAllMonthsPilotsByAirlines(); |
|
1622
|
|
|
foreach ($alldata as $number) { |
|
1623
|
|
|
$this->addStat('pilots_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])),$number['airline_icao']); |
|
1624
|
|
|
} |
|
1625
|
|
|
$alldata = $Spotter->countAllMonthsAircraftsByAirlines(); |
|
1626
|
|
|
foreach ($alldata as $number) { |
|
1627
|
|
|
$this->addStat('aircrafts_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])),$number['airline_icao']); |
|
1628
|
|
|
} |
|
1629
|
|
|
$alldata = $Spotter->countAllMonthsRealArrivalsByAirlines(); |
|
1630
|
|
|
foreach ($alldata as $number) { |
|
1631
|
|
|
$this->addStat('realarrivals_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])),$number['airline_icao']); |
|
1632
|
|
|
} |
|
1633
|
|
|
echo '...Departure'."\n"; |
|
1634
|
|
|
$pall = $Spotter->getLast7DaysAirportsDepartureByAirlines(); |
|
1635
|
|
|
$dall = $Spotter->getLast7DaysDetectedAirportsDepartureByAirlines(); |
|
1636
|
|
|
foreach ($dall as $value) { |
|
1637
|
|
|
$icao = $value['departure_airport_icao']; |
|
1638
|
|
|
$airline = $value['airline_icao']; |
|
1639
|
|
|
$ddate = $value['date']; |
|
1640
|
|
|
$find = false; |
|
1641
|
|
|
foreach ($pall as $pvalue) { |
|
1642
|
|
|
if ($pvalue['departure_airport_icao'] == $icao && $pvalue['date'] == $ddate && $pvalue['airline_icao'] = $airline) { |
|
1643
|
|
|
$pvalue['departure_airport_count'] = $pvalue['departure_airport_count'] + $value['departure_airport_count']; |
|
1644
|
|
|
$find = true; |
|
1645
|
|
|
break; |
|
1646
|
|
|
} |
|
1647
|
|
|
} |
|
1648
|
|
|
if ($find === false) { |
|
1649
|
|
|
$pall[] = $value; |
|
1650
|
|
|
} |
|
1651
|
|
|
} |
|
1652
|
|
|
$alldata = $pall; |
|
1653
|
|
|
foreach ($alldata as $number) { |
|
1654
|
|
|
$this->addStatDepartureAirportsDaily($number['date'],$number['departure_airport_icao'],$number['departure_airport_name'],$number['departure_airport_city'],$number['departure_airport_country'],$number['departure_airport_count'],$number['airline_icao']); |
|
1655
|
|
|
} |
|
1656
|
|
|
echo '...Arrival'."\n"; |
|
1657
|
|
|
$pall = $Spotter->getLast7DaysAirportsArrivalByAirlines(); |
|
1658
|
|
|
$dall = $Spotter->getLast7DaysDetectedAirportsArrivalByAirlines(); |
|
1659
|
|
|
foreach ($dall as $value) { |
|
1660
|
|
|
$icao = $value['arrival_airport_icao']; |
|
1661
|
|
|
$airline = $value['airline_icao']; |
|
1662
|
|
|
$ddate = $value['date']; |
|
1663
|
|
|
$find = false; |
|
1664
|
|
|
foreach ($pall as $pvalue) { |
|
1665
|
|
|
if ($pvalue['arrival_airport_icao'] == $icao && $pvalue['date'] == $ddate && $pvalue['airline_icao'] == $airline) { |
|
1666
|
|
|
$pvalue['arrival_airport_count'] = $pvalue['arrival_airport_count'] + $value['arrival_airport_count']; |
|
1667
|
|
|
$find = true; |
|
1668
|
|
|
break; |
|
1669
|
|
|
} |
|
1670
|
|
|
} |
|
1671
|
|
|
if ($find === false) { |
|
1672
|
|
|
$pall[] = $value; |
|
1673
|
|
|
} |
|
1674
|
|
|
} |
|
1675
|
|
|
$alldata = $pall; |
|
1676
|
|
|
foreach ($alldata as $number) { |
|
1677
|
|
|
$this->addStatArrivalAirportsDaily($number['date'],$number['arrival_airport_icao'],$number['arrival_airport_name'],$number['arrival_airport_city'],$number['arrival_airport_country'],$number['arrival_airport_count'],$number['airline_icao']); |
|
1678
|
|
|
} |
|
1679
|
|
|
|
|
1680
|
|
|
echo 'Flights data...'."\n"; |
|
1681
|
|
|
echo '-> countAllDatesLastMonth...'."\n"; |
|
1682
|
|
|
$alldata = $Spotter->countAllDatesLastMonthByAirlines(); |
|
1683
|
|
|
foreach ($alldata as $number) { |
|
1684
|
|
|
$this->addStatFlight('month',$number['date_name'],$number['date_count'], $number['airline_icao']); |
|
1685
|
|
|
} |
|
1686
|
|
|
echo '-> countAllDates...'."\n"; |
|
1687
|
|
|
$previousdata = $this->countAllDatesByAirlines(); |
|
1688
|
|
|
$alldata = $Common->array_merge_noappend($previousdata,$Spotter->countAllDatesByAirlines()); |
|
1689
|
|
|
$values = array(); |
|
1690
|
|
|
foreach ($alldata as $cnt) { |
|
1691
|
|
|
$values[] = $cnt['date_count']; |
|
1692
|
|
|
} |
|
1693
|
|
|
array_multisort($values,SORT_DESC,$alldata); |
|
1694
|
|
|
array_splice($alldata,11); |
|
1695
|
|
|
foreach ($alldata as $number) { |
|
1696
|
|
|
$this->addStatFlight('date',$number['date_name'],$number['date_count'],$number['airline_icao']); |
|
1697
|
|
|
} |
|
1698
|
|
|
|
|
1699
|
|
|
echo '-> countAllHours...'."\n"; |
|
1700
|
|
|
$alldata = $Spotter->countAllHoursByAirlines('hour'); |
|
1701
|
|
|
foreach ($alldata as $number) { |
|
1702
|
|
|
$this->addStatFlight('hour',$number['hour_name'],$number['hour_count'],$number['airline_icao']); |
|
1703
|
|
|
} |
|
1704
|
|
|
|
|
1705
|
|
|
|
|
1706
|
|
|
if (!isset($globalStatsFilters) || $globalStatsFilters == '') $globalStatsFilters = array(); |
|
1707
|
|
|
foreach ($globalStatsFilters as $name => $filter) { |
|
1708
|
|
|
//$filter_name = $filter['name']; |
|
1709
|
|
|
$filter_name = $name; |
|
1710
|
|
|
// Count by filter |
|
1711
|
|
|
echo '--- Stats by airlines ---'."\n"; |
|
1712
|
|
|
$Spotter = new Spotter($this->db); |
|
1713
|
|
|
$alldata = $Spotter->countAllAircraftTypes(false,0,$last_update_day,$filter); |
|
1714
|
|
|
foreach ($alldata as $number) { |
|
1715
|
|
|
$this->addStatAircraft($number['aircraft_icao'],$number['aircraft_icao_count'],$number['aircraft_name'],$number['aircraft_manufacturer'],'',$filter_name); |
|
1716
|
|
|
} |
|
1717
|
|
|
$alldata = $Spotter->countAllAircraftRegistrations(false,0,$last_update_day,$filter); |
|
1718
|
|
|
foreach ($alldata as $number) { |
|
1719
|
|
|
$this->addStatAircraftRegistration($number['registration'],$number['aircraft_registration_count'],$number['aircraft_icao'],'',$filter_name); |
|
1720
|
|
|
} |
|
1721
|
|
|
$alldata = $Spotter->countAllCallsigns(false,0,$last_update_day,$filter); |
|
1722
|
|
|
foreach ($alldata as $number) { |
|
1723
|
|
|
$this->addStatCallsign($number['callsign_icao'],$number['callsign_icao_count'],'',$filter_name); |
|
1724
|
|
|
} |
|
1725
|
|
|
$alldata = $Spotter->countAllOwners(false,0,$last_update_day,$filter); |
|
1726
|
|
|
foreach ($alldata as $number) { |
|
1727
|
|
|
$this->addStatOwner($number['owner_name'],$number['owner_count'],'',$filter_name); |
|
1728
|
|
|
} |
|
1729
|
|
|
$alldata = $Spotter->countAllPilots(false,0,$last_update_day,$filter); |
|
1730
|
|
|
foreach ($alldata as $number) { |
|
1731
|
|
|
$this->addStatPilot($number['pilot_id'],$number['pilot_count'],$number['pilot_name'],'',$filter_name); |
|
1732
|
|
|
} |
|
1733
|
|
|
|
|
1734
|
|
|
$pall = $Spotter->countAllDepartureAirports(false,0,$last_update_day,$filter); |
|
1735
|
|
|
$dall = $Spotter->countAllDetectedDepartureAirports(false,0,$last_update_day,$filter); |
|
1736
|
|
|
//$alldata = array(); |
|
1737
|
|
|
foreach ($dall as $value) { |
|
1738
|
|
|
$icao = $value['airport_departure_icao']; |
|
1739
|
|
|
$dicao = $value['airline_icap']; |
|
1740
|
|
|
$find = false; |
|
1741
|
|
|
foreach ($pall as $pvalue) { |
|
1742
|
|
|
if ($pvalue['airport_departure_icao'] == $icao && $pvalue['airline_icao'] = $dicao) { |
|
1743
|
|
|
$pvalue['airport_departure_icao_count'] = $pvalue['airport_departure_icao_count'] + $value['airport_departure_icao_count']; |
|
1744
|
|
|
$find = true; |
|
1745
|
|
|
break; |
|
1746
|
|
|
} |
|
1747
|
|
|
} |
|
1748
|
|
|
if ($find === false) { |
|
1749
|
|
|
$pall[] = $value; |
|
1750
|
|
|
} |
|
1751
|
|
|
} |
|
1752
|
|
|
$alldata = $pall; |
|
1753
|
|
|
foreach ($alldata as $number) { |
|
1754
|
|
|
echo $this->addStatDepartureAirports($number['airport_departure_icao'],$number['airport_departure_name'],$number['airport_departure_city'],$number['airport_departure_country'],$number['airport_departure_icao_count'],'',$filter_name); |
|
1755
|
|
|
} |
|
1756
|
|
|
$pall = $Spotter->countAllArrivalAirports(false,0,$last_update_day,$filter); |
|
1757
|
|
|
$dall = $Spotter->countAllDetectedArrivalAirports(false,0,$last_update_day,$filter); |
|
1758
|
|
|
//$alldata = array(); |
|
1759
|
|
|
foreach ($dall as $value) { |
|
1760
|
|
|
$icao = $value['airport_arrival_icao']; |
|
1761
|
|
|
$dicao = $value['airline_icao']; |
|
1762
|
|
|
$find = false; |
|
1763
|
|
|
foreach ($pall as $pvalue) { |
|
1764
|
|
|
if ($pvalue['airport_arrival_icao'] == $icao && $pvalue['airline_icao'] = $dicao) { |
|
1765
|
|
|
$pvalue['airport_arrival_icao_count'] = $pvalue['airport_arrival_icao_count'] + $value['airport_arrival_icao_count']; |
|
1766
|
|
|
$find = true; |
|
1767
|
|
|
break; |
|
1768
|
|
|
} |
|
1769
|
|
|
} |
|
1770
|
|
|
if ($find === false) { |
|
1771
|
|
|
$pall[] = $value; |
|
1772
|
|
|
} |
|
1773
|
|
|
} |
|
1774
|
|
|
$alldata = $pall; |
|
1775
|
|
|
foreach ($alldata as $number) { |
|
1776
|
|
|
echo $this->addStatArrivalAirports($number['airport_arrival_icao'],$number['airport_arrival_name'],$number['airport_arrival_city'],$number['airport_arrival_country'],$number['airport_arrival_icao_count'],'',$filter_name); |
|
1777
|
|
|
} |
|
1778
|
|
|
$Spotter = new Spotter($this->db); |
|
1779
|
|
|
$alldata = $Spotter->countAllMonths($filter); |
|
1780
|
|
|
$lastyear = false; |
|
1781
|
|
|
foreach ($alldata as $number) { |
|
1782
|
|
|
if ($number['year_name'] != date('Y')) $lastyear = true; |
|
1783
|
|
|
$this->addStat('flights_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])),'',$filter_name); |
|
1784
|
|
|
} |
|
1785
|
|
|
$alldata = $Spotter->countAllMonthsOwners($filter); |
|
1786
|
|
|
foreach ($alldata as $number) { |
|
1787
|
|
|
$this->addStat('owners_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])),'',$filter_name); |
|
1788
|
|
|
} |
|
1789
|
|
|
$alldata = $Spotter->countAllMonthsPilots($filter); |
|
1790
|
|
|
foreach ($alldata as $number) { |
|
1791
|
|
|
$this->addStat('pilots_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])),'',$filter_name); |
|
1792
|
|
|
} |
|
1793
|
|
|
$alldata = $Spotter->countAllMonthsAircrafts($filter); |
|
1794
|
|
|
foreach ($alldata as $number) { |
|
1795
|
|
|
$this->addStat('aircrafts_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])),'',$filter_name); |
|
1796
|
|
|
} |
|
1797
|
|
|
$alldata = $Spotter->countAllMonthsRealArrivals($filter); |
|
1798
|
|
|
foreach ($alldata as $number) { |
|
1799
|
|
|
$this->addStat('realarrivals_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])),'',$filter_name); |
|
1800
|
|
|
} |
|
1801
|
|
|
echo '...Departure'."\n"; |
|
1802
|
|
|
$pall = $Spotter->getLast7DaysAirportsDeparture($filter); |
|
1803
|
|
|
$dall = $Spotter->getLast7DaysDetectedAirportsDeparture($filter); |
|
1804
|
|
|
foreach ($dall as $value) { |
|
1805
|
|
|
$icao = $value['departure_airport_icao']; |
|
1806
|
|
|
$airline = $value['airline_icao']; |
|
1807
|
|
|
$ddate = $value['date']; |
|
1808
|
|
|
$find = false; |
|
1809
|
|
|
foreach ($pall as $pvalue) { |
|
1810
|
|
|
if ($pvalue['departure_airport_icao'] == $icao && $pvalue['date'] == $ddate && $pvalue['airline_icao'] = $airline) { |
|
1811
|
|
|
$pvalue['departure_airport_count'] = $pvalue['departure_airport_count'] + $value['departure_airport_count']; |
|
1812
|
|
|
$find = true; |
|
1813
|
|
|
break; |
|
1814
|
|
|
} |
|
1815
|
|
|
} |
|
1816
|
|
|
if ($find === false) { |
|
1817
|
|
|
$pall[] = $value; |
|
1818
|
|
|
} |
|
1819
|
|
|
} |
|
1820
|
|
|
$alldata = $pall; |
|
1821
|
|
|
foreach ($alldata as $number) { |
|
1822
|
|
|
$this->addStatDepartureAirportsDaily($number['date'],$number['departure_airport_icao'],$number['departure_airport_name'],$number['departure_airport_city'],$number['departure_airport_country'],$number['departure_airport_count'],'',$filter_name); |
|
1823
|
|
|
} |
|
1824
|
|
|
echo '...Arrival'."\n"; |
|
1825
|
|
|
$pall = $Spotter->getLast7DaysAirportsArrival($filter); |
|
1826
|
|
|
$dall = $Spotter->getLast7DaysDetectedAirportsArrival($filter); |
|
1827
|
|
|
foreach ($dall as $value) { |
|
1828
|
|
|
$icao = $value['arrival_airport_icao']; |
|
1829
|
|
|
$airline = $value['airline_icao']; |
|
1830
|
|
|
$ddate = $value['date']; |
|
1831
|
|
|
$find = false; |
|
1832
|
|
|
foreach ($pall as $pvalue) { |
|
1833
|
|
|
if ($pvalue['arrival_airport_icao'] == $icao && $pvalue['date'] == $ddate && $pvalue['airline_icao'] == $airline) { |
|
1834
|
|
|
$pvalue['arrival_airport_count'] = $pvalue['arrival_airport_count'] + $value['arrival_airport_count']; |
|
1835
|
|
|
$find = true; |
|
1836
|
|
|
break; |
|
1837
|
|
|
} |
|
1838
|
|
|
} |
|
1839
|
|
|
if ($find === false) { |
|
1840
|
|
|
$pall[] = $value; |
|
1841
|
|
|
} |
|
1842
|
|
|
} |
|
1843
|
|
|
$alldata = $pall; |
|
1844
|
|
|
foreach ($alldata as $number) { |
|
1845
|
|
|
$this->addStatArrivalAirportsDaily($number['date'],$number['arrival_airport_icao'],$number['arrival_airport_name'],$number['arrival_airport_city'],$number['arrival_airport_country'],$number['arrival_airport_count'],'',$filter_name); |
|
1846
|
|
|
} |
|
1847
|
|
|
|
|
1848
|
|
|
echo 'Flights data...'."\n"; |
|
1849
|
|
|
echo '-> countAllDatesLastMonth...'."\n"; |
|
1850
|
|
|
$alldata = $Spotter->countAllDatesLastMonth($filter); |
|
1851
|
|
|
foreach ($alldata as $number) { |
|
1852
|
|
|
$this->addStatFlight('month',$number['date_name'],$number['date_count'], '',$filter_name); |
|
1853
|
|
|
} |
|
1854
|
|
|
echo '-> countAllDates...'."\n"; |
|
1855
|
|
|
$previousdata = $this->countAllDates($filter); |
|
1856
|
|
|
$alldata = $Common->array_merge_noappend($previousdata,$Spotter->countAllDates($filter)); |
|
1857
|
|
|
$values = array(); |
|
1858
|
|
|
foreach ($alldata as $cnt) { |
|
1859
|
|
|
$values[] = $cnt['date_count']; |
|
1860
|
|
|
} |
|
1861
|
|
|
array_multisort($values,SORT_DESC,$alldata); |
|
1862
|
|
|
array_splice($alldata,11); |
|
1863
|
|
|
foreach ($alldata as $number) { |
|
1864
|
|
|
$this->addStatFlight('date',$number['date_name'],$number['date_count'],'',$filter_name); |
|
1865
|
|
|
} |
|
1866
|
|
|
|
|
1867
|
|
|
echo '-> countAllHours...'."\n"; |
|
1868
|
|
|
$alldata = $Spotter->countAllHours('hour',$filter); |
|
1869
|
|
|
foreach ($alldata as $number) { |
|
1870
|
|
|
$this->addStatFlight('hour',$number['hour_name'],$number['hour_count'],'',$filter_name); |
|
1871
|
|
|
} |
|
1872
|
|
|
} |
|
1873
|
|
|
|
|
1874
|
|
|
|
|
1875
|
|
|
// Last year stats |
|
1876
|
|
|
if ($lastyear) { |
|
1877
|
|
|
echo 'Data from last year...'."\n"; |
|
1878
|
|
|
// SUM all previous month to put as year |
|
1879
|
|
|
$previous_year = date('Y'); |
|
1880
|
|
|
$previous_year--; |
|
1881
|
|
|
$this->addStat('aircrafts_byyear',$this->getSumStats('aircrafts_bymonth',$previous_year),$previous_year.'-01-01 00:00:00'); |
|
1882
|
|
|
$this->addStat('airlines_byyear',$this->getSumStats('airlines_bymonth',$previous_year),$previous_year.'-01-01 00:00:00'); |
|
1883
|
|
|
$this->addStat('owner_byyear',$this->getSumStats('owner_bymonth',$previous_year),$previous_year.'-01-01 00:00:00'); |
|
1884
|
|
|
$this->addStat('pilot_byyear',$this->getSumStats('pilot_bymonth',$previous_year),$previous_year.'-01-01 00:00:00'); |
|
1885
|
|
|
$allairlines = $this->getAllAirlineNames(); |
|
1886
|
|
|
foreach ($allairlines as $data) { |
|
1887
|
|
|
$this->addStat('aircrafts_byyear',$this->getSumStats('aircrafts_bymonth',$previous_year,$data['airline_icao']),$previous_year.'-01-01 00:00:00',$data['airline_icao']); |
|
1888
|
|
|
$this->addStat('airlines_byyear',$this->getSumStats('airlines_bymonth',$previous_year,$data['airline_icao']),$previous_year.'-01-01 00:00:00',$data['airline_icao']); |
|
1889
|
|
|
$this->addStat('owner_byyear',$this->getSumStats('owner_bymonth',$previous_year,$data['airline_icao']),$previous_year.'-01-01 00:00:00',$data['airline_icao']); |
|
1890
|
|
|
$this->addStat('pilot_byyear',$this->getSumStats('pilot_bymonth',$previous_year,$data['airline_icao']),$previous_year.'-01-01 00:00:00',$data['airline_icao']); |
|
1891
|
|
|
} |
|
1892
|
|
|
|
|
1893
|
|
|
if (isset($globalArchiveYear) && $globalArchiveYear) { |
|
1894
|
|
|
if ($globalArchive) { |
|
1895
|
|
|
$query = "INSERT INTO spotter_archive_output SELECT * FROM spotter_output WHERE spotter_output.date < '".date('Y')."-01-01 00:00:00'"; |
|
1896
|
|
|
try { |
|
1897
|
|
|
$sth = $this->db->prepare($query); |
|
1898
|
|
|
$sth->execute(); |
|
1899
|
|
|
} catch(PDOException $e) { |
|
1900
|
|
|
return "error : ".$e->getMessage().' - query : '.$query."\n"; |
|
1901
|
|
|
} |
|
1902
|
|
|
} |
|
1903
|
|
|
echo 'Delete old data'."\n"; |
|
1904
|
|
|
$query = "DELETE FROM spotter_output WHERE spotter_output.date < '".date('Y')."-01-01 00:00:00'"; |
|
1905
|
|
|
try { |
|
1906
|
|
|
$sth = $this->db->prepare($query); |
|
1907
|
|
|
$sth->execute(); |
|
1908
|
|
|
} catch(PDOException $e) { |
|
1909
|
|
|
return "error : ".$e->getMessage().' - query : '.$query."\n"; |
|
1910
|
|
|
} |
|
1911
|
|
|
} |
|
1912
|
|
|
} |
|
1913
|
|
|
if ($globalArchiveMonths > 0) { |
|
1914
|
|
|
if ($globalArchive) { |
|
1915
|
|
|
echo 'Archive old data...'."\n"; |
|
1916
|
|
|
if ($globalDBdriver == 'mysql') { |
|
1917
|
|
|
//$query = "INSERT INTO spotter_archive_output SELECT * FROM spotter_output WHERE spotter_output.date < DATE_FORMAT(UTC_TIMESTAMP() - INTERVAL ".$globalArchiveMonths." MONTH, '%Y/%m/01')"; |
|
1918
|
|
|
$query = "INSERT INTO spotter_archive_output (spotter_id,flightaware_id,ident,registration,airline_name,airline_icao,airline_country,airline_type,aircraft_icao,aircraft_name,aircraft_manufacturer,departure_airport_icao,departure_airport_name,departure_airport_city,departure_airport_country,departure_airport_time,arrival_airport_icao,arrival_airport_name,arrival_airport_city,arrival_airport_country,arrival_airport_time,route_stop,date,latitude,longitude,waypoints,altitude,heading,ground_speed,highlight,squawk,ModeS,pilot_id,pilot_name,owner_name,verticalrate,format_source,source_name,ground,last_ground,last_seen,last_latitude,last_longitude,last_altitude,last_ground_speed,real_arrival_airport_icao,real_arrival_airport_time,real_departure_airport_icao,real_departure_airport_time) |
|
1919
|
|
|
SELECT spotter_id,flightaware_id,ident,registration,airline_name,airline_icao,airline_country,airline_type,aircraft_icao,aircraft_name,aircraft_manufacturer,departure_airport_icao,departure_airport_name,departure_airport_city,departure_airport_country,departure_airport_time,arrival_airport_icao,arrival_airport_name,arrival_airport_city,arrival_airport_country,arrival_airport_time,route_stop,date,latitude,longitude,waypoints,altitude,heading,ground_speed,highlight,squawk,ModeS,pilot_id,pilot_name,owner_name,verticalrate,format_source,source_name,ground,last_ground,last_seen,last_latitude,last_longitude,last_altitude,last_ground_speed,real_arrival_airport_icao,real_arrival_airport_time,real_departure_airport_icao,real_departure_airport_time |
|
1920
|
|
|
FROM spotter_output WHERE spotter_output.date < DATE_FORMAT(UTC_TIMESTAMP() - INTERVAL ".$globalArchiveMonths." MONTH, '%Y/%m/01')"; |
|
1921
|
|
|
} else { |
|
1922
|
|
|
$query = "INSERT INTO spotter_archive_output (spotter_id,flightaware_id,ident,registration,airline_name,airline_icao,airline_country,airline_type,aircraft_icao,aircraft_name,aircraft_manufacturer,departure_airport_icao,departure_airport_name,departure_airport_city,departure_airport_country,departure_airport_time,arrival_airport_icao,arrival_airport_name,arrival_airport_city,arrival_airport_country,arrival_airport_time,route_stop,date,latitude,longitude,waypoints,altitude,heading,ground_speed,highlight,squawk,ModeS,pilot_id,pilot_name,owner_name,verticalrate,format_source,source_name,ground,last_ground,last_seen,last_latitude,last_longitude,last_altitude,last_ground_speed,real_arrival_airport_icao,real_arrival_airport_time,real_departure_airport_icao,real_departure_airport_time) |
|
1923
|
|
|
SELECT |
|
1924
|
|
|
spotter_id,flightaware_id,ident,registration,airline_name,airline_icao,airline_country,airline_type,aircraft_icao,aircraft_name,aircraft_manufacturer,departure_airport_icao,departure_airport_name,departure_airport_city,departure_airport_country,departure_airport_time,arrival_airport_icao,arrival_airport_name,arrival_airport_city,arrival_airport_country,arrival_airport_time,route_stop,date,latitude,longitude,waypoints,altitude,heading,ground_speed,highlight,squawk,ModeS,pilot_id,pilot_name,owner_name,verticalrate,format_source,source_name,ground,last_ground,last_seen,last_latitude,last_longitude,last_altitude,last_ground_speed,real_arrival_airport_icao,real_arrival_airport_time,real_departure_airport_icao,real_departure_airport_time |
|
1925
|
|
|
FROM spotter_output WHERE spotter_output.date < CAST(to_char(CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalArchiveMonths." MONTHS', 'YYYY/mm/01') AS TIMESTAMP)"; |
|
1926
|
|
|
} |
|
1927
|
|
|
try { |
|
1928
|
|
|
$sth = $this->db->prepare($query); |
|
1929
|
|
|
$sth->execute(); |
|
1930
|
|
|
} catch(PDOException $e) { |
|
1931
|
|
|
return "error : ".$e->getMessage(); |
|
1932
|
|
|
} |
|
1933
|
|
|
} |
|
1934
|
|
|
echo 'Deleting old data...'."\n"; |
|
1935
|
|
|
//$query = 'DELETE FROM spotter_output WHERE spotter_output.date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$globalArchiveMonths.' MONTH)'; |
|
1936
|
|
|
if ($globalDBdriver == 'mysql') { |
|
1937
|
|
|
$query = "DELETE FROM spotter_output WHERE spotter_output.date < DATE_FORMAT(UTC_TIMESTAMP() - INTERVAL ".$globalArchiveMonths." MONTH, '%Y/%m/01')"; |
|
1938
|
|
|
} else { |
|
1939
|
|
|
$query = "DELETE FROM spotter_output WHERE spotter_output.date < CAST(to_char(CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalArchiveMonths." MONTHS', 'YYYY/mm/01') AS TIMESTAMP)"; |
|
1940
|
|
|
} |
|
1941
|
|
|
try { |
|
1942
|
|
|
$sth = $this->db->prepare($query); |
|
1943
|
|
|
$sth->execute(); |
|
1944
|
|
|
} catch(PDOException $e) { |
|
1945
|
|
|
return "error : ".$e->getMessage(); |
|
1946
|
|
|
} |
|
1947
|
|
|
} |
|
1948
|
|
|
echo 'Insert last stats update date...'."\n"; |
|
1949
|
|
|
date_default_timezone_set('UTC'); |
|
1950
|
|
|
$this->addLastStatsUpdate('last_update_stats',date('Y-m-d G:i:s')); |
|
1951
|
|
|
//} |
|
1952
|
|
|
} |
|
1953
|
|
|
} |
|
1954
|
|
|
|
|
1955
|
|
|
?> |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignorePhpDoc annotation to the duplicate definition and it will be ignored.