Merge pull request #456 from Struart88/patch-2
[FlightAirMap.git] / statistics-race.php
blobd699e8c6ba4c2be2f28697f533d9425cecf88fb3
1 <?php
2 require_once('require/class.Connection.php');
3 require_once('require/class.Marine.php');
4 require_once('require/class.Language.php');
5 $Marine = new Marine();
6 $title = _("Statistics").' - '._("Top 10 Races Number of Participants");
8 if (!isset($filter_name)) $filter_name = '';
9 $year = filter_input(INPUT_GET,'year',FILTER_SANITIZE_NUMBER_INT);
10 $month = filter_input(INPUT_GET,'month',FILTER_SANITIZE_NUMBER_INT);
11 $type = 'marine';
12 require_once('header.php');
13 include('statistics-sub-menu.php');
14 print '<script type="text/javascript" src="'.$globalURL.'/js/d3.min.js"></script>';
15 print '<script type="text/javascript" src="'.$globalURL.'/js/d3pie.min.js"></script>';
16 print '<div class="info">
17 <h1>'._("Top 10 Races Number of Participants").'</h1>
18 </div>
19 <p>'._("Below are the <strong>Top 10</strong> races with the most number of participants.").'</p>';
21 $race_array = $Marine->countAllCaptainsByRaces(true,$filter_name,$year,$month);
22 print '<div id="chart" class="chart" width="100%"></div><script>';
23 $pilot_data = '';
24 foreach($race_array as $race_item)
26 $race_data .= '["'.$race_item['marine_race_name'].' ('.$race_item['marine_race_id'].')",'.$race_item['marine_captain_count'].'],';
28 $race_data = substr($race_data, 0, -1);
29 print 'var series = ['.$race_data.'];';
30 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);';
31 print 'var paletteScale = d3.scale.log().domain([minValue,maxValue]).range(["#e6e6f6","#1a3151"]);';
32 print 'series.forEach(function(item){var lab = item[0], value = item[1]; dataset.push({"label":lab,"value":value,"color":paletteScale(value)});});';
33 print 'var marinetype = new d3pie("chart",{"header":{"title":{"fontSize":24,"font":"open sans"},"subtitle":{"color":"#999999","fontSize":12,"font":"open sans"},"titleSubtitlePadding":9},"footer":{"color":"#999999","fontSize":10,"font":"open sans","location":"bottom-left"},"size":{"canvasWidth":700,"pieOuterRadius":"60%"},"data":{"sortOrder":"value-desc","content":';
34 print 'dataset';
35 print '},"labels":{"outer":{"pieDistance":32},"inner":{"hideWhenLessThanPercentage":3,"format":"value"},"mainLabel":{"fontSize":11},"percentage":{"color":"#ffffff","decimalPlaces":0},"value":{"color":"#98e8e3","fontSize":11},"lines":{"enabled":true},"truncation":{"enabled":true}},"effects":{"pullOutSegmentOnClick":{"effect":"linear","speed":400,"size":8}},"misc":{"gradient":{"enabled":true,"percentage":100}}});';
36 print '</script>';
38 if (!empty($race_array))
40 print '<div class="table-responsive">';
41 print '<table class="common-type table-striped">';
42 print '<thead>';
43 print '<th></th>';
44 print '<th>'._("Race Name").'</th>';
45 print '<th>'._("# of captains").'</th>';
46 print '</thead>';
47 print '<tbody>';
48 $i = 1;
49 foreach($race_array as $race_item)
51 print '<tr>';
52 print '<td><strong>'.$i.'</strong></td>';
53 print '<td>';
54 print $race_item['marine_race_name'].' ('.$race_item['marine_race_id'].')</a>';
55 print '</td>';
56 print '<td>';
57 print $race_item['marine_captain_count'];
58 print '</td>';
59 print '</tr>';
60 $i++;
62 print '<tbody>';
63 print '</table>';
64 print '</div>';
66 require_once('footer.php');