diff --git a/app/Console/Commands/TabulateWinners.php b/app/Console/Commands/TabulateWinners.php index 5518777..c36fe24 100644 --- a/app/Console/Commands/TabulateWinners.php +++ b/app/Console/Commands/TabulateWinners.php @@ -46,9 +46,9 @@ class TabulateWinners extends Command public function handle() { - function mainWinner() + function bestInShowWinner() { - $mainWinnerQuery = VehicleScores::join('vehicles', 'vehicle_scores.vehicle', '=', 'vehicles.id') + $bestInShowWinnerQuery = VehicleScores::join('vehicles', 'vehicle_scores.vehicle', '=', 'vehicles.id') ->groupBy('vehicles.id') ->selectRaw('*, sum(vehicle_scores.overall_score) as totalscore') ->whereNotIn('vehicle_scores.vehicle', function($query){ @@ -57,8 +57,8 @@ class TabulateWinners extends Command ->where('vehicles.doNotJudge', '=', 0) ->orderBy('totalscore','desc') ->first(); - return $mainWinnerQuery->vehicle; - } + return $bestInShowWinnerQuery->vehicle; + } function pcWinner() { @@ -72,132 +72,40 @@ class TabulateWinners extends Command ->orderBy('totalscore','desc') ->first(); return $peoplesChoiceWinnerQuery->vehicle; - } - + } - function oughtsTo49Winner() + function zeroTo43Winner() { - $oughtsTo49Query = VehicleScores::join('vehicles', 'vehicle_scores.vehicle', '=', 'vehicles.id') + $zeroTo43Query = VehicleScores::join('vehicles', 'vehicle_scores.vehicle', '=', 'vehicles.id') ->groupBy('vehicles.id') ->selectRaw('*, sum(vehicle_scores.overall_score) as totalscore') ->whereNotIn('vehicle_scores.vehicle', function($query){ $query->select('vehicle')->from('car_show_winners'); }) - ->where('vehicles.year', '>=', 1900) - ->where('vehicles.year', '<=', 1949) + ->where('vehicles.year', '>=', 0) + ->where('vehicles.year', '<=', 1943) ->where('vehicles.doNotJudge', '=', 0) ->orderBy('totalscore','desc') ->first(); - return $oughtsTo49Query->vehicle; + return $zeroTo43Query->vehicle; } - - function fiftiesWinner() + + function fortyFourToCurrentWinner() { - $fiftiesQuery = VehicleScores::join('vehicles', 'vehicle_scores.vehicle', '=', 'vehicles.id') + $fortyFourToCurrentQuery = VehicleScores::join('vehicles', 'vehicle_scores.vehicle', '=', 'vehicles.id') ->groupBy('vehicles.id') ->selectRaw('*, sum(vehicle_scores.overall_score) as totalscore') ->whereNotIn('vehicle_scores.vehicle', function($query){ $query->select('vehicle')->from('car_show_winners'); }) - ->where('vehicles.year', '>=', 1950) - ->where('vehicles.year', '<=', 1959) - ->where('vehicles.doNotJudge', '=', 0) - ->orderBy('totalscore','desc') - ->first(); - return $fiftiesQuery->vehicle; - } - - function sixtiesWinner() - { - $sixtiesQuery = VehicleScores::join('vehicles', 'vehicle_scores.vehicle', '=', 'vehicles.id') - ->groupBy('vehicles.id') - ->selectRaw('*, sum(vehicle_scores.overall_score) as totalscore') - ->whereNotIn('vehicle_scores.vehicle', function($query){ - $query->select('vehicle')->from('car_show_winners'); - }) - ->where('vehicles.year', '>=', 1960) - ->where('vehicles.year', '<=', 1969) - ->where('vehicles.doNotJudge', '=', 0) - ->orderBy('totalscore','desc') - ->first(); - return $sixtiesQuery->vehicle; - } - function seventiesWinner() - { - $seventiesQuery = VehicleScores::join('vehicles', 'vehicle_scores.vehicle', '=', 'vehicles.id') - ->groupBy('vehicles.id') - ->selectRaw('*, sum(vehicle_scores.overall_score) as totalscore') - ->whereNotIn('vehicle_scores.vehicle', function($query){ - $query->select('vehicle')->from('car_show_winners'); - }) - ->where('vehicles.year', '>=', 1970) - ->where('vehicles.year', '<=', 1979) - ->where('vehicles.doNotJudge', '=', 0) - ->orderBy('totalscore','desc') - ->first(); - return $seventiesQuery->vehicle; - } - - function eightiesWinner() - { - $eightiesQuery = VehicleScores::join('vehicles', 'vehicle_scores.vehicle', '=', 'vehicles.id') - ->groupBy('vehicles.id') - ->selectRaw('*, sum(vehicle_scores.overall_score) as totalscore') - ->whereNotIn('vehicle_scores.vehicle', function($query){ - $query->select('vehicle')->from('car_show_winners'); - }) - ->where('vehicles.year', '>=', 1980) - ->where('vehicles.year', '<=', 1989) - ->where('vehicles.doNotJudge', '=', 0) - ->orderBy('totalscore','desc') - ->first(); - return $eightiesQuery->vehicle; - } - - function ninetiesWinner() - { - $ninetiesQuery = VehicleScores::join('vehicles', 'vehicle_scores.vehicle', '=', 'vehicles.id') - ->groupBy('vehicles.id') - ->selectRaw('*, sum(vehicle_scores.overall_score) as totalscore') - ->whereNotIn('vehicle_scores.vehicle', function($query){ - $query->select('vehicle')->from('car_show_winners'); - }) - ->where('vehicles.year', '>=', 1990) - ->where('vehicles.year', '<=', 1999) - ->where('vehicles.doNotJudge', '=', 0) - ->orderBy('totalscore','desc') - ->first(); - return $ninetiesQuery->vehicle; - } - function thousandsWinner() - { - $thousandsQuery = VehicleScores::join('vehicles', 'vehicle_scores.vehicle', '=', 'vehicles.id') - ->groupBy('vehicles.id') - ->selectRaw('*, sum(vehicle_scores.overall_score) as totalscore') - ->whereNotIn('vehicle_scores.vehicle', function($query){ - $query->select('vehicle')->from('car_show_winners'); - }) - ->where('vehicles.year', '>=', 2000) + ->where('vehicles.year', '>=', 1944) //->where('vehicles.year', '<=', 1959) ->where('vehicles.doNotJudge', '=', 0) ->orderBy('totalscore','desc') ->first(); - return $thousandsQuery->vehicle; - } - function categoryWinner($category) - { - $categoryWinnerQuery = VehicleScores::join('vehicles', 'vehicle_scores.vehicle', '=', 'vehicles.id') - ->groupBy('vehicles.id') - ->selectRaw('*, sum(vehicle_scores.overall_score) as totalscore') - ->whereNotIn('vehicle_scores.vehicle', function ($query) { - $query->select('vehicle')->from('car_show_winners'); - }) - ->where('vehicles.doNotJudge', '=', 0) - ->where('vehicles.type', '=', "$category") - ->orderBy('totalscore', 'desc') - ->first(); - return $categoryWinnerQuery->vehicle; + return $fortyFourToCurrentQuery->vehicle; } + //categories /* Here for reference only $individuallyProcessedAwards = array( @@ -205,30 +113,16 @@ class TabulateWinners extends Command 'pcFirst' => '3' ); */ $mainAwardsToCalculate = array( - // 'inShowFirst' =>'6', - // 'pcFirst' => '3', - 'bestTruckFirst' => '5', - 'corvetteFirst' => '7', - 'camaroFirst' => '8', - // 'moparFirst' => '16', - 'mustangFirst' => '1', - 'ratRideFirst' => '4' + 'inShowFirst' =>'6', + 'inShowSecond' =>'6', + 'pcFirst' => '3', + 'pcSecond' => '3' ); $yearAwardsToCalculate = array( - 'oughtsTo49First' => '9', - 'oughtsTo49Second' => '9', - 'fiftiesFirst' => '10', - 'fiftiesSecond' => '10', - 'sixtiesFirst' => '11', - 'sixtiesSecond' => '11', - 'seventiesFirst' => '12', - 'seventiesSecond' => '12', - 'eightiesFirst' => '13', - 'eightiesSecond' => '13', - 'ninetiesFirst' => '14', - 'ninetiesSecond' => '14', - 'thousandsFirst' => '15', - 'thousandsSecond' => '15' + 'zeroTo43First' => '17', + 'zeroTo43Second' => '17', + 'fourtyFourToCurrentFirst' => '18', + 'fourtyFourToCurrentSecond' => '18' ); //Insert Best In Show Winner CarShowWinner::updateOrCreate( @@ -237,174 +131,80 @@ class TabulateWinners extends Command 'place' => 'first' ], [ - 'vehicle' => mainWinner() + 'vehicle' => bestInShowWinner() + ] + ); + + //Insert Best In Show 2nd Place Winner + CarShowWinner::updateOrCreate( + [ + 'category' => '6', + 'place' => 'second' + ], + [ + 'vehicle' => bestInShowWinner() ] ); //Insert People's Choice Winner - /*CarShowWinner::updateOrCreate( + CarShowWinner::updateOrCreate( [ 'category' => '3', 'place' => 'first' ], [ - 'vehicle' => $peoplesChoiceWinnerQuery + 'vehicle' => pcWinner() ] - );*/ - //Insert Category Award Winners - foreach($mainAwardsToCalculate as $mainaward => $category) { - $categorywinner = CarShowWinner::updateOrCreate( - [ - 'category' => $category, - 'place' => 'first' - ], - [ - 'vehicle' => categoryWinner($category) - ] - ); - } + ); + CarShowWinner::updateOrCreate( + [ + 'category' => '3', + 'place' => 'second' + ], + [ + 'vehicle' => pcWinner() + ] + ); //Insert Year Award Winners - //1900-1949 + //0-1943 CarShowWinner::updateOrCreate( [ - 'category' => '9', + 'category' => '17', 'place' => 'first' ], [ - 'vehicle' => oughtsTo49Winner() + 'vehicle' => zeroTo43Winner() ] ); CarShowWinner::updateOrCreate( [ - 'category' => '9', + 'category' => '17', 'place' => 'second' ], [ - 'vehicle' => oughtsTo49Winner() + 'vehicle' => zeroTo43Winner() ] ); - //1950-1959 + //1944-Current CarShowWinner::updateOrCreate( [ - 'category' => '10', + 'category' => '18', 'place' => 'first' ], [ - 'vehicle' => fiftiesWinner() + 'vehicle' => fortyFourToCurrentWinner() ] ); CarShowWinner::updateOrCreate( [ - 'category' => '10', + 'category' => '18', 'place' => 'second' ], [ - 'vehicle' => fiftiesWinner() - ] - ); - //1960-1969 - CarShowWinner::updateOrCreate( - [ - 'category' => '11', - 'place' => 'first' - ], - [ - 'vehicle' => sixtiesWinner() - ] - ); - - CarShowWinner::updateOrCreate( - [ - 'category' => '11', - 'place' => 'second' - ], - [ - 'vehicle' => sixtiesWinner() - ] - ); - - //1970-1979 - CarShowWinner::updateOrCreate( - [ - 'category' => '12', - 'place' => 'first' - ], - [ - 'vehicle' => seventiesWinner() - ] - ); - - CarShowWinner::updateOrCreate( - [ - 'category' => '12', - 'place' => 'second' - ], - [ - 'vehicle' => seventiesWinner() - ] - ); - //1980-1989 - CarShowWinner::updateOrCreate( - [ - 'category' => '13', - 'place' => 'first' - ], - [ - 'vehicle' => eightiesWinner() - ] - ); - - CarShowWinner::updateOrCreate( - [ - 'category' => '13', - 'place' => 'second' - ], - [ - 'vehicle' => eightiesWinner() - ] - ); - - //1990-1999 - CarShowWinner::updateOrCreate( - [ - 'category' => '14', - 'place' => 'first' - ], - [ - 'vehicle' => ninetiesWinner() - ] - ); - - CarShowWinner::updateOrCreate( - [ - 'category' => '14', - 'place' => 'second' - ], - [ - 'vehicle' => ninetiesWinner() - ] - ); - //2000-present - CarShowWinner::updateOrCreate( - [ - 'category' => '15', - 'place' => 'first' - ], - [ - 'vehicle' => thousandsWinner() - ] - ); - - CarShowWinner::updateOrCreate( - [ - 'category' => '15', - 'place' => 'second' - ], - [ - 'vehicle' => thousandsWinner() + 'vehicle' => fortyFourToCurrentWinner() ] ); } diff --git a/app/Console/Commands/TabulateWinners.php.bak b/app/Console/Commands/TabulateWinners.php.bak new file mode 100644 index 0000000..5518777 --- /dev/null +++ b/app/Console/Commands/TabulateWinners.php.bak @@ -0,0 +1,411 @@ +groupBy('vehicles.id') + ->selectRaw('*, sum(vehicle_scores.overall_score) as totalscore') + ->whereNotIn('vehicle_scores.vehicle', function($query){ + $query->select('vehicle')->from('car_show_winners'); + }) + ->where('vehicles.doNotJudge', '=', 0) + ->orderBy('totalscore','desc') + ->first(); + return $mainWinnerQuery->vehicle; + } + + function pcWinner() + { + $peoplesChoiceWinnerQuery = DB::table('peoples_choice') + ->groupBy('peoples_choice.vehicle') + ->selectRaw('*, sum(pc_count as totalscore') + ->whereNotIn('vehicle', function($query){ + $query->select('vehicle')->from('car_show_winners'); + }) + ->where('vehicles.doNotJudge', '=', 0) + ->orderBy('totalscore','desc') + ->first(); + return $peoplesChoiceWinnerQuery->vehicle; + } + + + function oughtsTo49Winner() + { + $oughtsTo49Query = VehicleScores::join('vehicles', 'vehicle_scores.vehicle', '=', 'vehicles.id') + ->groupBy('vehicles.id') + ->selectRaw('*, sum(vehicle_scores.overall_score) as totalscore') + ->whereNotIn('vehicle_scores.vehicle', function($query){ + $query->select('vehicle')->from('car_show_winners'); + }) + ->where('vehicles.year', '>=', 1900) + ->where('vehicles.year', '<=', 1949) + ->where('vehicles.doNotJudge', '=', 0) + ->orderBy('totalscore','desc') + ->first(); + return $oughtsTo49Query->vehicle; + } + + function fiftiesWinner() + { + $fiftiesQuery = VehicleScores::join('vehicles', 'vehicle_scores.vehicle', '=', 'vehicles.id') + ->groupBy('vehicles.id') + ->selectRaw('*, sum(vehicle_scores.overall_score) as totalscore') + ->whereNotIn('vehicle_scores.vehicle', function($query){ + $query->select('vehicle')->from('car_show_winners'); + }) + ->where('vehicles.year', '>=', 1950) + ->where('vehicles.year', '<=', 1959) + ->where('vehicles.doNotJudge', '=', 0) + ->orderBy('totalscore','desc') + ->first(); + return $fiftiesQuery->vehicle; + } + + function sixtiesWinner() + { + $sixtiesQuery = VehicleScores::join('vehicles', 'vehicle_scores.vehicle', '=', 'vehicles.id') + ->groupBy('vehicles.id') + ->selectRaw('*, sum(vehicle_scores.overall_score) as totalscore') + ->whereNotIn('vehicle_scores.vehicle', function($query){ + $query->select('vehicle')->from('car_show_winners'); + }) + ->where('vehicles.year', '>=', 1960) + ->where('vehicles.year', '<=', 1969) + ->where('vehicles.doNotJudge', '=', 0) + ->orderBy('totalscore','desc') + ->first(); + return $sixtiesQuery->vehicle; + } + function seventiesWinner() + { + $seventiesQuery = VehicleScores::join('vehicles', 'vehicle_scores.vehicle', '=', 'vehicles.id') + ->groupBy('vehicles.id') + ->selectRaw('*, sum(vehicle_scores.overall_score) as totalscore') + ->whereNotIn('vehicle_scores.vehicle', function($query){ + $query->select('vehicle')->from('car_show_winners'); + }) + ->where('vehicles.year', '>=', 1970) + ->where('vehicles.year', '<=', 1979) + ->where('vehicles.doNotJudge', '=', 0) + ->orderBy('totalscore','desc') + ->first(); + return $seventiesQuery->vehicle; + } + + function eightiesWinner() + { + $eightiesQuery = VehicleScores::join('vehicles', 'vehicle_scores.vehicle', '=', 'vehicles.id') + ->groupBy('vehicles.id') + ->selectRaw('*, sum(vehicle_scores.overall_score) as totalscore') + ->whereNotIn('vehicle_scores.vehicle', function($query){ + $query->select('vehicle')->from('car_show_winners'); + }) + ->where('vehicles.year', '>=', 1980) + ->where('vehicles.year', '<=', 1989) + ->where('vehicles.doNotJudge', '=', 0) + ->orderBy('totalscore','desc') + ->first(); + return $eightiesQuery->vehicle; + } + + function ninetiesWinner() + { + $ninetiesQuery = VehicleScores::join('vehicles', 'vehicle_scores.vehicle', '=', 'vehicles.id') + ->groupBy('vehicles.id') + ->selectRaw('*, sum(vehicle_scores.overall_score) as totalscore') + ->whereNotIn('vehicle_scores.vehicle', function($query){ + $query->select('vehicle')->from('car_show_winners'); + }) + ->where('vehicles.year', '>=', 1990) + ->where('vehicles.year', '<=', 1999) + ->where('vehicles.doNotJudge', '=', 0) + ->orderBy('totalscore','desc') + ->first(); + return $ninetiesQuery->vehicle; + } + function thousandsWinner() + { + $thousandsQuery = VehicleScores::join('vehicles', 'vehicle_scores.vehicle', '=', 'vehicles.id') + ->groupBy('vehicles.id') + ->selectRaw('*, sum(vehicle_scores.overall_score) as totalscore') + ->whereNotIn('vehicle_scores.vehicle', function($query){ + $query->select('vehicle')->from('car_show_winners'); + }) + ->where('vehicles.year', '>=', 2000) + //->where('vehicles.year', '<=', 1959) + ->where('vehicles.doNotJudge', '=', 0) + ->orderBy('totalscore','desc') + ->first(); + return $thousandsQuery->vehicle; + } + function categoryWinner($category) + { + $categoryWinnerQuery = VehicleScores::join('vehicles', 'vehicle_scores.vehicle', '=', 'vehicles.id') + ->groupBy('vehicles.id') + ->selectRaw('*, sum(vehicle_scores.overall_score) as totalscore') + ->whereNotIn('vehicle_scores.vehicle', function ($query) { + $query->select('vehicle')->from('car_show_winners'); + }) + ->where('vehicles.doNotJudge', '=', 0) + ->where('vehicles.type', '=', "$category") + ->orderBy('totalscore', 'desc') + ->first(); + return $categoryWinnerQuery->vehicle; + } + //categories + /* Here for reference only + $individuallyProcessedAwards = array( + 'inShowFirst' =>'6', + 'pcFirst' => '3' + ); */ + $mainAwardsToCalculate = array( + // 'inShowFirst' =>'6', + // 'pcFirst' => '3', + 'bestTruckFirst' => '5', + 'corvetteFirst' => '7', + 'camaroFirst' => '8', + // 'moparFirst' => '16', + 'mustangFirst' => '1', + 'ratRideFirst' => '4' + ); + $yearAwardsToCalculate = array( + 'oughtsTo49First' => '9', + 'oughtsTo49Second' => '9', + 'fiftiesFirst' => '10', + 'fiftiesSecond' => '10', + 'sixtiesFirst' => '11', + 'sixtiesSecond' => '11', + 'seventiesFirst' => '12', + 'seventiesSecond' => '12', + 'eightiesFirst' => '13', + 'eightiesSecond' => '13', + 'ninetiesFirst' => '14', + 'ninetiesSecond' => '14', + 'thousandsFirst' => '15', + 'thousandsSecond' => '15' + ); + //Insert Best In Show Winner + CarShowWinner::updateOrCreate( + [ + 'category' => '6', + 'place' => 'first' + ], + [ + 'vehicle' => mainWinner() + ] + ); + + //Insert People's Choice Winner + /*CarShowWinner::updateOrCreate( + [ + 'category' => '3', + 'place' => 'first' + ], + [ + 'vehicle' => $peoplesChoiceWinnerQuery + ] + );*/ + //Insert Category Award Winners + foreach($mainAwardsToCalculate as $mainaward => $category) { + $categorywinner = CarShowWinner::updateOrCreate( + [ + 'category' => $category, + 'place' => 'first' + ], + [ + 'vehicle' => categoryWinner($category) + ] + ); + } + + //Insert Year Award Winners + //1900-1949 + CarShowWinner::updateOrCreate( + [ + 'category' => '9', + 'place' => 'first' + ], + [ + 'vehicle' => oughtsTo49Winner() + ] + ); + + CarShowWinner::updateOrCreate( + [ + 'category' => '9', + 'place' => 'second' + ], + [ + 'vehicle' => oughtsTo49Winner() + ] + ); + //1950-1959 + CarShowWinner::updateOrCreate( + [ + 'category' => '10', + 'place' => 'first' + ], + [ + 'vehicle' => fiftiesWinner() + ] + ); + + CarShowWinner::updateOrCreate( + [ + 'category' => '10', + 'place' => 'second' + ], + [ + 'vehicle' => fiftiesWinner() + ] + ); + //1960-1969 + CarShowWinner::updateOrCreate( + [ + 'category' => '11', + 'place' => 'first' + ], + [ + 'vehicle' => sixtiesWinner() + ] + ); + + CarShowWinner::updateOrCreate( + [ + 'category' => '11', + 'place' => 'second' + ], + [ + 'vehicle' => sixtiesWinner() + ] + ); + + //1970-1979 + CarShowWinner::updateOrCreate( + [ + 'category' => '12', + 'place' => 'first' + ], + [ + 'vehicle' => seventiesWinner() + ] + ); + + CarShowWinner::updateOrCreate( + [ + 'category' => '12', + 'place' => 'second' + ], + [ + 'vehicle' => seventiesWinner() + ] + ); + //1980-1989 + CarShowWinner::updateOrCreate( + [ + 'category' => '13', + 'place' => 'first' + ], + [ + 'vehicle' => eightiesWinner() + ] + ); + + CarShowWinner::updateOrCreate( + [ + 'category' => '13', + 'place' => 'second' + ], + [ + 'vehicle' => eightiesWinner() + ] + ); + + //1990-1999 + CarShowWinner::updateOrCreate( + [ + 'category' => '14', + 'place' => 'first' + ], + [ + 'vehicle' => ninetiesWinner() + ] + ); + + CarShowWinner::updateOrCreate( + [ + 'category' => '14', + 'place' => 'second' + ], + [ + 'vehicle' => ninetiesWinner() + ] + ); + //2000-present + CarShowWinner::updateOrCreate( + [ + 'category' => '15', + 'place' => 'first' + ], + [ + 'vehicle' => thousandsWinner() + ] + ); + + CarShowWinner::updateOrCreate( + [ + 'category' => '15', + 'place' => 'second' + ], + [ + 'vehicle' => thousandsWinner() + ] + ); + } +} diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index 4a5db5a..ac3c315 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -146,6 +146,11 @@ Car Show Winners +
  • + + Vehicle Total Scores + +