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

404 lines
13 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()
{
function mainWinner()
{
$mainWinnerQuery = 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');
})
->orderBy('totalscore','desc')
->first();
return $mainWinnerQuery->vehicle;
}
2020-02-08 15:02:53 -05:00
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');
})
2020-02-08 15:17:33 -05:00
//->where('vehicles.doNotJudge', '=', "0")
->where('vehicles.type', '=', "$category")
2020-02-08 15:02:53 -05:00
->orderBy('totalscore', 'desc')
->first();
return $categoryWinnerQuery->vehicle;
}
2019-07-11 20:55:45 -04:00
2020-02-08 12:49:38 -05:00
2019-07-11 20:55:45 -04:00
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');
})
->orderBy('totalscore','desc')
->first();
return $peoplesChoiceWinnerQuery->vehicle;
}
2020-02-08 12:49:38 -05:00
function oughtsTo49Winner()
2019-07-11 20:55:45 -04:00
{
$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)
->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)
->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)
->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)
->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)
->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)
->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)
->orderBy('totalscore','desc')
->first();
return $thousandsQuery->vehicle;
}
//categories
/* Here for reference only
$individuallyProcessedAwards = array(
'inShowFirst' =>'6',
'pcFirst' => '3'
); */
$mainAwardsToCalculate = array(
'inShowFirst' =>'6',
'pcFirst' => '3',
'bestTruckFirst' => '5',
'corvetteFirst' => '7',
'camaroFirst' => '8',
'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'
],
[
2020-02-08 15:02:53 -05:00
'vehicle' => categoryWinner($category)
2019-07-11 20:55:45 -04:00
]
);
}
//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()
]
);
}
}