From 1426edacd979a0840dfaa216bcfef5e292b6da7f Mon Sep 17 00:00:00 2001 From: skodak Date: Thu, 15 Nov 2007 22:30:01 +0000 Subject: [PATCH] MDL-12096 new simple weighted mean aggregation type; merged from MOODLE_18_STABLE --- admin/settings/grades.php | 1 + grade/edit/tree/category_form.php | 1 + grade/lib.php | 1 + lang/en_utf8/grades.php | 1 + lib/grade/constants.php | 1 + lib/grade/grade_category.php | 20 +++++++++++++++++++- 6 files changed, 24 insertions(+), 1 deletion(-) diff --git a/admin/settings/grades.php b/admin/settings/grades.php index 74b2fa60e71..32af0dbdd7e 100644 --- a/admin/settings/grades.php +++ b/admin/settings/grades.php @@ -61,6 +61,7 @@ $options = array(GRADE_AGGREGATE_MEAN =>get_string('aggregatemean', ' GRADE_AGGREGATE_MAX =>get_string('aggregatemax', 'grades'), GRADE_AGGREGATE_MODE =>get_string('aggregatemode', 'grades'), GRADE_AGGREGATE_WEIGHTED_MEAN =>get_string('aggregateweightedmean', 'grades'), + GRADE_AGGREGATE_WEIGHTED_MEAN2 =>get_string('aggregateweightedmean2', 'grades'), GRADE_AGGREGATE_EXTRACREDIT_MEAN=>get_string('aggregateextracreditmean', 'grades'), GRADE_AGGREGATE_SUM =>get_string('aggregatesum', 'grades')); $defaults = array('value'=>GRADE_AGGREGATE_MEAN, 'forced'=>false, 'adv'=>false); diff --git a/grade/edit/tree/category_form.php b/grade/edit/tree/category_form.php index 0a7391809bc..050415db17c 100644 --- a/grade/edit/tree/category_form.php +++ b/grade/edit/tree/category_form.php @@ -37,6 +37,7 @@ class edit_category_form extends moodleform { GRADE_AGGREGATE_MAX =>get_string('aggregatemax', 'grades'), GRADE_AGGREGATE_MODE =>get_string('aggregatemode', 'grades'), GRADE_AGGREGATE_WEIGHTED_MEAN =>get_string('aggregateweightedmean', 'grades'), + GRADE_AGGREGATE_WEIGHTED_MEAN2 =>get_string('aggregateweightedmean2', 'grades'), GRADE_AGGREGATE_EXTRACREDIT_MEAN=>get_string('aggregateextracreditmean', 'grades'), GRADE_AGGREGATE_SUM =>get_string('aggregatesum', 'grades')); diff --git a/grade/lib.php b/grade/lib.php index 321558a075b..899af8e9fb7 100644 --- a/grade/lib.php +++ b/grade/lib.php @@ -738,6 +738,7 @@ class grade_structure { case GRADE_AGGREGATE_MEAN: case GRADE_AGGREGATE_MEDIAN: case GRADE_AGGREGATE_WEIGHTED_MEAN: + case GRADE_AGGREGATE_WEIGHTED_MEAN2: case GRADE_AGGREGATE_EXTRACREDIT_MEAN: return ''.get_string('aggregation', 'grades').''; case GRADE_AGGREGATE_SUM: diff --git a/lang/en_utf8/grades.php b/lang/en_utf8/grades.php index b4e447575d5..bdd5351e428 100644 --- a/lang/en_utf8/grades.php +++ b/lang/en_utf8/grades.php @@ -26,6 +26,7 @@ $string['aggregatesubcatshelp'] = 'The aggregation is usually done only with imm $string['aggregatesum'] = 'Sum of grades'; $string['aggregatesonly'] = 'Aggregates only'; $string['aggregateweightedmean'] = 'Weighted mean of grades'; +$string['aggregateweightedmean2'] = 'Simple weighted mean of grades'; $string['aggregation'] = 'Aggregation'; $string['aggregationcoef'] = 'Aggregation coefficient'; $string['aggregationcoefextra'] = 'Extra credit'; diff --git a/lib/grade/constants.php b/lib/grade/constants.php index b35a45c02d2..6852a1e5d4c 100644 --- a/lib/grade/constants.php +++ b/lib/grade/constants.php @@ -39,6 +39,7 @@ define('GRADE_AGGREGATE_MIN', 4); define('GRADE_AGGREGATE_MAX', 6); define('GRADE_AGGREGATE_MODE', 8); define('GRADE_AGGREGATE_WEIGHTED_MEAN', 10); +define('GRADE_AGGREGATE_WEIGHTED_MEAN2', 11); define('GRADE_AGGREGATE_EXTRACREDIT_MEAN', 12); define('GRADE_AGGREGATE_SUM', 13); diff --git a/lib/grade/grade_category.php b/lib/grade/grade_category.php index e3ff22d124f..68a2cdba543 100644 --- a/lib/grade/grade_category.php +++ b/lib/grade/grade_category.php @@ -605,7 +605,7 @@ class grade_category extends grade_object { $agg_grade = reset($modes); break; - case GRADE_AGGREGATE_WEIGHTED_MEAN: // Weighted average of all existing final grades + case GRADE_AGGREGATE_WEIGHTED_MEAN: // Weighted average of all existing final grades, weight specified in coef $weightsum = 0; $sum = 0; foreach($grade_values as $itemid=>$grade_value) { @@ -622,6 +622,24 @@ class grade_category extends grade_object { } break; + case GRADE_AGGREGATE_WEIGHTED_MEAN2: // Weighted average of all existing final grades, weight is the range of grade (ususally grademax) + $weightsum = 0; + $sum = 0; + foreach($grade_values as $itemid=>$grade_value) { + $weight = $items[$itemid]->grademax - $items[$itemid]->grademin; + if ($weight <= 0) { + continue; + } + $weightsum += $weight; + $sum += $weight * $grade_value; + } + if ($weightsum == 0) { + $agg_grade = null; + } else { + $agg_grade = $sum / $weightsum; + } + break; + case GRADE_AGGREGATE_EXTRACREDIT_MEAN: // special average $num = 0; $sum = 0;