コード例 #1
0
ファイル: FlightStat.php プロジェクト: T-SummerStudent/new
 function topAirlines()
 {
     $other = 0;
     $result = array();
     $chart = array();
     $names = array();
     $counter = $this->query()->select(DB::raw('airline_id, count(airline_id) as counter'))->groupBy('airline_id')->orderBy('counter', 'DESC')->whereCallsignType(1)->lists('counter', 'airline_id');
     if (count($counter) > 0) {
         $namesRaw = Airline::whereIn('icao', array_slice(array_keys($counter), 0, 5))->get();
         foreach ($namesRaw as $airline) {
             $names[$airline->icao] = $airline;
         }
         foreach ($counter as $key => $flights) {
             if (count($result) < 5 && array_key_exists($key, $names)) {
                 $percentage = $this->_total == 0 ? 0 : number_format($flights / $this->_total * 100, 1);
                 $result[] = array('data' => $names[$key], 'count' => $flights, 'percent' => $percentage, 'key' => $names[$key]->icao);
                 if ($percentage > 0) {
                     $chart[] = [$names[$key]->icao, $percentage];
                 }
             } else {
                 $other += $flights;
             }
         }
     }
     $private = $this->query()->whereCallsignType(2)->count();
     $unknown = $this->query()->whereCallsignType(0)->count();
     $result['Private'] = array('count' => $private, 'percent' => $this->_total == 0 ? 0 : number_format($private / $this->_total * 100, 1), 'key' => 'Private');
     $chart[] = ['Private', $result['Private']['percent']];
     $result['Other'] = array('count' => $other + $unknown, 'percent' => $this->_total == 0 ? 0 : number_format(($other + $unknown) / $this->_total * 100, 1), 'key' => 'Other');
     $chart[] = ['Other', $result['Other']['percent']];
     $piechartData = piechartData($chart);
     return array('table' => $result, 'chart' => $piechartData['javascript'], 'colours' => $piechartData['colours']);
 }