From d0dd8d35a92f0b1d3be0c911377f32772d6c6900 Mon Sep 17 00:00:00 2001 From: Russ Long Date: Wed, 12 Apr 2023 19:31:00 -0400 Subject: [PATCH] Update tabulation for new year --- app/Console/Commands/TabulateWinners.php | 206 ++++++------ app/Console/Commands/TabulateWinners.php.2022 | 309 ++++++++++++++++++ 2 files changed, 412 insertions(+), 103 deletions(-) create mode 100644 app/Console/Commands/TabulateWinners.php.2022 diff --git a/app/Console/Commands/TabulateWinners.php b/app/Console/Commands/TabulateWinners.php index d48db4d..df3d1d5 100644 --- a/app/Console/Commands/TabulateWinners.php +++ b/app/Console/Commands/TabulateWinners.php @@ -102,7 +102,7 @@ class TabulateWinners extends Command return $peoplesChoice2ndWinnerQuery->vehicle; } - function zeroTo43Winner() + function zeroTo42Winner() { $zeroTo43Query = VehicleScores::join('vehicles', 'vehicle_scores.vehicle', '=', 'vehicles.id') ->groupBy('vehicles.id') @@ -111,59 +111,43 @@ class TabulateWinners extends Command $query->select('vehicle')->from('car_show_winners'); }) ->where('vehicles.year', '>=', 0) - ->where('vehicles.year', '<=', 1943) + ->where('vehicles.year', '<=', 1942) ->where('vehicles.doNotJudge', '=', 0) ->orderBy('totalscore','desc') ->first(); return $zeroTo43Query->vehicle; } - function zeroTo432ndWinner() + function fortyThreeToSixtySevenWinner() { - $zeroTo432ndQuery = VehicleScores::join('vehicles', 'vehicle_scores.vehicle', '=', 'vehicles.id') + $fortyThreeToSixtySevenQuery = 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', '>=', 0) - ->where('vehicles.year', '<=', 1943) + ->where('vehicles.year', '>=', 1943) + ->where('vehicles.year', '<=', 1967) ->where('vehicles.doNotJudge', '=', 0) ->orderBy('totalscore','desc') ->first(); - return $zeroTo432ndQuery->vehicle; + return $fortyThreeToSixtySevenQuery->vehicle; } - function fortyFourToNinetySevenWinner() + function sixtyEightToNinetySevenWinner() { - $fortyFourToNinetySevenQuery = VehicleScores::join('vehicles', 'vehicle_scores.vehicle', '=', 'vehicles.id') + $sixtyEightToNinetySevenQuery = 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', '>=', 1944) - ->where('vehicles.year', '<=', 1997) + ->where('vehicles.year', '>=', 1943) + ->where('vehicles.year', '<=', 1967) ->where('vehicles.doNotJudge', '=', 0) ->orderBy('totalscore','desc') ->first(); - return $fortyFourToNinetySevenQuery->vehicle; - } - - function fortyFourToNinetySeven2ndWinner() - { - $fortyFourToNinetySeven2ndQuery = 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', '>=', 1944) - ->where('vehicles.year', '<=', 1997) - ->where('vehicles.doNotJudge', '=', 0) - ->orderBy('totalscore','desc') - ->first(); - return $fortyFourToNinetySeven2ndQuery->vehicle; + return $sixtyEightToNinetySevenQuery->vehicle; } function NinetyEightToCurrentWinner() @@ -182,22 +166,6 @@ class TabulateWinners extends Command return $NinetyEightToCurrentQuery->vehicle; } - function NinetyEightToCurrent2ndWinner() - { - $NinetyEightToCurrent2ndQuery = 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', '>=', 1998) - //->where('vehicles.year', '<=', 1997) - ->where('vehicles.doNotJudge', '=', 0) - ->orderBy('totalscore','desc') - ->first(); - return $NinetyEightToCurrent2ndQuery->vehicle; - } - // Truncate table first CarShowWinner::truncate(); //Insert Best In Show Winner @@ -210,18 +178,7 @@ class TabulateWinners extends Command 'vehicle' => bestInShowWinner() ] ); - /* - //Insert Best In Show 2nd Place Winner - CarShowWinner::updateOrCreate( - [ - 'category' => '6', - 'place' => 'second' - ], - [ - 'vehicle' => bestInShow2ndWinner() - ] - ); - */ + //Insert People's Choice Winner CarShowWinner::updateOrCreate( [ @@ -232,59 +189,94 @@ class TabulateWinners extends Command 'vehicle' => pcWinner() ] ); - /* + + //Insert Year Award Winners + //0-1942 + CarShowWinner::updateOrCreate( + [ + 'category' => '17', + 'place' => 'first' + ], + [ + 'vehicle' => zeroTo42Winner() + ] + ); + CarShowWinner::updateOrCreate( + [ + 'category' => '17', + 'place' => 'second' + ], + [ + 'vehicle' => zeroTo42Winner() + ] + ); + CarShowWinner::updateOrCreate( + [ + 'category' => '17', + 'place' => 'third' + ], + [ + 'vehicle' => zeroTo42Winner() + ] + ); + //1943-1967 + CarShowWinner::updateOrCreate( + [ + 'category' => '18', + 'place' => 'first' + ], + [ + 'vehicle' => fortyThreeToSixtySevenWinner() + ] + ); + CarShowWinner::updateOrCreate( + [ + 'category' => '18', + 'place' => 'second' + ], + [ + 'vehicle' => fortyThreeToSixtySevenWinner() + ] + ); + CarShowWinner::updateOrCreate( + [ + 'category' => '18', + 'place' => 'third' + ], + [ + 'vehicle' => fortyThreeToSixtySevenWinner() + ] + ); + + //1968-1997 CarShowWinner::updateOrCreate( [ - 'category' => '3', + 'category' => '20', + 'place' => 'first' + ], + [ + 'vehicle' => sixtyEightToNinetySevenWinner() + ] + ); + CarShowWinner::updateOrCreate( + [ + 'category' => '20', 'place' => 'second' ], [ - 'vehicle' => pc2ndWinner() + 'vehicle' => sixtyEightToNinetySevenWinner() ] - ); - */ - //Insert Year Award Winners - //0-1943 + ); CarShowWinner::updateOrCreate( - [ - 'category' => '17', - 'place' => 'first' - ], - [ - 'vehicle' => zeroTo43Winner() - ] - ); + [ + 'category' => '20', + 'place' => 'third' + ], + [ + 'vehicle' => sixtyEightToNinetySevenWinner() + ] + ); - CarShowWinner::updateOrCreate( - [ - 'category' => '17', - 'place' => 'second' - ], - [ - 'vehicle' => zeroTo432ndWinner() - ] - ); - //1944-1997 - CarShowWinner::updateOrCreate( - [ - 'category' => '18', - 'place' => 'first' - ], - [ - 'vehicle' => fortyFourToNinetySevenWinner() - ] - ); - - CarShowWinner::updateOrCreate( - [ - 'category' => '18', - 'place' => 'second' - ], - [ - 'vehicle' => fortyFourToNinetySeven2ndWinner() - ] - ); - //1998-Current CarShowWinner::updateOrCreate( [ @@ -295,14 +287,22 @@ class TabulateWinners extends Command 'vehicle' => NinetyEightToCurrentWinner() ] ); - CarShowWinner::updateOrCreate( [ 'category' => '19', 'place' => 'second' ], [ - 'vehicle' => NinetyEightToCurrent2ndWinner() + 'vehicle' => NinetyEightToCurrentWinner() + ] + ); + CarShowWinner::updateOrCreate( + [ + 'category' => '19', + 'place' => 'third' + ], + [ + 'vehicle' => NinetyEightToCurrentWinner() ] ); } diff --git a/app/Console/Commands/TabulateWinners.php.2022 b/app/Console/Commands/TabulateWinners.php.2022 new file mode 100644 index 0000000..d48db4d --- /dev/null +++ b/app/Console/Commands/TabulateWinners.php.2022 @@ -0,0 +1,309 @@ +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 $bestInShowWinnerQuery->vehicle; + } + + function bestInShow2ndWinner() + { + $bestInShow2ndWinnerQuery = 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) + ->orderBy('totalscore','desc') + ->first(); + return $bestInShow2ndWinnerQuery->vehicle; + } + + function pcWinner() + { + $peoplesChoiceWinnerQuery = PeoplesChoice::join('vehicles', 'peoples_choice.vehicle', '=', 'vehicles.id') + ->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 pc2ndWinner() + { + $peoplesChoice2ndWinnerQuery = PeoplesChoice::join('vehicles', 'peoples_choice.vehicle', '=', 'vehicles.id') + ->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 $peoplesChoice2ndWinnerQuery->vehicle; + } + + function zeroTo43Winner() + { + $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', '>=', 0) + ->where('vehicles.year', '<=', 1943) + ->where('vehicles.doNotJudge', '=', 0) + ->orderBy('totalscore','desc') + ->first(); + return $zeroTo43Query->vehicle; + } + + function zeroTo432ndWinner() + { + $zeroTo432ndQuery = 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', '>=', 0) + ->where('vehicles.year', '<=', 1943) + ->where('vehicles.doNotJudge', '=', 0) + ->orderBy('totalscore','desc') + ->first(); + return $zeroTo432ndQuery->vehicle; + } + + function fortyFourToNinetySevenWinner() + { + $fortyFourToNinetySevenQuery = 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', '>=', 1944) + ->where('vehicles.year', '<=', 1997) + ->where('vehicles.doNotJudge', '=', 0) + ->orderBy('totalscore','desc') + ->first(); + return $fortyFourToNinetySevenQuery->vehicle; + } + + function fortyFourToNinetySeven2ndWinner() + { + $fortyFourToNinetySeven2ndQuery = 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', '>=', 1944) + ->where('vehicles.year', '<=', 1997) + ->where('vehicles.doNotJudge', '=', 0) + ->orderBy('totalscore','desc') + ->first(); + return $fortyFourToNinetySeven2ndQuery->vehicle; + } + + function NinetyEightToCurrentWinner() + { + $NinetyEightToCurrentQuery = 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', '>=', 1998) + //->where('vehicles.year', '<=', 1997) + ->where('vehicles.doNotJudge', '=', 0) + ->orderBy('totalscore','desc') + ->first(); + return $NinetyEightToCurrentQuery->vehicle; + } + + function NinetyEightToCurrent2ndWinner() + { + $NinetyEightToCurrent2ndQuery = 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', '>=', 1998) + //->where('vehicles.year', '<=', 1997) + ->where('vehicles.doNotJudge', '=', 0) + ->orderBy('totalscore','desc') + ->first(); + return $NinetyEightToCurrent2ndQuery->vehicle; + } + + // Truncate table first + CarShowWinner::truncate(); + //Insert Best In Show Winner + CarShowWinner::updateOrCreate( + [ + 'category' => '6', + 'place' => 'first' + ], + [ + 'vehicle' => bestInShowWinner() + ] + ); + /* + //Insert Best In Show 2nd Place Winner + CarShowWinner::updateOrCreate( + [ + 'category' => '6', + 'place' => 'second' + ], + [ + 'vehicle' => bestInShow2ndWinner() + ] + ); + */ + //Insert People's Choice Winner + CarShowWinner::updateOrCreate( + [ + 'category' => '3', + 'place' => 'first' + ], + [ + 'vehicle' => pcWinner() + ] + ); + /* + CarShowWinner::updateOrCreate( + [ + 'category' => '3', + 'place' => 'second' + ], + [ + 'vehicle' => pc2ndWinner() + ] + ); + */ + //Insert Year Award Winners + //0-1943 + CarShowWinner::updateOrCreate( + [ + 'category' => '17', + 'place' => 'first' + ], + [ + 'vehicle' => zeroTo43Winner() + ] + ); + + CarShowWinner::updateOrCreate( + [ + 'category' => '17', + 'place' => 'second' + ], + [ + 'vehicle' => zeroTo432ndWinner() + ] + ); + //1944-1997 + CarShowWinner::updateOrCreate( + [ + 'category' => '18', + 'place' => 'first' + ], + [ + 'vehicle' => fortyFourToNinetySevenWinner() + ] + ); + + CarShowWinner::updateOrCreate( + [ + 'category' => '18', + 'place' => 'second' + ], + [ + 'vehicle' => fortyFourToNinetySeven2ndWinner() + ] + ); + + //1998-Current + CarShowWinner::updateOrCreate( + [ + 'category' => '19', + 'place' => 'first' + ], + [ + 'vehicle' => NinetyEightToCurrentWinner() + ] + ); + + CarShowWinner::updateOrCreate( + [ + 'category' => '19', + 'place' => 'second' + ], + [ + 'vehicle' => NinetyEightToCurrent2ndWinner() + ] + ); + } +}