Permalink
Browse files

MDL-42494 Fix workshop coding exception if all assessments have zero …

…weight

If all assessments for the given submission have zero weight, the grading
evaluation plugin "Comparison with the best assessment" is unable to decide on
the average assessment as it ignores those with zero weight. In such rare case,
it makes sense to set the grading grade to null and prevent the coding
exception.
  • Loading branch information...
1 parent b6ced2f commit 1cdd43b12b8f0bc7f154c65e354d9dd109de4ce1 @mudrd8mz mudrd8mz committed Oct 23, 2013
Showing with 12 additions and 0 deletions.
  1. +12 −0 mod/workshop/eval/best/lib.php
View
12 mod/workshop/eval/best/lib.php
@@ -163,6 +163,16 @@ protected function process_assessments(array $assessments, array $diminfo, stdcl
// get a hypothetical average assessment
$average = $this->average_assessment($assessments);
+ // if unable to calculate the average assessment, set the grading grades to null
+ if (is_null($average)) {
+ foreach ($assessments as $asid => $assessment) {
+ if (!is_null($assessment->gradinggrade)) {
+ $DB->set_field('workshop_assessments', 'gradinggrade', null, array('id' => $asid));
+ }
+ }
+ return;
+ }
+
// calculate variance of dimension grades
$variances = $this->weighted_variance($assessments);
foreach ($variances as $dimid => $variance) {
@@ -272,6 +282,8 @@ protected function normalize_grades(array $assessments, array $diminfo) {
* Given a set of a submission's assessments, returns a hypothetical average assessment
*
* The passed structure must be array of assessments objects with ->weight and ->dimgrades properties.
+ * Returns null if all passed assessments have zero weight as there is nothing to choose
+ * from then.
*
* @param array $assessments as prepared by {@link self::prepare_data_from_recordset()}
* @return null|stdClass

0 comments on commit 1cdd43b

Please sign in to comment.