From 3afeea81884cd80c7140f1f559e7c5e879555d4e Mon Sep 17 00:00:00 2001 From: Ycarus Date: Fri, 24 Mar 2017 19:40:44 +0100 Subject: [PATCH] Image search for VA, some fix,... --- ...ort-statistics-arrival-airport-country.php | 63 +++++++++++-------- ...t-statistics-departure-airport-country.php | 63 +++++++++++-------- require/class.APRS.php | 14 +++-- require/class.Spotter.php | 31 +++++---- 4 files changed, 97 insertions(+), 74 deletions(-) diff --git a/airport-statistics-arrival-airport-country.php b/airport-statistics-arrival-airport-country.php index aa3876c8..5d38ad63 100644 --- a/airport-statistics-arrival-airport-country.php +++ b/airport-statistics-arrival-airport-country.php @@ -59,37 +59,48 @@ print '

'._("Most Common Arrival Airports by Country").'

'; print '

'.sprintf(_("The statistic below shows all arrival airports by Country of origin of flights from %s, %s (%s)."),$airport_array[0]['city'],$airport_array[0]['name'],$airport_array[0]['icao']).'

'; $airport_country_array = $Spotter->countAllArrivalAirportCountriesByAirport($airport); - print ''; - print '
- '; + print ''; + print ''; + print '
'; + print '];'; + print 'var dataset = {};var onlyValues = series.map(function(obj){ return obj[1]; });var minValue = Math.min.apply(null, onlyValues), maxValue = Math.max.apply(null, onlyValues);'; + print 'var paletteScale = d3.scale.linear().domain([minValue,maxValue]).range(["#EFEFFF","#001830"]);'; + print 'series.forEach(function(item){var iso = item[0], value = item[1]; dataset[iso] = { numberOfThings: value, fillColor: paletteScale(value) };});'; + print 'new Datamap({ + element: document.getElementById("chartCountry"), + projection: "mercator", // big world map + fills: { defaultFill: "#F5F5F5" }, + data: dataset, + responsive: true, + geographyConfig: { + borderColor: "#DEDEDE", + highlightBorderWidth: 2, + highlightFillColor: function(geo) { + return geo["fillColor"] || "#F5F5F5"; + }, + highlightBorderColor: "#B7B7B7", + done: function(datamap) { + datamap.svg.call(d3.behavior.zoom().on("zoom", redraw)); + function redraw() { + datamap.svg.selectAll("g").attr("transform", "translate(" + d3.event.translate + ")scale(" + d3.event.scale + ")"); + } + }, + popupTemplate: function(geo, data) { + if (!data) { return ; } + return ['."'".'
'."','', geo.properties.name, '','
Count: ', data.numberOfThings, '','
'].join(''); + } + } + });"; + print ''; if (!empty($airport_country_array)) { diff --git a/airport-statistics-departure-airport-country.php b/airport-statistics-departure-airport-country.php index 182d8763..fc783b5e 100644 --- a/airport-statistics-departure-airport-country.php +++ b/airport-statistics-departure-airport-country.php @@ -60,37 +60,48 @@ print '

'.sprintf(_("The statistic below shows all departure airports by Country of origin of flights to %s, %s, (%s)."),$airport_array[0]['city'],$airport_array[0]['name'],$airport_array[0]['icao']).'

'; $airport_country_array = $Spotter->countAllDepartureAirportCountriesByAirport($airport); - print ''; - print '
- '; + print ''; + print ''; + print '
'; + print '];'; + print 'var dataset = {};var onlyValues = series.map(function(obj){ return obj[1]; });var minValue = Math.min.apply(null, onlyValues), maxValue = Math.max.apply(null, onlyValues);'; + print 'var paletteScale = d3.scale.linear().domain([minValue,maxValue]).range(["#EFEFFF","#001830"]);'; + print 'series.forEach(function(item){var iso = item[0], value = item[1]; dataset[iso] = { numberOfThings: value, fillColor: paletteScale(value) };});'; + print 'new Datamap({ + element: document.getElementById("chartCountry"), + projection: "mercator", // big world map + fills: { defaultFill: "#F5F5F5" }, + data: dataset, + responsive: true, + geographyConfig: { + borderColor: "#DEDEDE", + highlightBorderWidth: 2, + highlightFillColor: function(geo) { + return geo["fillColor"] || "#F5F5F5"; + }, + highlightBorderColor: "#B7B7B7", + done: function(datamap) { + datamap.svg.call(d3.behavior.zoom().on("zoom", redraw)); + function redraw() { + datamap.svg.selectAll("g").attr("transform", "translate(" + d3.event.translate + ")scale(" + d3.event.scale + ")"); + } + }, + popupTemplate: function(geo, data) { + if (!data) { return ; } + return ['."'".'
'."','', geo.properties.name, '','
Count: ', data.numberOfThings, '','
'].join(''); + } + } + });"; + print ''; if (!empty($airport_country_array)) { diff --git a/require/class.APRS.php b/require/class.APRS.php index f1f98355..3c6a040d 100644 --- a/require/class.APRS.php +++ b/require/class.APRS.php @@ -434,7 +434,7 @@ public function parse($input) { return $result; } - function connect() { + public function connect() { global $globalAPRSversion, $globalServerAPRSssid, $globalServerAPRSpass,$globalName, $globalServerAPRShost, $globalServerAPRSport; $aprs_connect = 0; $aprs_keep = 120; @@ -470,8 +470,12 @@ function connect() { socket_set_option($this->socket,SOL_SOCKET,SO_KEEPALIVE); } } + + public function disconnect() { + socket_close($this->socket); + } - function send($data) { + public function send($data) { if ($this->connected === false) $this->connect(); $send = socket_send( $this->socket , $data , strlen($data),0); if ($send === FALSE) { @@ -482,7 +486,7 @@ function send($data) { } class APRSSpotter extends APRS { - function addLiveSpotterData($id,$ident,$aircraft_icao,$departure_airport,$arrival_airport,$latitude,$longitude,$waypoints,$altitude,$altitude_real,$heading,$speed,$datetime,$departure_airport_time,$arrival_airport_time,$squawk,$route_stop,$hex,$putinarchive,$registration,$pilot_id,$pilot_name, $verticalrate, $noarchive, $ground,$format_source,$source_name,$over_country) { + public function addLiveSpotterData($id,$ident,$aircraft_icao,$departure_airport,$arrival_airport,$latitude,$longitude,$waypoints,$altitude,$altitude_real,$heading,$speed,$datetime,$departure_airport_time,$arrival_airport_time,$squawk,$route_stop,$hex,$putinarchive,$registration,$pilot_id,$pilot_name, $verticalrate, $noarchive, $ground,$format_source,$source_name,$over_country) { $Common = new Common(); if ($latitude != '' && $longitude != '') { $latitude = $Common->convertDM($latitude,'latitude'); @@ -511,12 +515,12 @@ function addLiveSpotterData($id,$ident,$aircraft_icao,$departure_airport,$arriva } } class APRSMarine extends APRS { - function addLiveMarineData($id, $ident, $latitude, $longitude, $heading, $speed,$datetime, $putinarchive,$mmsi,$type,$typeid,$imo,$callsign,$arrival_code,$arrival_date,$status,$noarchive,$format_source,$source_name,$over_country) { + public function addLiveMarineData($id, $ident, $latitude, $longitude, $heading, $speed,$datetime, $putinarchive,$mmsi,$type,$typeid,$imo,$callsign,$arrival_code,$arrival_date,$status,$noarchive,$format_source,$source_name,$over_country) { $Common = new Common(); if ($latitude != '' && $longitude != '') { $latitude = $Common->convertDM($latitude,'latitude'); $longitude = $Common->convertDM($longitude,'longitude'); - $coordinate = str_pad($latitude['deg'].number_format($latitude['min'],2,'.',''),7,'0',STR_PAD_LEFT).$latitude['NSEW'].'/'.str_pad($longitude['deg'].number_format($longitude['min'],2,'.',''),8,'0',STR_PAD_LEFT).$longitude['NSEW']; + $coordinate = sprintf("%02d",$latitude['deg']).str_pad(number_format($latitude['min'],2,'.',''),5,'0',STR_PAD_LEFT).$latitude['NSEW'].'/'.sprintf("%03d",$longitude['deg']).str_pad(number_format($longitude['min'],2,'.',''),5,'0',STR_PAD_LEFT).$longitude['NSEW']; $w1 = abs(ceil(($latitude['min'] - number_format($latitude['min'],2,'.',''))*1000)); $w2 = abs(ceil(($longitude['min'] - number_format($longitude['min'],2,'.',''))*1000)); $w = $w1.$w2; diff --git a/require/class.Spotter.php b/require/class.Spotter.php index 01edba73..e9cee9b8 100644 --- a/require/class.Spotter.php +++ b/require/class.Spotter.php @@ -413,12 +413,13 @@ public function getDataFromDB($query, $params = array(), $limitQuery = '',$sched $temp_array['aircraft_date_first_reg'] = $owner_info['date_first_reg']; } - if($temp_array['registration'] != "" || ($globalIVAO && isset($temp_array['aircraft_type']) && $temp_array['aircraft_type'] != '')) + if($temp_array['registration'] != "" || (($globalIVAO || $globalVATSIM || $globalphpVMS || $globalVAM) && isset($temp_array['aircraft_type']) && $temp_array['aircraft_type'] != '')) { if ($globalIVAO) { if (isset($temp_array['airline_icao'])) $image_array = $Image->getSpotterImage('',$temp_array['aircraft_type'],$temp_array['airline_icao']); else $image_array = $Image->getSpotterImage('',$temp_array['aircraft_type']); - } else $image_array = $Image->getSpotterImage($temp_array['registration']); + } elseif (isset($temp_array['aircraft_type'])) $image_array = $Image->getSpotterImage($temp_array['registration'],$temp_array['aircraft_type']); + else $image_array = $Image->getSpotterImage($temp_array['registration']); if (count($image_array) > 0) { $temp_array['image'] = $image_array[0]['image']; $temp_array['image_thumbnail'] = $image_array[0]['image_thumbnail']; @@ -3812,7 +3813,7 @@ public function addSpotterData($flightaware_id = '', $ident = '', $aircraft_icao if ($owner_info['owner'] != '') $aircraft_owner = ucwords(strtolower($owner_info['owner'])); } - if ($globalIVAO && $aircraft_icao != '') + if (($globalIVAO || $globalVATSIM || $globalphpVMS || $globalVAM) && $aircraft_icao != '') { if (isset($airline_array[0]['icao'])) $airline_icao = $airline_array[0]['icao']; else $airline_icao = ''; @@ -7164,11 +7165,10 @@ public function countAllDepartureAirportCountriesByAirport($airport_icao,$filter { $filter_query = $this->getFilter($filters,true,true); $airport_icao = filter_var($airport_icao,FILTER_SANITIZE_STRING); - $query = "SELECT DISTINCT spotter_output.departure_airport_country, COUNT(spotter_output.departure_airport_country) AS airport_departure_country_count - FROM spotter_output".$filter_query." spotter_output.departure_airport_country <> '' AND spotter_output.arrival_airport_icao = :airport_icao - GROUP BY spotter_output.departure_airport_country - ORDER BY airport_departure_country_count DESC"; - + $query = "SELECT DISTINCT spotter_output.departure_airport_country, COUNT(spotter_output.departure_airport_country) AS airport_departure_country_count, countries.iso3 AS departure_airport_country_iso3 + FROM countries,spotter_output".$filter_query." countries.name = spotter_output.departure_airport_country AND spotter_output.departure_airport_country <> '' AND spotter_output.arrival_airport_icao = :airport_icao + GROUP BY spotter_output.departure_airport_country, countries.iso3 + ORDER BY airport_departure_country_count DESC"; $sth = $this->db->prepare($query); $sth->execute(array(':airport_icao' => $airport_icao)); @@ -7180,10 +7180,9 @@ public function countAllDepartureAirportCountriesByAirport($airport_icao,$filter { $temp_array['departure_airport_country'] = $row['departure_airport_country']; $temp_array['airport_departure_country_count'] = $row['airport_departure_country_count']; - + $temp_array['departure_airport_country_iso3'] = $row['departure_airport_country_iso3']; $airport_array[] = $temp_array; } - return $airport_array; } @@ -8163,11 +8162,10 @@ public function countAllArrivalAirportCountriesByAirport($airport_icao,$filters { $filter_query = $this->getFilter($filters,true,true); $airport_icao = filter_var($airport_icao,FILTER_SANITIZE_STRING); - $query = "SELECT DISTINCT spotter_output.arrival_airport_country, COUNT(spotter_output.arrival_airport_country) AS airport_arrival_country_count - FROM spotter_output".$filter_query." spotter_output.arrival_airport_country <> '' AND spotter_output.departure_airport_icao = :airport_icao - GROUP BY spotter_output.arrival_airport_country - ORDER BY airport_arrival_country_count DESC"; - + $query = "SELECT DISTINCT spotter_output.arrival_airport_country, COUNT(spotter_output.arrival_airport_country) AS airport_arrival_country_count, countries.iso3 AS arrival_airport_country_iso3 + FROM countries, spotter_output".$filter_query." countries.name = spotter_output.arrival_airport_country AND spotter_output.arrival_airport_country <> '' AND spotter_output.departure_airport_icao = :airport_icao + GROUP BY spotter_output.arrival_airport_country, countries.iso3 + ORDER BY airport_arrival_country_count DESC"; $sth = $this->db->prepare($query); $sth->execute(array(':airport_icao' => $airport_icao)); @@ -8179,10 +8177,9 @@ public function countAllArrivalAirportCountriesByAirport($airport_icao,$filters { $temp_array['arrival_airport_country'] = $row['arrival_airport_country']; $temp_array['airport_arrival_country_count'] = $row['airport_arrival_country_count']; - + $temp_array['arrival_airport_country_iso3'] = $row['arrival_airport_country_iso3']; $airport_array[] = $temp_array; } - return $airport_array; }