Skip to content
This repository has been archived by the owner on Oct 5, 2021. It is now read-only.

Commit

Permalink
ScoreEngine: Make the Staff Scoreboard even better
Browse files Browse the repository at this point in the history
  • Loading branch information
jtdroste committed Apr 18, 2017
1 parent 2bc472e commit 507fa2c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 25 deletions.
41 changes: 19 additions & 22 deletions app/Plugin/ScoreEngine/Controller/ScoreboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,11 @@
App::uses('ScoreEngineAppController', 'ScoreEngine.Controller');

class ScoreboardController extends ScoreEngineAppController {
public $helpers = ['ScoreEngine.EngineOutputter'];
public $uses = [
'ScoreEngine.Check', 'ScoreEngine.Service', 'ScoreEngine.Team', 'ScoreEngine.Round',
'Config', 'Submission', 'Schedule', 'Group'
];

public function beforeRender() {
parent::beforeRender();

// Setup the ScoreEngine EngineOutputter
$this->helpers['ScoreEngine.EngineOutputter']['data'] = $this->Check->getChecksTable(
$this->Team->findAllByEnabled(true),
$this->Service->findAllByEnabled(true)
);
}

/**
* ScoreBoard Overview Page
*
Expand Down Expand Up @@ -57,17 +46,7 @@ public function overview() {
}

// Grab the check overview
$overview = $this->Check->find('all', [
'fields' => [
'Check.total_passed', 'Check.total', 'Team.id',
],
'group' => [
'Team.id',
],
'order' => [
'Check.total_passed DESC',
],
]);
$overview = $this->Check->getMaxCheck(false);

// Grab the grade overview
$grades = $this->Submission->getGrades($this->Group->getChildren(env('GROUP_BLUE')));
Expand All @@ -76,12 +55,24 @@ public function overview() {
$grade_team_mappings[$g['Group']['team_number']] = $g['Submission']['total_grade'];
}

// Grab the max check
$max_check = $this->Check->getMaxCheck(true);

// Grab the max grade
$injects = $this->Schedule->getInjects(env('GROUP_BLUE'));
$max_grade = 0;
foreach ( $injects AS $i ) {
$max_grade += $i->getInjectMaxPoints();
}

$this->set('at_staff', true);
$this->set('round', $this->Round->getLastRound());
$this->set('overview', $overview);
$this->set('grades', $grades);
$this->set('grade_team_mappings', $grade_team_mappings);
$this->set('team_mappings', $team_mappings);
$this->set('max_grade', $max_grade);
$this->set('max_check', $max_check[0]['Check']['total_passed']);
}

/**
Expand All @@ -98,6 +89,12 @@ public function api() {
if ( $inject->isExpired() ) unset($active_injects[$i]);
}

// Setup the ScoreEngine EngineOutputter
$this->helpers['ScoreEngine.EngineOutputter']['data'] = $this->Check->getChecksTable(
$this->Team->findAllByEnabledAndCheckTeam(true, false),
$this->Service->findAllByEnabled(true)
);

$this->set('active_injects', $active_injects);
$this->set('round', $this->Round->getLastRound());
}
Expand Down
23 changes: 21 additions & 2 deletions app/Plugin/ScoreEngine/Model/Check.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ public function getChecksTable($teams, $services) {
]);

foreach ( $data AS $d ) {
if ( !in_array($d['Service']['id'], $enabled_services) ) continue;

$team_name = $d['Team']['name'];
$service_name = $d['Service']['name'];

if ( !in_array($d['Service']['id'], $enabled_services) ) continue;
if ( !isset($rtn[$team_name]) ) continue;

$rtn[$team_name][$service_name] = ((bool) $d['Check']['passed']);
}
return $rtn;
Expand Down Expand Up @@ -109,4 +110,22 @@ public function getLastTeamCheck($tid) {

return $rtn;
}

public function getMaxCheck($onlyCheckTeam=false) {
return $this->find('all', [
'fields' => [
'Check.total_passed', 'Check.total',
'Team.id', 'Team.check_team',
],
'conditions' => [
'Team.check_team' => $onlyCheckTeam,
],
'group' => [
'Team.id',
],
'order' => [
'Check.total_passed DESC',
],
]);
}
}
1 change: 0 additions & 1 deletion app/Plugin/ScoreEngine/Model/Round.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
App::uses('ScoreEngineAppModel', 'ScoreEngine.Model');

class Round extends ScoreEngineAppModel {

public function getLastRound() {
$round = $this->find('first', [
'fields' => [
Expand Down
3 changes: 3 additions & 0 deletions app/Plugin/ScoreEngine/View/Scoreboard/overview.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ function drawScoreboard() {
data.addColumn('number', 'Successful Checks');
data.addColumn('number', 'Inject Score');
data.addRows([
[
'Check Team', <?= $max_check; ?>, <?= $max_grade; ?>
],
<?php foreach ( $overview AS $o ): ?>
[
'<?= $team_mappings[$o['Team']['id']]; ?>',
Expand Down

0 comments on commit 507fa2c

Please sign in to comment.