-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix(ci): helm chart release (#407) * fix(ci): helm chart release action version (#404) * Bump guzzlehttp/guzzle from 7.7.0 to 7.8.0 (#403) Bumps [guzzlehttp/guzzle](https://github.com/guzzle/guzzle) from 7.7.0 to 7.8.0. - [Release notes](https://github.com/guzzle/guzzle/releases) - [Changelog](https://github.com/guzzle/guzzle/blob/7.8/CHANGELOG.md) - [Commits](guzzle/guzzle@7.7.0...7.8.0) --- updated-dependencies: - dependency-name: guzzlehttp/guzzle dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump axios from 1.4.0 to 1.5.0 (#402) Bumps [axios](https://github.com/axios/axios) from 1.4.0 to 1.5.0. - [Release notes](https://github.com/axios/axios/releases) - [Changelog](https://github.com/axios/axios/blob/v1.x/CHANGELOG.md) - [Commits](axios/axios@v1.4.0...v1.5.0) --- updated-dependencies: - dependency-name: axios dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * fix(ci): helm chart release (#406) --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * create division logger and offer env var for log file path * create controller and routes to use division logger * add logging to divisions and fix assignLeftover bug * create testing seeder and add config values for it * enable logging for both divisions * remove unused functions from GBD * additional checks for optimization and fixing leftover assignment * renamed seeder config to testingSeeder * remove logging routes, disable logging by default, rename logging env var --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: Simon Ostendorf <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
- Loading branch information
1 parent
78bc372
commit 5e25add
Showing
9 changed files
with
278 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?php | ||
|
||
namespace App\Helpers; | ||
|
||
use App\Models\Course; | ||
use App\Models\Event; | ||
use App\Models\Group; | ||
|
||
class DivisionLogger | ||
{ | ||
public string $logFilePath; | ||
public int $writeFlags; | ||
|
||
public function __construct($logFilePath, $writeFlags = FILE_APPEND) | ||
{ | ||
$this->logFilePath = $logFilePath; | ||
$this->writeFlags = $writeFlags; | ||
} | ||
|
||
/** | ||
* Logs current state of specified event | ||
* | ||
* @param Event $event The event that will be logged | ||
* @return void | ||
*/ | ||
public function logEvent(Event $event) | ||
{ | ||
$groupsTotal = $event->groups()->count(); | ||
$regsTotal = $event->registrations()->count(); | ||
$nonDrinkerRegsTotal = $event->registrations()->where('drinks_alcohol', '=', false)->count(); | ||
|
||
$line = sprintf('Event %d :: %d groups, %d total regs, %d non-drinker regs (%d %%)', $event->id, $groupsTotal, $regsTotal, $nonDrinkerRegsTotal, $nonDrinkerRegsTotal/$regsTotal * 100); | ||
|
||
$line .= "\n"; | ||
foreach (Course::all() as $course) { | ||
$regs = $event->registrations()->get(); | ||
$regsOfCourse = $regs->toQuery() | ||
->join('users', 'registrations.user_id', '=', 'users.id') | ||
->where('users.course_id', '=', $course->id) | ||
->get(); | ||
$regsCount = $regsOfCourse->count(); | ||
$nonDrinkerRegsCount = $regsOfCourse->where('drinks_alcohol', '=', false)->count(); | ||
|
||
$line .= sprintf('%s : [ %d t (%d %%), %d nd ] ;', $course->abbreviation, $regsCount, $regsCount/$regsTotal * 100, $nonDrinkerRegsCount); | ||
} | ||
|
||
$this->logMsg($line . "\n-----\n"); | ||
|
||
foreach ($event->groups as $group) { | ||
$this->logGroup($group); | ||
} | ||
|
||
$this->logMsg("-----\n"); | ||
} | ||
|
||
/** | ||
* Logs current state of specified group | ||
* | ||
* @param Group $group The group that will be logged | ||
* @return void | ||
*/ | ||
public function logGroup(Group $group) | ||
{ | ||
$regsTotal = $group->registrations()->count(); | ||
$nonDrinkerRegsTotal = $group->registrations()->where('drinks_alcohol', '=', false)->count(); | ||
|
||
$line = sprintf('Group %d :: %d total, %d non-drinker -- ', $group->id, $regsTotal, $nonDrinkerRegsTotal); | ||
|
||
if ($regsTotal == 0) { | ||
$line .= "\n"; | ||
$this->logMsg($line); | ||
return; | ||
} | ||
|
||
$this->logMsg($line); | ||
|
||
$line = ""; | ||
foreach (Course::all() as $course) { | ||
$regs = $group->registrations()->get(); | ||
$regsOfCourse = $regs->toQuery() | ||
->join('users', 'registrations.user_id', '=', 'users.id') | ||
->where('users.course_id', '=', $course->id) | ||
->get(); | ||
$regsCount = $regsOfCourse->count(); | ||
$nonDrinkerRegsCount = $regsOfCourse->where('drinks_alcohol', '=', false)->count(); | ||
|
||
$line .= sprintf('%s : [ %d t (%d %%), %d nd ] ;', $course->abbreviation, $regsCount, $regsCount/$regsTotal * 100, $nonDrinkerRegsCount); | ||
} | ||
$this->logMsg($line . "\n"); | ||
} | ||
|
||
/** | ||
* Logs a single message | ||
* | ||
* @param string $msg | ||
* @return void | ||
*/ | ||
public function logMsg(string $msg) | ||
{ | ||
file_put_contents($this->logFilePath, $msg, $this->writeFlags); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Helpers\GroupBalancedDivision; | ||
use App\Helpers\DivisionLogger; | ||
use App\Models\Event; | ||
use App\Models\Group; | ||
|
||
class DivisionLoggingController extends Controller | ||
{ | ||
public function logGrp(int $groupId) | ||
{ | ||
$logPath = 'logs/' . env('DIVISION_DEBUG_LOG', 'division.log'); | ||
$logger = new DivisionLogger(storage_path($logPath)); | ||
|
||
$group = Group::find($groupId); | ||
|
||
if (! $group) return sprintf('DIVISION_LOGGER_ERROR: Could not find group with ID %&d', $groupId); | ||
|
||
$logger->logGroup($group); | ||
|
||
return sprintf('DIVISION_LOGGER: Wrote group log (%s)', storage_path($logPath)); | ||
} | ||
|
||
public function logEvt(int $eventId) | ||
{ | ||
$logPath = 'logs/' . env('DIVISION_DEBUG_LOG', 'division.log'); | ||
$logger = new DivisionLogger(storage_path($logPath)); | ||
|
||
$event = Event::find($eventId); | ||
|
||
if (! $event) return sprintf('DIVISION_LOGGER_ERROR: Could not find event with ID %&d', $eventId); | ||
|
||
$logger->logEvent($event); | ||
|
||
return sprintf('DIVISION_LOGGER: Wrote event log (%s)', storage_path($logPath)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.