Merge pull request #456 from Struart88/patch-2
[FlightAirMap.git] / statistics-airport-arrival.php
blob28e344fd9863d2ddc5fa604f9835e5d32a8e5797
1 <?php
2 require_once('require/class.Connection.php');
3 require_once('require/class.Stats.php');
4 require_once('require/class.Language.php');
5 $Stats = new Stats();
6 $title = _("Statistics").' - '._("Most common Arrival Airport");
8 if (!isset($filter_name)) $filter_name = '';
9 $airline_icao = (string)filter_input(INPUT_GET,'airline',FILTER_SANITIZE_STRING);
10 if ($airline_icao == '' && isset($globalFilter)) {
11 if (isset($globalFilter['airline'])) $airline_icao = $globalFilter['airline'][0];
13 $year = filter_input(INPUT_GET,'year',FILTER_SANITIZE_NUMBER_INT);
14 $month = filter_input(INPUT_GET,'month',FILTER_SANITIZE_NUMBER_INT);
16 require_once('header.php');
17 include('statistics-sub-menu.php');
19 print '<script type="text/javascript" src="'.$globalURL.'/js/d3.min.js"></script>';
20 print '<script type="text/javascript" src="'.$globalURL.'/js/topojson.v2.min.js"></script>';
21 print '<script type="text/javascript" src="'.$globalURL.'/js/datamaps.world.min.js"></script>';
22 print '<div class="info">
23 <h1>'._("Most common Arrival Airport").'</h1>
24 </div>
25 <p>'._("Below are the <strong>Top 10</strong> most common arrival airports.").'</p>';
26 print '<div id="chartAirport" class="chart" width="100%"></div>';
27 print '<script>';
28 $airport_airport_array = $Stats->countAllArrivalAirports(true,$airline_icao,$filter_name,$year,$month);
30 print 'var series = [';
31 $airport_data = '';
32 foreach($airport_airport_array as $airport_item)
34 $airport_data .= '[ "'.$airport_item['airport_arrival_icao_count'].'", "'.$airport_item['airport_arrival_icao'].'",'.$airport_item['airport_arrival_latitude'].','.$airport_item['airport_arrival_longitude'].'],';
36 $airport_data = substr($airport_data, 0, -1);
37 print $airport_data;
38 print '];'."\n";
39 print 'var onlyValues = series.map(function(obj){ return obj[0]; });var minValue = Math.min.apply(null, onlyValues), maxValue = Math.max.apply(null, onlyValues);'."\n";
40 print 'var paletteScale = d3.scale.log().domain([minValue,maxValue]).range(["#EFEFFF","#001830"]);'."\n";
41 print 'var radiusScale = d3.scale.log().domain([minValue,maxValue]).range([0,10]);'."\n";
42 print 'var dataset = [];'."\n";
43 print 'var colorset = [];'."\n";
44 print 'colorset["defaultFill"] = "#F5F5F5";';
45 print 'series.forEach(function(item){'."\n";
46 print 'var cnt = item[0], nm = item[1], lat = item[2], long = item[3];'."\n";
47 print 'colorset[nm] = paletteScale(cnt);';
48 print 'dataset.push({ count: cnt, name: nm, radius: Math.floor(radiusScale(cnt)), latitude: lat, longitude: long, fillKey: nm });'."\n";
49 print '});'."\n";
50 print 'var bbl = new Datamap({
51 element: document.getElementById("chartAirport"),
52 projection: "mercator", // big world map
53 fills: colorset,
54 responsive: true,
55 geographyConfig: {
56 borderColor: "#DEDEDE",
57 highlightBorderWidth: 2,
58 highlightFillColor: function(geo) {
59 return geo["fillColor"] || "#F5F5F5";
61 highlightBorderColor: "#B7B7B7"},
62 done: function(datamap) {
63 datamap.svg.call(d3.behavior.zoom().on("zoom", redraw));
64 function redraw() {
65 datamap.svg.selectAll("g").attr("transform", "translate(" + d3.event.translate + ")scale(" + d3.event.scale + ")");
68 });
69 bbl.bubbles(dataset,{
70 popupTemplate: function(geo, data) {
71 if (!data) { return ; }
72 return ['."'".'<div class="hoverinfo">'."','<strong>', data.name, '</strong>','<br>Count: <strong>', data.count, '</strong>','</div>'].join('');
74 });";
75 print '</script>';
76 print '<div class="table-responsive">';
77 print '<table class="common-airport table-striped">';
78 print '<thead>';
79 print '<th></th>';
80 print '<th>'._("Airport").'</th>';
81 print '<th>'._("Country").'</th>';
82 print '<th>'._("# of times").'</th>';
83 print '</thead>';
84 print '<tbody>';
85 $i = 1;
86 foreach($airport_airport_array as $airport_item)
88 print '<tr>';
89 print '<td><strong>'.$i.'</strong></td>';
90 print '<td>';
91 print '<a href="'.$globalURL.'/airport/'.$airport_item['airport_arrival_icao'].'">'.$airport_item['airport_arrival_city'].', '.$airport_item['airport_arrival_country'].' ('.$airport_item['airport_arrival_icao'].')</a>';
92 print '</td>';
93 print '<td>';
94 print '<a href="'.$globalURL.'/country/'.strtolower(str_replace(" ", "-", $airport_item['airport_arrival_country'])).'">'.$airport_item['airport_arrival_country'].'</a>';
95 print '</td>';
96 print '<td>'.$airport_item['airport_arrival_icao_count'].'</td>';
97 print '</tr>';
98 $i++;
100 print '<tbody>';
101 print '</table>';
102 print '</div>';
104 require_once('footer.php');