Skip to content

Commit

Permalink
Merge pull request #341 from czqoocavatsim/JoshuaBranch
Browse files Browse the repository at this point in the history
Quite a few Updates
  • Loading branch information
JoshuaMicallefYBSU authored Aug 30, 2024
2 parents 1cf0991 + 7038e56 commit 8e8f7d3
Show file tree
Hide file tree
Showing 8 changed files with 172 additions and 41 deletions.
33 changes: 13 additions & 20 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected function schedule(Schedule $schedule)
$schedule->job(new ProcessSessionLogging())->everyMinute();

//Inactivity checks
$schedule->job(new ProcessRosterInactivity())->dailyAt('8:30');
$schedule->job(new ProcessRosterInactivity())->daily();

//CRONS FOR INACTIVITY EMAILS 2 weeks
// $schedule->call(function () {
Expand Down Expand Up @@ -78,28 +78,21 @@ protected function schedule(Schedule $schedule)
// $discord->sendMessage(753086414811562014, 'Sent '.$count.' one-week warning inactivity emails');
// })->cron('00 00 23 MAR,JUN,SEP,DEC *'); // 1 week before end of quarter*/

// Monthly Statistics Breakdown
$schedule->job(new ProcessShanwickController())->monthlyOn(1, '00:00');

/// Monthly leaderboard wipe
$schedule->call(function () {
// Loop through all roster members
foreach (RosterMember::all() as $rosterMember) {
// Reset the hours for every member
$rosterMember->monthly_hours = 0.0;
$rosterMember->save();
}
})->monthlyOn(1, '00:00');

// Quarterly Currency Wipe
$schedule->call(function () {
// Loop through all roster members
foreach (RosterMember::all() as $rosterMember) {
// Reset the hours for every member
$rosterMember->currency = 0.0;
$rosterMember->save();
}
})->cron('15 00 01 JAN,APR,JUL,OCT *');
// $schedule->call(function () {
// // Loop through all roster members
// foreach (RosterMember::all() as $rosterMember) {
// // Reset the hours for every member
// $rosterMember->monthly_hours = 0.0;
// $rosterMember->save();
// }
// })

//Solo cert expiry warning
$schedule->job(new ProcessSoloCertExpiryWarnings())->daily();
// $schedule->job(new ProcessSoloCertExpiryWarnings())->daily();

// Shanwick Controller Roster Update
$schedule->job(new ProcessShanwickController())->daily();
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/DiscordTestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Illuminate\Http\Request;
use App\Services\DiscordClient;
use App\Jobs\ProcessRosterInactivity;
use App\Jobs\ProcessMonthlyBreakdown;

class DiscordTestController extends Controller
{
Expand All @@ -26,7 +26,7 @@ public function EditTagTest()
public function Job()
{
// Dispatch the job
$job = ProcessRosterInactivity::dispatch();
$job = ProcessMonthlyBreakdown::dispatch();

// Call the handle method directly to get the result synchronously
$result = $job->handle();
Expand Down
4 changes: 3 additions & 1 deletion app/Http/Controllers/PrimaryViewsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ public function dashboard(Request $request)
{
$user = Auth::user();

$sessions = SessionLog::where('cid', Auth::user()->id)->where('created_at', '>=', Carbon::now()->subMonths(12))->orderBy('created_at', 'desc')->get();

$atcResources = AtcResource::all()->sortBy('title');

$bannerCollection = RotationImage::all();
Expand All @@ -73,6 +75,6 @@ public function dashboard(Request $request)
$bannerImg = null;
}

return view('my.index', compact('atcResources', 'bannerImg'));
return view('my.index', compact('atcResources', 'bannerImg', 'sessions'));
}
}
2 changes: 0 additions & 2 deletions app/Jobs/DiscordAccountCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ class DiscordAccountCheck implements ShouldQueue
* @return void
*/

protected $signature = 'discord:accountupdate';

public function handle()
{
// Initialise some variables
Expand Down
82 changes: 82 additions & 0 deletions app/Jobs/ProcessMonthlyBreakdown.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

use GuzzleHttp\Client;
use App\Services\DiscordClient;
use App\Models\Training\Instructing\Records\TrainingSession;
use App\Models\Users\User;
use App\Models\Roster\RosterMember;
use App\Models\News\HomeNewControllerCert;
use App\Notifications\Training\Instructing\RemovedAsStudent;
use App\Models\Training\Instructing\Students\StudentStatusLabel;
use App\Models\Training\Instructing\Links\StudentStatusLabelLink;
use Carbon\Carbon;

class ProcessMonthlyBreakdown implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

/**
* Execute the job.
*
* @return void
*/

public function handle()
{
// Get Collection Values
$roster_member = RosterMember::all();
$top_3 = RosterMember::all()->sortByDesc(function ($member) {return (float) $member->monthly_hours;})->take(3);
$new_controllers = HomeNewControllerCert::where('timestamp', '>=', Carbon::now()->subMonths(1))->get();

// Set Variables
$total_hours = 0;

foreach($roster_member as $roster){
$total_hours += $roster->monthly_hours;
}

$message = 'It is the beginning of a new month, so here are some wonderful stats for ' . Carbon::now()->subMonth()->format('F, Y') . "\n\n";

$message .= "**__Total Controller Hours__**\n";
$message .= "- " . $total_hours . " hours\n";

$message .= "\n**__Top 3 Controllers__**\n";

foreach($top_3 as $t) {
if($t->user->discord_user_id === null){
$message .= "- " . $t->user->fullName('FLC') . " - ".$t->monthly_hours."\n";
} else {
$message .= "- <@" . $t->user->discord_user_id . "> - ".$t->monthly_hours."\n";
}
}

$message .= "\n**__New Certified Controllers__**\n";

foreach($new_controllers as $nc) {
if($nc->controller->discord_user_id === null){
$message .= "- " . $nc->controller->fullName('FLC') . "\n";
} else {
$message .= "- <@" . $nc->controller->discord_user_id . ">\n";
}
}

$message .= "\nWell done to everyone for your contributions to Gander Oceanic over the last Month! Enjoy ".Carbon::now()->format('F, Y');

$discord = new DiscordClient();
$discord->sendMessageWithEmbed('1274861846880456785', 'Gander Oceanic Operations Breakdown - '.Carbon::now()->subMonth()->format('F, Y'), $message);

foreach($roster_member as $roster){
$roster->monthly_hours = 0.0;
$roster->save();
}
}

}
23 changes: 14 additions & 9 deletions app/Jobs/ProcessRosterInactivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ public function handle()

