MDL-12096 new simple weighted mean aggregation type; merged from MOODLE_18_STABLE

This commit is contained in:
skodak 2007-11-15 22:30:01 +00:00
parent 3d5c00b344
commit 1426edacd9
6 changed files with 24 additions and 1 deletions

View File

@ -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);

View File

@ -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'));

View File

@ -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 '<img src="'.$CFG->pixpath.'/i/agg_mean.gif" class="icon itemicon" alt="'.get_string('aggregation', 'grades').'"/>';
case GRADE_AGGREGATE_SUM:

View File

@ -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';

View File

@ -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);

View File

@ -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;