Skip to content

Commit

Permalink
Image search for VA, some fix,...
Browse files Browse the repository at this point in the history
  • Loading branch information
Ysurac committed Mar 24, 2017
1 parent a24ad0b commit 3afeea8
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 74 deletions.
63 changes: 37 additions & 26 deletions airport-statistics-arrival-airport-country.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,37 +59,48 @@
print '<h2>'._("Most Common Arrival Airports by Country").'</h2>';
print '<p>'.sprintf(_("The statistic below shows all arrival airports by Country of origin of flights from <strong>%s, %s (%s)</strong>."),$airport_array[0]['city'],$airport_array[0]['name'],$airport_array[0]['icao']).'</p>';
$airport_country_array = $Spotter->countAllArrivalAirportCountriesByAirport($airport);
print '<script type="text/javascript" src="https://www.google.com/jsapi"></script>';
print '<div id="chartCountry" class="chart" width="100%"></div>
<script>
google.load("visualization", "1", {packages:["geochart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
["'._("Country").'", "'._("# of times").'"], ';
$country_data = '';
print '<script type="text/javascript" src="'.$globalURL.'/js/d3.min.js"></script>';
print '<script type="text/javascript" src="'.$globalURL.'/js/topojson.v2.min.js"></script>';
print '<script type="text/javascript" src="'.$globalURL.'/js/datamaps.world.min.js"></script>';
print '<div id="chartCountry" class="chart" width="100%"></div><script>';
print 'var series = [';
$country_data = '';
foreach($airport_country_array as $airport_item)
{
$country_data .= '[ "'.$airport_item['arrival_airport_country'].'",'.$airport_item['airport_arrival_country_count'].'],';
$country_data .= '[ "'.$airport_item['arrival_airport_country_iso3'].'",'.$airport_item['airport_arrival_country_count'].'],';
}
$country_data = substr($country_data, 0, -1);
print $country_data;
print ']);
var options = {
legend: {position: "none"},
chartArea: {"width": "80%", "height": "60%"},
height:500,
colors: ["#8BA9D0","#1a3151"]
};
var chart = new google.visualization.GeoChart(document.getElementById("chartCountry"));
chart.draw(data, options);
}
$(window).resize(function(){
drawChart();
});
</script>';
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 ['."'".'<div class="hoverinfo">'."','<strong>', geo.properties.name, '</strong>','<br>Count: <strong>', data.numberOfThings, '</strong>','</div>'].join('');
}
}
});";
print '</script>';

if (!empty($airport_country_array))
{
Expand Down
63 changes: 37 additions & 26 deletions airport-statistics-departure-airport-country.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,37 +60,48 @@
print '<p>'.sprintf(_("The statistic below shows all departure airports by Country of origin of flights to <strong>%s, %s, (%s)</strong>."),$airport_array[0]['city'],$airport_array[0]['name'],$airport_array[0]['icao']).'</p>';

$airport_country_array = $Spotter->countAllDepartureAirportCountriesByAirport($airport);
print '<script type="text/javascript" src="https://www.google.com/jsapi"></script>';
print '<div id="chartCountry" class="chart" width="100%"></div>
<script>
google.load("visualization", "1", {packages:["geochart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
["'._("Country").'", "'._("# of times").'"], ';
$country_data = '';
print '<script type="text/javascript" src="'.$globalURL.'/js/d3.min.js"></script>';
print '<script type="text/javascript" src="'.$globalURL.'/js/topojson.v2.min.js"></script>';
print '<script type="text/javascript" src="'.$globalURL.'/js/datamaps.world.min.js"></script>';
print '<div id="chartCountry" class="chart" width="100%"></div><script>';
print 'var series = [';
$country_data = '';
foreach($airport_country_array as $airport_item)
{
$country_data .= '[ "'.$airport_item['departure_airport_country'].'",'.$airport_item['airport_departure_country_count'].'],';
$country_data .= '[ "'.$airport_item['departure_airport_country_iso3'].'",'.$airport_item['airport_departure_country_count'].'],';
}
$country_data = substr($country_data, 0, -1);
print $country_data;
print ']);
var options = {
legend: {position: "none"},
chartArea: {"width": "80%", "height": "60%"},
height:500,
colors: ["#8BA9D0","#1a3151"]
};
var chart = new google.visualization.GeoChart(document.getElementById("chartCountry"));
chart.draw(data, options);
}
$(window).resize(function(){
drawChart();
});
</script>';
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 ['."'".'<div class="hoverinfo">'."','<strong>', geo.properties.name, '</strong>','<br>Count: <strong>', data.numberOfThings, '</strong>','</div>'].join('');
}
}
});";
print '</script>';

if (!empty($airport_country_array))
{
Expand Down
14 changes: 9 additions & 5 deletions require/class.APRS.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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');
Expand Down Expand Up @@ -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;
Expand Down
31 changes: 14 additions & 17 deletions require/class.Spotter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down Expand Up @@ -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 = '';
Expand Down Expand Up @@ -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));
Expand All @@ -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;
}

Expand Down Expand Up @@ -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));
Expand All @@ -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;
}

Expand Down

0 comments on commit 3afeea8

Please sign in to comment.