|
@@ 75-127 (lines=53) @@
|
| 72 |
|
* @return Array the spotter information |
| 73 |
|
* |
| 74 |
|
*/ |
| 75 |
|
public function getMinLiveSpotterData($filter = array()) |
| 76 |
|
{ |
| 77 |
|
global $globalDBdriver, $globalLiveInterval; |
| 78 |
|
date_default_timezone_set('UTC'); |
| 79 |
|
|
| 80 |
|
$filter_query = ''; |
| 81 |
|
if (isset($filter['source']) && !empty($filter['source'])) { |
| 82 |
|
$filter_query .= " AND format_source IN ('".implode("','",$filter['source'])."') "; |
| 83 |
|
} |
| 84 |
|
if (isset($filter['airlines']) && !empty($filter['airlines'])) { |
| 85 |
|
$filter_query .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_icao IN ('".implode("','",$filter['airlines'])."')) so ON so.flightaware_id = spotter_live.flightaware_id "; |
| 86 |
|
} |
| 87 |
|
if (isset($filter['airlinestype']) && !empty($filter['airlinestype'])) { |
| 88 |
|
$filter_query .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_type = '".$filter['airlinestype']."') sa ON sa.flightaware_id = spotter_live.flightaware_id "; |
| 89 |
|
} |
| 90 |
|
if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) { |
| 91 |
|
$filter_query = " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')"; |
| 92 |
|
} |
| 93 |
|
|
| 94 |
|
if (!isset($globalLiveInterval)) $globalLiveInterval = '200'; |
| 95 |
|
if ($globalDBdriver == 'mysql') { |
| 96 |
|
// $query = "SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL ".$globalLiveInterval." SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate$orderby_query"; |
| 97 |
|
// $query = 'SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, a.aircraft_shadow FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate INNER JOIN (SELECT * FROM aircraft) a on spotter_live.aircraft_icao = a.icao'; |
| 98 |
|
// $query = 'SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate'.$filter_query; |
| 99 |
|
|
| 100 |
|
$query = 'SELECT a.aircraft_shadow, spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source |
| 101 |
|
FROM spotter_live |
| 102 |
|
INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate '.$filter_query.'LEFT JOIN (SELECT aircraft_shadow,icao FROM aircraft) a ON spotter_live.aircraft_icao = a.icao'; |
| 103 |
|
|
| 104 |
|
// $query = 'SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk FROM spotter_live WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= spotter_live.date ORDER BY spotter_live.date GROUP BY spotter_live.flightaware_id'.$filter_query; |
| 105 |
|
|
| 106 |
|
//$query = 'SELECT a.aircraft_shadow, spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk FROM spotter_live WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date '.$filter_query.'LEFT JOIN (SELECT aircraft_shadow,icao FROM aircraft) a ON spotter_live.aircraft_icao = a.icao'; |
| 107 |
|
} else if ($globalDBdriver == 'pgsql') { |
| 108 |
|
//$query = "SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE NOW() AT TIME ZONE 'UTC' - '30 SECONDS'->INTERVAL <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate"; |
| 109 |
|
//$query = "SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE NOW() AT TIME ZONE 'UTC' - '".$globalLiveInterval." SECONDS'->INTERVAL <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate$orderby_query"; |
| 110 |
|
//$query = 'SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, a.aircraft_shadow FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate '.$filter_query.'INNER JOIN (SELECT * FROM aircraft) a on spotter_live.aircraft_icao = a.icao'; |
| 111 |
|
$query = "SELECT a.aircraft_shadow, spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source |
| 112 |
|
FROM spotter_live |
| 113 |
|
INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate ".$filter_query.'LEFT JOIN (SELECT aircraft_shadow,icao FROM aircraft) a ON spotter_live.aircraft_icao = a.icao'; |
| 114 |
|
} |
| 115 |
|
// $spotter_array = Spotter->getDataFromDB($query.$limit_query); |
| 116 |
|
//echo $query; |
| 117 |
|
|
| 118 |
|
try { |
| 119 |
|
$sth = $this->db->prepare($query); |
| 120 |
|
$sth->execute(); |
| 121 |
|
} catch(PDOException $e) { |
| 122 |
|
return "error"; |
| 123 |
|
} |
| 124 |
|
$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC); |
| 125 |
|
|
| 126 |
|
return $spotter_array; |
| 127 |
|
} |
| 128 |
|
|
| 129 |
|
/** |
| 130 |
|
* Gets Minimal Live Spotter data since xx seconds |
|
@@ 135-181 (lines=47) @@
|
| 132 |
|
* @return Array the spotter information |
| 133 |
|
* |
| 134 |
|
*/ |
| 135 |
|
public function getMinLastLiveSpotterData($filter = array()) |
| 136 |
|
{ |
| 137 |
|
global $globalDBdriver, $globalLiveInterval; |
| 138 |
|
date_default_timezone_set('UTC'); |
| 139 |
|
|
| 140 |
|
$filter_query = ''; |
| 141 |
|
if (isset($filter['source']) && !empty($filter['source'])) { |
| 142 |
|
$filter_query .= " AND format_source IN ('".implode("','",$filter['source'])."') "; |
| 143 |
|
} |
| 144 |
|
if (isset($filter['airlines']) && !empty($filter['airlines'])) { |
| 145 |
|
$filter_query .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_icao IN ('".implode("','",$filter['airlines'])."')) so ON so.flightaware_id = spotter_live.flightaware_id "; |
| 146 |
|
} |
| 147 |
|
if (isset($filter['airlinestype']) && !empty($filter['airlinestype'])) { |
| 148 |
|
$filter_query .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_type = '".$filter['airlinestype']."') sa ON sa.flightaware_id = spotter_live.flightaware_id "; |
| 149 |
|
} |
| 150 |
|
if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) { |
| 151 |
|
$filter_query = " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')"; |
| 152 |
|
} |
| 153 |
|
|
| 154 |
|
if (!isset($globalLiveInterval)) $globalLiveInterval = '200'; |
| 155 |
|
if ($globalDBdriver == 'mysql') { |
| 156 |
|
|
| 157 |
|
$query = 'SELECT a.aircraft_shadow, spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source |
| 158 |
|
FROM spotter_live LEFT JOIN (SELECT aircraft_shadow,icao FROM aircraft) a ON spotter_live.aircraft_icao = a.icao WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= spotter_live.date |
| 159 |
|
'.$filter_query.'ORDER BY spotter_live.flightaware_id, spotter_live.date'; |
| 160 |
|
} else if ($globalDBdriver == 'pgsql') { |
| 161 |
|
/* |
| 162 |
|
$query = "SELECT a.aircraft_shadow, spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source |
| 163 |
|
FROM spotter_live WHERE CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= spotter_live.date |
| 164 |
|
".$filter_query.'LEFT JOIN (SELECT aircraft_shadow,icao FROM aircraft) a ON spotter_live.aircraft_icao = a.icao ORDER BY spotter_live.flightaware_id, spotter_live.date'; |
| 165 |
|
*/ |
| 166 |
|
$query = "SELECT a.aircraft_shadow, spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source |
| 167 |
|
FROM spotter_live LEFT JOIN (SELECT aircraft_shadow, icao FROM aircraft) a ON spotter_live.aircraft_icao = a.icao WHERE CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= spotter_live.date |
| 168 |
|
".$filter_query.'ORDER BY spotter_live.flightaware_id, spotter_live.date'; |
| 169 |
|
// echo $query; |
| 170 |
|
} |
| 171 |
|
|
| 172 |
|
try { |
| 173 |
|
$sth = $this->db->prepare($query); |
| 174 |
|
$sth->execute(); |
| 175 |
|
} catch(PDOException $e) { |
| 176 |
|
return "error"; |
| 177 |
|
} |
| 178 |
|
$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC); |
| 179 |
|
|
| 180 |
|
return $spotter_array; |
| 181 |
|
} |
| 182 |
|
|
| 183 |
|
/** |
| 184 |
|
* Gets number of latest data entry |