silent-auction/app/Console/Commands/TabulateWinners.php

310 lines
10 KiB
PHP
Raw Normal View History

2019-07-11 20:55:45 -04:00
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Models\Bidders;
use App\Models\CarShowCategory;
use App\Models\CarShowWinner;
use App\Models\PeoplesChoice;
use App\Models\Vehicles;
use App\Models\VehicleScores;
use Illuminate\Support\Facades\DB;
class TabulateWinners extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'carshow:tabulatewinners';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Tabulate Show Winners, and add them to the CarShowWinner table';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
2022-05-01 08:58:49 -04:00
function bestInShowWinner()
2019-07-11 20:55:45 -04:00
{
2022-05-01 08:58:49 -04:00
$bestInShowWinnerQuery = VehicleScores::join('vehicles', 'vehicle_scores.vehicle', '=', 'vehicles.id')
2019-07-11 20:55:45 -04:00
->groupBy('vehicles.id')
->selectRaw('*, sum(vehicle_scores.overall_score) as totalscore')
->whereNotIn('vehicle_scores.vehicle', function($query){
$query->select('vehicle')->from('car_show_winners');
})
2020-02-08 15:36:02 -05:00
->where('vehicles.doNotJudge', '=', 0)
2019-07-11 20:55:45 -04:00
->orderBy('totalscore','desc')
->first();
2022-05-01 08:58:49 -04:00
return $bestInShowWinnerQuery->vehicle;
2022-05-01 09:42:47 -04:00
}
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;
}
2020-02-08 15:24:15 -05:00
2019-07-11 20:55:45 -04:00
function pcWinner()
{
2022-05-01 09:37:11 -04:00
$peoplesChoiceWinnerQuery = PeoplesChoice::join('vehicles', 'peoples_choice.vehicle', '=', 'vehicles.id')
2019-07-11 20:55:45 -04:00
->groupBy('peoples_choice.vehicle')
2022-05-01 09:33:38 -04:00
->selectRaw('*, sum(pc_count) as totalscore')
2019-07-11 20:55:45 -04:00
->whereNotIn('vehicle', function($query){
$query->select('vehicle')->from('car_show_winners');
})
2020-02-08 15:36:02 -05:00
->where('vehicles.doNotJudge', '=', 0)
2019-07-11 20:55:45 -04:00
->orderBy('totalscore','desc')
->first();
return $peoplesChoiceWinnerQuery->vehicle;
2022-05-01 08:58:49 -04:00
}
2020-02-08 12:49:38 -05:00
2022-05-01 09:44:49 -04:00
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;
}
2023-04-12 19:31:00 -04:00
function zeroTo42Winner()
2019-07-11 20:55:45 -04:00
{
2022-05-01 08:58:49 -04:00
$zeroTo43Query = VehicleScores::join('vehicles', 'vehicle_scores.vehicle', '=', 'vehicles.id')
2019-07-11 20:55:45 -04:00
->groupBy('vehicles.id')
->selectRaw('*, sum(vehicle_scores.overall_score) as totalscore')
->whereNotIn('vehicle_scores.vehicle', function($query){
$query->select('vehicle')->from('car_show_winners');
})
2022-05-01 08:58:49 -04:00
->where('vehicles.year', '>=', 0)
2023-04-12 19:31:00 -04:00
->where('vehicles.year', '<=', 1942)
2020-02-08 15:36:02 -05:00
->where('vehicles.doNotJudge', '=', 0)
2019-07-11 20:55:45 -04:00
->orderBy('totalscore','desc')
->first();
2022-05-01 08:58:49 -04:00
return $zeroTo43Query->vehicle;
2019-07-11 20:55:45 -04:00
}
2022-05-01 08:58:49 -04:00
2024-05-12 15:01:21 -04:00
function fortyThreeToSixtySevenWinner()
2022-05-01 09:44:49 -04:00
{
2024-05-12 15:01:21 -04:00
$fortyThreeToSixtySevenQuery = VehicleScores::join('vehicles', 'vehicle_scores.vehicle', '=', 'vehicles.id')
2022-05-01 09:44:49 -04:00
->groupBy('vehicles.id')
->selectRaw('*, sum(vehicle_scores.overall_score) as totalscore')
->whereNotIn('vehicle_scores.vehicle', function($query){
$query->select('vehicle')->from('car_show_winners');
})
2023-04-12 19:31:00 -04:00
->where('vehicles.year', '>=', 1943)
2024-05-12 15:01:21 -04:00
->where('vehicles.year', '<=', 1967)
2020-02-08 15:36:02 -05:00
->where('vehicles.doNotJudge', '=', 0)
2019-07-11 20:55:45 -04:00
->orderBy('totalscore','desc')
->first();
2024-05-12 15:01:21 -04:00
return $fortyThreeToSixtySevenQuery->vehicle;
2020-02-08 15:24:15 -05:00
}
2022-05-01 08:58:49 -04:00
2024-05-12 15:01:21 -04:00
function sixtyEightToNinetyEightWinner()
2022-05-01 09:44:49 -04:00
{
2024-05-12 15:01:21 -04:00
$sixtyEightToNinetyEightQuery = VehicleScores::join('vehicles', 'vehicle_scores.vehicle', '=', 'vehicles.id')
2022-05-01 09:44:49 -04:00
->groupBy('vehicles.id')
->selectRaw('*, sum(vehicle_scores.overall_score) as totalscore')
->whereNotIn('vehicle_scores.vehicle', function($query){
$query->select('vehicle')->from('car_show_winners');
})
2024-05-12 15:01:21 -04:00
->where('vehicles.year', '>=', 1968)
2024-03-16 13:39:58 -04:00
->where('vehicles.year', '<=', 1998)
2022-05-01 09:44:49 -04:00
->where('vehicles.doNotJudge', '=', 0)
->orderBy('totalscore','desc')
->first();
2024-05-12 15:01:21 -04:00
return $sixtyEightToNinetyEightQuery->vehicle;
2022-05-01 09:44:49 -04:00
}
2024-03-16 13:39:58 -04:00
function NinetyNineToCurrentWinner()
2022-06-08 20:21:59 -04:00
{
2024-03-16 13:39:58 -04:00
$NinetyNineToCurrentQuery = VehicleScores::join('vehicles', 'vehicle_scores.vehicle', '=', 'vehicles.id')
2022-06-08 20:21:59 -04:00
->groupBy('vehicles.id')
->selectRaw('*, sum(vehicle_scores.overall_score) as totalscore')
->whereNotIn('vehicle_scores.vehicle', function($query){
$query->select('vehicle')->from('car_show_winners');
})
2024-03-16 13:39:58 -04:00
->where('vehicles.year', '>=', 1999)
2022-06-08 20:21:59 -04:00
//->where('vehicles.year', '<=', 1997)
->where('vehicles.doNotJudge', '=', 0)
->orderBy('totalscore','desc')
->first();
2024-03-16 13:39:58 -04:00
return $NinetyNineToCurrentQuery->vehicle;
2022-06-08 20:21:59 -04:00
}
2023-03-16 14:13:40 -04:00
// Truncate table first
CarShowWinner::truncate();
2019-07-11 20:55:45 -04:00
//Insert Best In Show Winner
CarShowWinner::updateOrCreate(
[
'category' => '6',
'place' => 'first'
],
[
2022-05-01 08:58:49 -04:00
'vehicle' => bestInShowWinner()
]
);
2023-04-12 19:31:00 -04:00
2019-07-11 20:55:45 -04:00
//Insert People's Choice Winner
2022-05-01 08:58:49 -04:00
CarShowWinner::updateOrCreate(
2019-07-11 20:55:45 -04:00
[
'category' => '3',
'place' => 'first'
],
[
2022-05-01 08:58:49 -04:00
'vehicle' => pcWinner()
2019-07-11 20:55:45 -04:00
]
2022-05-01 08:58:49 -04:00
);
2023-04-12 19:31:00 -04:00
2022-05-01 08:58:49 -04:00
//Insert Year Award Winners
2023-04-12 19:31:00 -04:00
//0-1942
2019-07-11 20:55:45 -04:00
CarShowWinner::updateOrCreate(
[
2022-05-01 08:58:49 -04:00
'category' => '17',
2019-07-11 20:55:45 -04:00
'place' => 'first'
],
[
2023-04-12 19:31:00 -04:00
'vehicle' => zeroTo42Winner()
2019-07-11 20:55:45 -04:00
]
);
CarShowWinner::updateOrCreate(
[
2022-05-01 08:58:49 -04:00
'category' => '17',
2019-07-11 20:55:45 -04:00
'place' => 'second'
],
[
2023-04-12 19:31:00 -04:00
'vehicle' => zeroTo42Winner()
2019-07-11 20:55:45 -04:00
]
);
2023-04-12 19:31:00 -04:00
CarShowWinner::updateOrCreate(
[
'category' => '17',
'place' => 'third'
],
[
'vehicle' => zeroTo42Winner()
]
);
//1943-1967
2019-07-11 20:55:45 -04:00
CarShowWinner::updateOrCreate(
[
2022-05-01 08:58:49 -04:00
'category' => '18',
2019-07-11 20:55:45 -04:00
'place' => 'first'
],
[
2024-05-12 15:01:21 -04:00
'vehicle' => fortyThreeToSixtySevenWinner()
2019-07-11 20:55:45 -04:00
]
);
CarShowWinner::updateOrCreate(
[
2022-05-01 08:58:49 -04:00
'category' => '18',
2019-07-11 20:55:45 -04:00
'place' => 'second'
],
[
2024-05-12 15:01:21 -04:00
'vehicle' => fortyThreeToSixtySevenWinner()
2019-07-11 20:55:45 -04:00
]
2022-06-08 20:21:59 -04:00
);
2023-04-12 19:31:00 -04:00
CarShowWinner::updateOrCreate(
[
'category' => '18',
'place' => 'third'
],
[
2024-05-12 15:01:21 -04:00
'vehicle' => fortyThreeToSixtySevenWinner()
2023-04-12 19:31:00 -04:00
]
);
//1968-1997
CarShowWinner::updateOrCreate(
[
'category' => '20',
'place' => 'first'
],
[
2024-05-12 15:01:21 -04:00
'vehicle' => sixtyEightToNinetyEightWinner()
2023-04-12 19:31:00 -04:00
]
);
CarShowWinner::updateOrCreate(
[
'category' => '20',
'place' => 'second'
],
[
2024-05-12 15:01:21 -04:00
'vehicle' => sixtyEightToNinetyEightWinner()
2023-04-12 19:31:00 -04:00
]
);
CarShowWinner::updateOrCreate(
[
'category' => '20',
'place' => 'third'
],
[
2024-05-12 15:01:21 -04:00
'vehicle' => sixtyEightToNinetyEightWinner()
2023-04-12 19:31:00 -04:00
]
);
2022-06-08 20:21:59 -04:00
//1998-Current
CarShowWinner::updateOrCreate(
[
'category' => '19',
'place' => 'first'
],
[
2024-03-16 13:39:58 -04:00
'vehicle' => NinetyNineToCurrentWinner()
2022-06-08 20:21:59 -04:00
]
);
CarShowWinner::updateOrCreate(
[
'category' => '19',
'place' => 'second'
],
[
2024-03-16 13:39:58 -04:00
'vehicle' => NinetyNineToCurrentWinner()
2023-04-12 19:31:00 -04:00
]
);
CarShowWinner::updateOrCreate(
[
'category' => '19',
'place' => 'third'
],
[
2024-03-16 13:39:58 -04:00
'vehicle' => NinetyNineToCurrentWinner()
2022-06-08 20:21:59 -04:00
]
);
2019-07-11 20:55:45 -04:00
}
}