예제 #1
0
 function citypair($departureId, $arrivalId)
 {
     $routes = Flight::select('id', 'route', DB::raw('COUNT(route) AS count'))->whereDepartureId($departureId)->whereArrivalId($arrivalId)->where('route', '!=', '')->whereState(2)->groupBy('route')->orderBy('count', 'desc')->get();
     $departure = Airport::whereIcao($departureId)->first();
     $arrival = Airport::whereIcao($arrivalId)->first();
     $this->autoRender(compact('departure', 'arrival', 'routes', 'airports', 'departureId', 'arrivalId'), 'Routes for ' . $departureId . ' - ' . $arrivalId);
 }
    public function index()
    {
        $most_popular_routes = Timetable::select(DB::raw('*,
					COUNT(*) AS flights_per_week,
					least(origin_airport_id, destination_airport_id) as city1,
					greatest(origin_airport_id, destination_airport_id) as city2'))->with('origin', 'destination', 'airline')->groupBy(DB::raw('least(origin_airport_id, destination_airport_id)'))->groupBy(DB::raw('greatest(origin_airport_id, destination_airport_id)'))->orderBy('flights_per_week', 'DESC')->limit(20)->get();
        $most_km = Flight::select(DB::raw('airline_id, SUM(`distance`) AS overall_distance, COUNT(*) AS number_of_flights'))->with('airline')->where('accounted', '1')->groupBy('airline_id')->orderBy('overall_distance', 'DESC')->limit(20)->get();
        $longest_flights = Flight::select(DB::raw('*,
					COUNT(*) AS flights_per_week,
					least(origin_airport_id, destination_airport_id) as city1,
					greatest(origin_airport_id, destination_airport_id) as city2'))->with('origin', 'destination')->groupBy(DB::raw('least(origin_airport_id, destination_airport_id)'))->groupBy(DB::raw('greatest(origin_airport_id, destination_airport_id)'))->orderBy('distance', 'DESC')->limit(10)->get();
        $shortest_flights = Flight::select(DB::raw('*'))->with('origin', 'destination')->groupBy('origin_airport_id')->orderBy('distance', 'ASC')->limit(5)->get();
        return View::make('statistics/index', array('most_popular_routes' => $most_popular_routes, 'most_km' => $most_km, 'longest_flights' => $longest_flights, 'shortest_flights' => $shortest_flights));
        /*
        SELECT  `origin_airport_id` ,  `destination_airport_id` ,  `airline_id` , COUNT(  `origin_airport_id` )
        		FROM  `timetables`
        		GROUP BY  `origin_airport_id` ,  `destination_airport_id` ,  `airline_id`
        		ORDER BY COUNT(  `origin_airport_id` ) ASC
        */
    }