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

272 lines
9.0 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;
}
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
2022-05-01 09:44:49 -04:00
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;
}
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
2022-05-01 09:44:49 -04:00
function fortyFourToCurrent2ndWinner()
{
$fortyFourToCurrent2ndQuery = 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', '<=', 1959)
->where('vehicles.doNotJudge', '=', 0)
->orderBy('totalscore','desc')
->first();
return $fortyFourToCurrent2ndQuery->vehicle;
}
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'
],
[
2022-05-01 09:42:47 -04:00
'vehicle' => bestInShow2ndWinner()
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'
],
[
2022-05-01 09:44:49 -04:00
'vehicle' => pc2ndWinner()
2022-05-01 08:58:49 -04:00
]
);
//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 09:44:49 -04:00
'vehicle' => zeroTo432ndWinner()
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 09:44:49 -04:00
'vehicle' => fortyFourToCurrent2ndWinner()
2019-07-11 20:55:45 -04:00
]
);
}
}