]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-9137 readding GRADE_AGGREGATE_MODE
authorskodak <skodak>
Mon, 18 Jun 2007 15:29:20 +0000 (15:29 +0000)
committerskodak <skodak>
Mon, 18 Jun 2007 15:29:20 +0000 (15:29 +0000)
lib/grade/grade_category.php
lib/gradelib.php

index 94f27c1ea476efc997edfc3aca98ad00f99bcf67..41e491dfaa0837e288a2c28f4c545be53ce143bb 100644 (file)
@@ -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;
index ecbeea04c48d4a0566a8123e25ca3f9b3c4e4535..616927b89da867831c23f30944c55ee8c6f58a42 100644 (file)
@@ -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);