Skip to content

Commit

Permalink
Issue #292 - Calculating and showing final result of process
Browse files Browse the repository at this point in the history
  • Loading branch information
Emiliemorais committed May 1, 2017
1 parent 8c801d2 commit 139273c
Show file tree
Hide file tree
Showing 6 changed files with 219 additions and 50 deletions.
66 changes: 59 additions & 7 deletions application/modules/program/controllers/Selectiveprocess.php
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,9 @@ public function showResults($processId){
$allProcessCandidates = $this->selectiveprocessevaluation->getCandidates($allProcessCandidates);

$candidatesResults = [];
$approvedCandidates = [];
$resultCandidatesByPhase = [];
$status = $selectiveProcess->getStatus();
$phasesResultPerCandidate = [];
if($allProcessCandidates){

foreach ($allProcessCandidates as $candidateId => $evaluations) {
Expand All @@ -392,7 +394,7 @@ public function showResults($processId){
foreach ($candidatesResults as $key => $results) {
$hasResult = TRUE;
$phase = $this->process_evaluation_model->getPhaseNameByPhaseProcessId($key);
$approvedCandidatesInPhase = array();
$resultOfCandidatesInPhase = array();
foreach ($results as $candidateId => $result) {
if($phase->phase_name == SelectionProcessConstants::HOMOLOGATION_PHASE){
$hasResult = TRUE;
Expand All @@ -401,25 +403,75 @@ public function showResults($processId){
$hasResult = $result['hasResult'] && $hasResult;
}

if($hasResult && ($result['approved'] || $phase->phase_name == SelectionProcessConstants::HOMOLOGATION_PHASE)){
$approvedCandidatesInPhase[] = $candidateId;
if($hasResult){
$label = $this->selectiveprocessevaluation->getCandidatePhaseResultLabel($result);
$result['label'] = $label;
$resultOfCandidatesInPhase[$candidateId] = $result;

if($status === SelectionProcessConstants::FINISHED){
$phaseInfo = array('phase_weight' => $phase->weight);
$phasesResultPerCandidate[$candidateId][$phase->phase_name] = $result + $phaseInfo;
}
}
}
if(!empty($approvedCandidatesInPhase)){
$approvedCandidates[$phase->phase_name] = $approvedCandidatesInPhase;
if(!empty($resultOfCandidatesInPhase)){
$resultCandidatesByPhase[$phase->phase_name] = $resultOfCandidatesInPhase;
}
}
}
}

if($phasesResultPerCandidate){
$quantityOfPhases = sizeof($resultCandidatesByPhase);
$selectedCandidates = $this->getFinalResult($quantityOfPhases, $phasesResultPerCandidate);
$resultCandidatesByPhase = $selectedCandidates + $resultCandidatesByPhase;
}

$data = array(
'approvedCandidates' => $approvedCandidates,
'resultCandidatesByPhase' => $resultCandidatesByPhase,
'process' => $selectiveProcess
);

loadTemplateSafelyByPermission(PermissionConstants::SELECTION_PROCESS_PERMISSION, "program/selection_process/results", $data);
}

private function getFinalResult($quantityOfPhases, $phasesResultPerCandidate){

$selectedCandidates = array();
$candidatesScore = array();
$quantityOfPhases = $quantityOfPhases - 1;
if($phasesResultPerCandidate){
foreach ($phasesResultPerCandidate as $candidateId => $phasesResults) {
unset($phasesResults[SelectionProcessConstants::HOMOLOGATION_PHASE]);
$candidatePoints = 0;
$totalWeight = 0;
$approvedTimes = 0;
foreach ($phasesResults as $phaseName => $phaseResult) {
$phaseWeight = $phaseResult['phase_weight'];
$candidatePoints += ($phaseWeight * $phaseResult['average']);
$totalWeight += $phaseWeight;

$candidatesScore[$candidateId][] = array(
'phaseName' => $phaseName,
'average' => $phaseResult['average'],
'phaseWeight' => $phaseWeight,
);
$approvedTimes = $phaseResult['approved'] ? $approvedTimes + 1 : $approvedTimes;
}

$candidatePointsAverage = $candidatePoints/$totalWeight;
$candidatesScore[$candidateId]['final_average'] = $candidatePointsAverage;
$selected = $approvedTimes == $quantityOfPhases ? TRUE : FALSE;
$candidatesScore[$candidateId]['selected'] = $selected;
}
}

arsort($candidatesScore);
$selectedCandidates['Final'] = $candidatesScore;

return $selectedCandidates;
}

public function generatePDF(){

$candidates = $this->input->post('candidates');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,9 @@ public function getCandidates($evaluations, $resultInLabelForm = FALSE){
$candidateId = $subscription['candidate_id'];
$idProcessPhase = $evaluation['id_process_phase'];
$candidatesEvaluations[$candidateId][$idProcessPhase][$idSubscription][] = $evaluation;
$phaseResult = $this->getCandidatePhaseResult($evaluation['id_subscription'], $idProcessPhase);
if($resultInLabelForm){
$phaseResult = $this->getCandidatePhaseResultLabel($evaluation['id_subscription'], $idProcessPhase);
}
else{
$phaseResult = $this->getCandidatePhaseResult($evaluation['id_subscription'], $idProcessPhase);
$phaseResult = $this->getCandidatePhaseResultLabel($phaseResult);
}
$candidatesEvaluations[$candidateId][$idProcessPhase]['phase_result'] = $phaseResult;
}
Expand Down Expand Up @@ -158,7 +156,8 @@ private function saveGrade(){
$data = ['grade' => $grade];
$saved = $this->process_evaluation_model->saveOrUpdate($subscriptionId, $teacherId, $phaseprocessId, $data);
if($saved){
$labelCandidate = $this->getCandidatePhaseResultLabel($subscriptionId, $phaseprocessId);
$phaseResult = $this->getCandidatePhaseResult($subscriptionId, $phaseprocessId);
$labelCandidate = $this->getCandidatePhaseResultLabel($phaseResult);

$response = array(
'type' => "success",
Expand Down Expand Up @@ -191,6 +190,7 @@ public function getCandidatePhaseResult($subscriptionId, $phaseprocessId){
$phaseEvaluationElements = $this->process_evaluation_model->getPhaseEvaluationElementsOfPhaseByProcessPhaseId($phaseprocessId);

$totalGrade = 0;
$knockoutPhase = $phaseEvaluationElements->knockout_phase;
foreach ($candidateGradesOnPhase as $result) {

if(is_null($result['grade'])){
Expand All @@ -205,37 +205,28 @@ public function getCandidatePhaseResult($subscriptionId, $phaseprocessId){
}

$approvedOnPhase = FALSE;
$knockoutPhase = $phaseEvaluationElements->knockout_phase;
$passingScore = $phaseEvaluationElements->grade;
$average = 0;
if($hasResult && $knockoutPhase){
if(($totalGrade/2) >= $passingScore){
$average = $totalGrade/2;
if($average >= $passingScore){
$approvedOnPhase = TRUE;
}
}
elseif (!$knockoutPhase) {
$average = $totalGrade/2;
$approvedOnPhase = TRUE;
}

$phaseResult = ['hasResult' => $hasResult, 'approved' => $approvedOnPhase, 'knockoutPhase' => $knockoutPhase];
$phaseResult = ['hasResult' => $hasResult, 'approved' => $approvedOnPhase, 'knockoutPhase' => $knockoutPhase, 'average' => $average];

return $phaseResult;
}

public function getCandidatePhaseResultLabel($subscriptionId, $phaseprocessId){

$phaseResult = $this->getCandidatePhaseResult($subscriptionId, $phaseprocessId);
public function getCandidatePhaseResultLabel($phaseResult){

if($phaseResult['hasResult']){
if($phaseResult['approved'] && $phaseResult['knockoutPhase']){
$labelCandidate = "<b class='text text-success'>Aprovado</b>";
}
elseif ($phaseResult['approved'] && !$phaseResult['knockoutPhase']) {
$labelCandidate = "<b class='text text-success'>Classificado</b>";
}
else{

$labelCandidate = "<b class='text text-danger'>Reprovado</b>";
}
$labelCandidate = $phaseResult['approved'] ? "<b class='text text-success'>Aprovado</b>" : "<b class='text text-danger'>Eliminado</b>";
}
else{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function getProcessesOnObject($processes){

public function getPhaseNameByPhaseProcessId($processphaseId){

$this->db->select("phase.phase_name");
$this->db->select("phase.phase_name, pp.weight");
$this->db->join("phase", "phase.id_phase = pp.id_phase");
$this->db->where("id", $processphaseId);

Expand Down Expand Up @@ -132,7 +132,7 @@ public function getProcessCandidates($processId){

$query = "SELECT * FROM `selection_process_evaluation`";
$query .= "WHERE `id_process_phase` IN (SELECT `id` FROM `process_phase` WHERE `id_process` = {$processId}) ";
$query .= "ORDER BY `id_subscription`";
$query .= "ORDER BY `id_process_phase`";


$evaluations = $this->db->query($query);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ function createNextPhaseModal($process){
}
else{
$question = "Deseja <b>finalizar</b> o processo?";
$formPath = "selection_process/finalize_process/{$processId}/{$courseId}";
$formPath = "selection_process/next_phase/{$processId}/{$courseId}";
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
<h2 class="principal">Processo Seletivo <b><i><?=$processName?></i></b> </h2>
<?php $resultLabel = $phaseName == "Final" ? "<b>Resultado Final</b><br>Candidatos selecionados" : "Resultado da fase de <b>{$phaseName}</b>";?>
<div class="box box-primary">
<div class="box-header">
<h3 class="box-title">Resultado da fase de <b><?=$phaseName?></b></h3>
<h3 class="box-title"><?=$resultLabel?></h3>
</div>
<div class="box-body">
<ul class="list-unstyled">
<h4><center> Candidatos aprovados </center></h4>
<?php
foreach ($candidates->candidates as $candidateId) {
echo "<h4><li><center><b>{$candidateId}</b></center></li></h4>";
}?>
</ul>
<?php
if($phaseName == SelectionProcessConstants::HOMOLOGATION_PHASE){
createHomologationTable($candidates->candidates);
}
elseif($phaseName == "Final"){
createFinalTable($candidates->candidates);
}else{
createTableByPhase($candidates->candidates);
} ?>
</div><!-- /.box-body -->
<div class="box-footer no-print">
<button id= "print_report_btn" class= "btn btn-primary btn-flat" type= "submit"><i class='fa fa-print'></i> Imprimir Resultado</button>
Expand All @@ -22,6 +25,68 @@
</div><!-- /.box-footer-->
</div>

<?php
function createHomologationTable($candidates){
buildTableDeclaration();
buildTableHeaders(array('Candidatos homologados'));
foreach ($candidates as $candidateId => $result) {
echo "<tr>";
echo "<td><h4><center>{$candidateId}</center></h4></td>";
echo "</tr>";
}
buildTableEndDeclaration();
}

function createTableByPhase($candidates){
buildTableDeclaration();
buildTableHeaders(array('Candidato', 'Nota', 'Resultado'));
foreach ($candidates as $candidateId => $result) {
$average = $result->average;
$labelResult = $result->label;
echo "<tr>";
echo "<td><h4><center>{$candidateId}</center></h4></td>";
echo "<td><center>{$average}</center></td>";
echo "<td><center>{$labelResult}</center></td>";
echo "</tr>";
}
buildTableEndDeclaration();
}

function createFinalTable($candidates){
buildTableDeclaration();
$headers = array('Classificação', 'Candidato');
$first = key($candidates);
$candidatesHeaders = clone $candidates->$first;
unset($candidatesHeaders->final_average);
unset($candidatesHeaders->selected);
foreach ($candidatesHeaders as $header) {
$headers[] = "Nota da Fase ".$header->phaseName."- Peso ".$header->phaseWeight;
}
$headers[] = "Nota Final";
buildTableHeaders($headers);
$classificacao = 1;
foreach ($candidates as $candidateId => $result) {
$selected = $result->selected;
$finalAverage = number_format($result->final_average, 2, ',', ' ');
unset($result->final_average);
unset($result->selected);
if($selected){
echo "<tr>";
echo "<td><center>{$classificacao}º</center></td>";
echo "<td><h4><center>{$candidateId}</center></h4></td>";
foreach ($result as $phaseResult) {
$average = $phaseResult->average;
echo "<td><center>{$average}</center></td>";
}
echo "<td><center>{$finalAverage}</center></td>";
echo "</tr>";
$classificacao++;
}
}
buildTableEndDeclaration();
}
?>

<script>
$(document).ready(function(){
window.print();
Expand Down
Loading

0 comments on commit 139273c

Please sign in to comment.