Gradebook: Fix best category column calculation BT#16157

behat
Julio 6 years ago
parent 67e5db66a1
commit 67a6035622
  1. 50
      main/gradebook/lib/be/category.class.php
  2. 4
      main/gradebook/lib/be/exerciselink.class.php
  3. 15
      main/gradebook/lib/fe/gradebooktable.class.php
  4. 22
      main/gradebook/lib/flatview_data_generator.class.php

@ -969,10 +969,8 @@ class Category implements GradebookItem
$linkres = $link->calc_score($stud_id, null);
if (!empty($linkres) && $link->get_weight() != 0) {
$students[$stud_id] = $linkres[0];
$linkweight = $link->get_weight();
$link_res_denom = $linkres[1] == 0 ? 1 : $linkres[1];
$count++;
$weightsum += $linkweight;
$ressum += $linkres[0] / $link_res_denom * $linkweight;
} else {
@ -1000,10 +998,10 @@ class Category implements GradebookItem
}
// Calculate score
$count = 0;
$ressum = 0;
$weightsum = 0;
$bestResult = 0;
$totalScorePerStudent = [];
if (!empty($cats)) {
/** @var Category $cat */
@ -1033,6 +1031,23 @@ class Category implements GradebookItem
}
if (!empty($evals)) {
if ($type === 'best') {
$studentList = $this->getStudentList();
foreach ($studentList as $student) {
$studentId = $student['user_id'];
foreach ($evals as $eval) {
$linkres = $eval->calc_score($studentId, null);
$linkweight = $eval->get_weight();
$link_res_denom = $linkres[1] == 0 ? 1 : $linkres[1];
$ressum = $linkres[0] / $link_res_denom * $linkweight;
if (!isset($totalScorePerStudent[$studentId])) {
$totalScorePerStudent[$studentId] = 0;
}
$totalScorePerStudent[$studentId] += $ressum;
}
}
} else {
/** @var Evaluation $eval */
foreach ($evals as $eval) {
$evalres = $eval->calc_score(null, $type);
@ -1041,7 +1056,6 @@ class Category implements GradebookItem
if (isset($evalres) && $eval->get_weight() != 0) {
$evalweight = $eval->get_weight();
$weightsum += $evalweight;
$count++;
if (!empty($evalres[1])) {
$ressum += $evalres[0] / $evalres[1] * $evalweight;
}
@ -1057,7 +1071,26 @@ class Category implements GradebookItem
}
}
}
}
if (!empty($links)) {
$studentList = $this->getStudentList();
if ($type === 'best') {
foreach ($studentList as $student) {
$studentId = $student['user_id'];
foreach ($links as $link) {
$linkres = $link->calc_score($studentId, null);
$linkweight = $link->get_weight();
$link_res_denom = $linkres[1] == 0 ? 1 : $linkres[1];
$ressum = $linkres[0] / $link_res_denom * $linkweight;
if (!isset($totalScorePerStudent[$studentId])) {
$totalScorePerStudent[$studentId] = 0;
}
$totalScorePerStudent[$studentId] += $ressum;
}
}
} else {
/** @var EvalLink|ExerciseLink $link */
foreach ($links as $link) {
$link->setStudentList($this->getStudentList());
@ -1067,15 +1100,13 @@ class Category implements GradebookItem
}
$linkres = $link->calc_score($stud_id, $type);
if (!empty($linkres) && $link->get_weight() != 0) {
$students[$stud_id] = $linkres[0];
$linkweight = $link->get_weight();
$link_res_denom = $linkres[1] == 0 ? 1 : $linkres[1];
$count++;
$weightsum += $linkweight;
$ressum += $linkres[0] / $link_res_denom * $linkweight;
if ($ressum > $bestResult) {
$bestResult = $ressum;
}
@ -1089,9 +1120,14 @@ class Category implements GradebookItem
}
}
}
}
switch ($type) {
case 'best':
arsort($totalScorePerStudent);
$maxScore = current($totalScorePerStudent);
return [$maxScore, $this->get_weight()];
if (empty($bestResult)) {
if ($cacheAvailable) {
$cacheDriver->save($key, null);

@ -204,10 +204,6 @@ class ExerciseLink extends AbstractLink
break;
case 'ranking':
return [null, null];
/*
$newList = [];
$ranking = AbstractLink::getCurrentUserRanking($stud_id, $link->getUserScoreList());
return $ranking;*/
break;
default:
if (!empty($stud_id)) {

@ -457,7 +457,6 @@ class GradebookTable extends SortableTable
}
$category_weight = $item->get_weight();
$mainCategoryWeight = $main_cat[0]->get_weight();
if ($this->teacherView) {
$weight_total_links += $data[3];
@ -472,12 +471,10 @@ class GradebookTable extends SortableTable
}
} else {
$score = $item->calc_score($this->userId);
$scoreToDisplay = '-';
if (!empty($score[1])) {
$completeScore = $scoredisplay->display_score($score, SCORE_DIV_PERCENT);
$score = $score[0] / $score[1] * $item->get_weight();
$score = $scoredisplay->display_score([$score, null], SCORE_SIMPLE);
$scoreToDisplay = Display::tip($score, $completeScore);
} else {
$categoryScore = null;
}
@ -493,9 +490,6 @@ class GradebookTable extends SortableTable
$data['result_score'][1],
];
$totalUserResult[0] += $totalResult[0] / ($totalResult[1] ?: 1) * $data[3];
$totalUserResult[1] += $data[3];
if (empty($model)) {
$totalBest = [
$scoredisplay->format_score($totalBest[0] + $data['best_score'][0]),
@ -521,7 +515,6 @@ class GradebookTable extends SortableTable
$mode = SCORE_AVERAGE;
if ($userExerciseScoreInCategory) {
$mode = SCORE_SIMPLE;
$result = ExerciseLib::convertScoreToPlatformSetting($totalAverage[0], $totalAverage[1]);
$totalAverage[0] = $result['score'];
$totalAverage[1] = $result['weight'];
@ -808,6 +801,10 @@ class GradebookTable extends SortableTable
if (isset($defaultData[$categoryId]) && isset($defaultData[$categoryId]['ranking'])) {
$totalRanking = $defaultData[$categoryId]['ranking'];
$invalidateRanking = $defaultData[$categoryId]['ranking_invalidate'];
$average = 0;
foreach ($totalRanking as $ranking) {
$average += $ranking;
}
} else {
$totalRanking = [];
$invalidateRanking = true;
@ -817,8 +814,8 @@ class GradebookTable extends SortableTable
$score = $main_cat[0]->calc_score(
$student['user_id'],
null,
api_get_course_id(),
api_get_session_id()
$course_code,
$session_id
);
if (!empty($score[0])) {
$invalidateRanking = false;

@ -137,22 +137,6 @@ class FlatViewDataGenerator
$mainCategoryId = $mainCourseCategory->get_id();
}
if (isset($this->category) && !empty($this->category)) {
$categories = Category::load(
null,
null,
null,
$this->category->get_id()
);
if (!empty($categories)) {
foreach ($categories as $category) {
$sum_categories_weight_array[$category->get_id()] = $category->get_weight();
}
} else {
$sum_categories_weight_array[$this->category->get_id()] = $this->category->get_weight();
}
}
// No category was added
$course_code = api_get_course_id();
$session_id = api_get_session_id();
@ -567,8 +551,6 @@ class FlatViewDataGenerator
$show_all,
$row
);
$item_total += $result['item_total'];
$item_value_total += $result['item_value_total'];
$evaluationsAdded = $result['evaluations_added'];
$item_total = $main_weight;
@ -589,7 +571,6 @@ class FlatViewDataGenerator
$item_total += $result['item_total'];
$item_value_total += $result['item_value_total'];
$total_score = [$item_value_total, $item_total];
$style = api_get_configuration_value('gradebook_report_score_style');
if (!$show_all) {
@ -651,7 +632,6 @@ class FlatViewDataGenerator
$item_total = 0;
$item_value_total = 0;
$evaluationsAdded = [];
$model = ExerciseLib::getCourseScoreModel();
for ($count = 0; $count < $items_count && ($items_start + $count < count($this->evals_links)); $count++) {
/** @var AbstractLink $item */
@ -692,7 +672,6 @@ class FlatViewDataGenerator
} else {
$item_value = $score[0] / $divide * $item->get_weight();
}
$item_total += $item->get_weight();
$style = api_get_configuration_value('gradebook_report_score_style');
@ -728,7 +707,6 @@ class FlatViewDataGenerator
);
$temp_score = Display::tip($temp_score, $complete_score);
}
if (!empty($model)) {
$scoreToShow = '';
if (isset($score[0]) && isset($score[1])) {

Loading…
Cancel
Save