// Go through each session to get some information
foreach($sessions as $s){
$currency += $s->duration;
if($s->duration > 0.49){
$currency += $s->duration;
}
}


Expand Down Expand Up @@ -135,19 +137,22 @@ public function handle()

}

$roster->user->removeRole('Certified Controller');
$roster->user->removeRole('Certified Controller');
$roster->user->assignRole('Guest');
$roster->delete();
$termination_notice++;
}
}

// Send Web Notification if any changes have been made
$discord = new DiscordClient();
$discord->sendMessageWithEmbed(env('DISCORD_WEB_LOGS'), 'AUTO: Roster Inactivity Update',
'60 Days till Removed: '.$first_notice.'
30 Days till Removed: '.$second_notice.'
7 Days till Removed: '.$third_notice.'
Removed from Roster: '.$termination_notice
);
if($first_notice != 0 || $second_notice !== 0 || $third_notice !== 0 || $termination_notice !== 0){
$discord = new DiscordClient();
$discord->sendMessageWithEmbed(env('DISCORD_WEB_LOGS'), 'AUTO: Roster Inactivity Update',
'The Following changes have occured to the Controller Roster
60 Days till Removed: '.$first_notice.'
30 Days till Removed: '.$second_notice.'
7 Days till Removed: '.$third_notice.'
Removed from Roster: '.$termination_notice
);
}
}}
23 changes: 19 additions & 4 deletions app/Jobs/ProcessSessionLogging.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,26 @@ public function handle()

//If there is an associated roster member, give them the hours and set as active
if ($rosterMember = $log->rosterMember) {

// Set variables
$currency = $log->session_start->floatDiffInMinutes(Carbon::now()) / 60;
$monthly_hours = $log->session_start->floatDiffInMinutes(Carbon::now()) / 60;

// Controller is either Certified or In Training
if (($rosterMember->certification == 'certified' || $rosterMember->certification == 'training')) {
$rosterMember->currency += $log->session_start->floatDiffInMinutes(Carbon::now()) / 60;
$rosterMember->monthly_hours += $log->session_start->floatDiffInMinutes(Carbon::now()) / 60;
$rosterMember->active = 1;
$rosterMember->save();

// Only add hours if more than 30mins
if($currency > 0.49){
$rosterMember->currency += $currency;
$rosterMember->monthly_hours += $monthly_hours;
$rosterMember->save();
}

// Set user as active if more than 1 hour
if($rosterMember->currency > 0.99){
$rosterMember->active = 1;
$rosterMember->save();
}
}
}
}
Expand Down
42 changes: 39 additions & 3 deletions resources/views/my/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ class="list-group-item list-group-item-action p-4 z-depth-1 shadow-none mb-3">
{{ $rosterProfile->activeLabelHtml() }}
</h3>
</div>
<h3 class="font-weight-bold blue-text mt-3 pb-2">Activity</h3>
<h3 class="font-weight-bold blue-text mt-4 pb-2">Activity</h3>
@php
$currency = auth()->user()->rosterProfile->currency;
$class = $currency < 0.1 ? 'red' : ($currency < 1.0 ? 'blue' : 'green');
Expand All @@ -364,9 +364,45 @@ class="list-group-item list-group-item-action p-4 z-depth-1 shadow-none mb-3">
class='badge rounded {{ $class }} text-white p-2 shadow-none'>
{{ $currency }} hours recorded
</span>
</h3>
</h3>

<p class="mt-2">To remain active, you require 60 minutes of connection within the last 12 months.</p>

<p class="mt-4">You require 1 hour of activity within the last 12 months.</p>
<h3 class="font-weight-bold blue-text mt-4 pb-2">Your Connections</h3>
<p class="mt-2">List of all your Gander Oceanic connections to VATSIM over the last 12 Months.</p>
<p class="mt-0">Connections less than 30 minutes are shown in red, and do not count towards Controller Currency.</p>
<table class="table dt table-hover table-bordered">
<thead>
<th>Position</th>
<th>Logon</th>
<th>Logoff</th>
<th>Time</th>
</thead>
<tbody>
@foreach ($sessions as $s)
<tr>
<th>{{$s->callsign}}</th>
<th>{{\Carbon\Carbon::parse($s->session_start)->format('l, d F \a\t Hi\Z')}}</th>
<th>
@if($s->session_end === null)
Currently Connected
@else
{{\Carbon\Carbon::parse($s->session_end)->format('l, d F \a\t Hi\Z')}}
@endif
</th>
@if($s->duration < 0.5)
<td class="bg-danger text-white">
{{$s->duration}}
</td>
@else
<td class="bg-success text-white">
{{$s->duration}}
</td>
@endif
</tr>
@endforeach
</tbody>
</table>
@else
<h3>
<span style='font-weight: 400' class='badge rounded p-2 red text-white shadow-none'>
Expand Down

0 comments on commit 8e8f7d3

Please sign in to comment.