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;
|
|
|
|
}
|
2020-02-08 15:24:15 -05:00
|
|
|
|
2019-07-11 20:55:45 -04:00
|
|
|
function pcWinner()
|
|
|
|
{
|
|
|
|
$peoplesChoiceWinnerQuery = DB::table('peoples_choice')
|
|
|
|
->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 08:58:49 -04:00
|
|
|
function zeroTo43Winner()
|
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)
|
|
|
|
->where('vehicles.year', '<=', 1943)
|
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
|
|
|
|
|
|
|
function fortyFourToCurrentWinner()
|
2019-07-11 20:55:45 -04:00
|
|
|
{
|
2022-05-01 08:58:49 -04:00
|
|
|
$fortyFourToCurrentQuery = 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', '>=', 1944)
|
2019-07-11 20:55:45 -04:00
|
|
|
//->where('vehicles.year', '<=', 1959)
|
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 $fortyFourToCurrentQuery->vehicle;
|
2020-02-08 15:24:15 -05:00
|
|
|
}
|
2022-05-01 08:58:49 -04:00
|
|
|
|
2019-07-11 20:55:45 -04:00
|
|
|
//categories
|
|
|
|
/* Here for reference only
|
|
|
|
$individuallyProcessedAwards = array(
|
|
|
|
'inShowFirst' =>'6',
|
|
|
|
'pcFirst' => '3'
|
|
|
|
); */
|
|
|
|
$mainAwardsToCalculate = array(
|
2022-05-01 08:58:49 -04:00
|
|
|
'inShowFirst' =>'6',
|
|
|
|
'inShowSecond' =>'6',
|
|
|
|
'pcFirst' => '3',
|
|
|
|
'pcSecond' => '3'
|
2019-07-11 20:55:45 -04:00
|
|
|
);
|
|
|
|
$yearAwardsToCalculate = array(
|
2022-05-01 08:58:49 -04:00
|
|
|
'zeroTo43First' => '17',
|
|
|
|
'zeroTo43Second' => '17',
|
|
|
|
'fourtyFourToCurrentFirst' => '18',
|
|
|
|
'fourtyFourToCurrentSecond' => '18'
|
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()
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
//Insert Best In Show 2nd Place Winner
|
|
|
|
CarShowWinner::updateOrCreate(
|
|
|
|
[
|
|
|
|
'category' => '6',
|
|
|
|
'place' => 'second'
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'vehicle' => bestInShowWinner()
|
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
|
|
|
);
|
2019-07-11 20:55:45 -04:00
|
|
|
|
|
|
|
CarShowWinner::updateOrCreate(
|
2022-05-01 08:58:49 -04:00
|
|
|
[
|
|
|
|
'category' => '3',
|
|
|
|
'place' => 'second'
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'vehicle' => pcWinner()
|
|
|
|
]
|
|
|
|
);
|
|
|
|
//Insert Year Award Winners
|
|
|
|
//0-1943
|
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'
|
|
|
|
],
|
|
|
|
[
|
2022-05-01 08:58:49 -04:00
|
|
|
'vehicle' => zeroTo43Winner()
|
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'
|
|
|
|
],
|
|
|
|
[
|
2022-05-01 08:58:49 -04:00
|
|
|
'vehicle' => zeroTo43Winner()
|
2019-07-11 20:55:45 -04:00
|
|
|
]
|
|
|
|
);
|
2022-05-01 08:58:49 -04:00
|
|
|
//1944-Current
|
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'
|
|
|
|
],
|
|
|
|
[
|
2022-05-01 08:58:49 -04:00
|
|
|
'vehicle' => fortyFourToCurrentWinner()
|
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'
|
|
|
|
],
|
|
|
|
[
|
2022-05-01 08:58:49 -04:00
|
|
|
'vehicle' => fortyFourToCurrentWinner()
|
2019-07-11 20:55:45 -04:00
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|