From: skodak Date: Mon, 18 Jun 2007 15:29:20 +0000 (+0000) Subject: MDL-9137 readding GRADE_AGGREGATE_MODE X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=95affb8a35e5cf98d944a6e451cd75f6afb3b982;p=moodle.git MDL-9137 readding GRADE_AGGREGATE_MODE --- diff --git a/lib/grade/grade_category.php b/lib/grade/grade_category.php index 94f27c1ea4..41e491dfaa 100644 --- a/lib/grade/grade_category.php +++ b/lib/grade/grade_category.php @@ -448,13 +448,21 @@ class grade_category extends grade_object { $gradevalue = array_pop($grades); break; - case GRADE_AGGREGATE_MEAN_ALL: // Arithmetic average of all grade items including event NULLs; NULL grade caunted as minimum - $num = count($dependson); // you can calculate sum from this one if you multiply it with count($this->dependson();-) + case GRADE_AGGREGATE_MEAN_ALL: // Arithmetic average of all grade items including even NULLs; NULL grade caunted as minimum + $num = count($dependson); // you can calculate sum from this one if you multiply it with count($this->dependson() ;-) $sum = array_sum($grades); $gradevalue = $sum / $num; break; - case GRADE_AGGREGATE_MEAN_GRADED: // Arithmetic average of all final grades, unfinished not calculated + case GRADE_AGGREGATE_MODE: // the most common value, the highest one if multimode + $freq = array_count_values($grades); + arsort($freq); // sort by frequency keeping keys + $top = reset($freq); // highest frequency count + $modes = array_keys($freq, $top); // search for all modes (have the same highest count) + rsort($modes, SORT_NUMERIC); // get highes mode + $gradevalue = reset($modes); + + case GRADE_AGGREGATE_MEAN_GRADED: // Arithmetic average of all final grades, unfinished are not calculated $num = count($grades); $sum = array_sum($grades); $gradevalue = $sum / $num; diff --git a/lib/gradelib.php b/lib/gradelib.php index ecbeea04c4..616927b89d 100644 --- a/lib/gradelib.php +++ b/lib/gradelib.php @@ -37,6 +37,7 @@ define('GRADE_AGGREGATE_MEDIAN', 1); define('GRADE_AGGREGATE_MEAN_GRADED', 2); define('GRADE_AGGREGATE_MIN', 3); define('GRADE_AGGREGATE_MAX', 4); +define('GRADE_AGGREGATE_MODE', 5); define('GRADE_CHILDTYPE_ITEM', 0); define('GRADE_CHILDTYPE_CAT', 1);