Skip to content

Commit

Permalink
MDL-12942 new extra credit option for simple mean agg
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Apr 24, 2009
1 parent 0b3f171 commit 4ea98f4
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 10 deletions.
8 changes: 7 additions & 1 deletion grade/edit/tree/category.php
Expand Up @@ -58,7 +58,13 @@
// set parent
$category->parentcategory = $grade_category->parent;
$grade_item = $grade_category->load_grade_item();
foreach ($grade_item as $key => $value) {
// nomalize coef values if needed
if ($parent_category = $grade_category->get_parent_category()) {
if ($parent_category->aggregation == GRADE_AGGREGATE_SUM or $parent_category->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN2) {
$grade_item->aggregationcoef = $grade_item->aggregationcoef == 0 ? 0 : 1;
}
}
foreach ($grade_item->get_record_data() as $key => $value) {
$category->{"grade_item_$key"} = $value;
}

Expand Down
4 changes: 2 additions & 2 deletions grade/edit/tree/item.php
Expand Up @@ -96,8 +96,8 @@

if (empty($parent_category)) {
$item->aggregationcoef = 0;
} else if ($parent_category->aggregation == GRADE_AGGREGATE_SUM) {
$item->aggregationcoef = $item->aggregationcoef > 0 ? 1 : 0;
} else if ($parent_category->aggregation == GRADE_AGGREGATE_SUM or $parent_category->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN2) {
$item->aggregationcoef = $item->aggregationcoef == 0 ? 0 : 1;
} else {
$item->aggregationcoef = format_float($item->aggregationcoef, 4);
}
Expand Down
2 changes: 1 addition & 1 deletion grade/edit/tree/lib.php
Expand Up @@ -566,7 +566,7 @@ function get_category_cell($category, $levelclass, $params) {
}

$script = "window.location='index.php?id={$params['id']}&category={$category->id}&aggregationtype='+this.value+'&sesskey=" . sesskey()."';";
$aggregation = choose_from_menu($options, 'aggregation_'.$category->id, $category->aggregation, get_string('choose'), $script, 0, true);
$aggregation = choose_from_menu($options, 'aggregation_'.$category->id, $category->aggregation, null, $script, 0, true);

if ($this->forced) {
$aggregation = $options[$category->aggregation];
Expand Down
6 changes: 6 additions & 0 deletions grade/edit/tree/outcomeitem_form.php
Expand Up @@ -102,6 +102,9 @@ function definition() {
if ($cat->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN) {
$coefstring = ($coefstring=='' or $coefstring=='aggregationcoefweight') ? 'aggregationcoefweight' : 'aggregationcoef';

} else if ($cat->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN2) {
$coefstring = ($coefstring=='' or $coefstring=='aggregationcoefextrasum') ? 'aggregationcoefextrasum' : 'aggregationcoef';

} else if ($cat->aggregation == GRADE_AGGREGATE_EXTRACREDIT_MEAN) {
$coefstring = ($coefstring=='' or $coefstring=='aggregationcoefextra') ? 'aggregationcoefextra' : 'aggregationcoef';

Expand Down Expand Up @@ -201,6 +204,9 @@ function definition_after_data() {
if ($parent_category->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN) {
$aggcoef = 'aggregationcoefweight';

} else if ($parent_category->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN2) {
$aggcoef = 'aggregationcoefextrasum';

} else if ($parent_category->aggregation == GRADE_AGGREGATE_EXTRACREDIT_MEAN) {
$aggcoef = 'aggregationcoefextra';

Expand Down
19 changes: 13 additions & 6 deletions lib/grade/grade_category.php
Expand Up @@ -642,27 +642,31 @@ function aggregate_values($grade_values, $items) {
}
break;

case GRADE_AGGREGATE_WEIGHTED_MEAN2: // Weighted average of all existing final grades, weight is the range of grade (ususally grademax)
case GRADE_AGGREGATE_WEIGHTED_MEAN2:
// Weighted average of all existing final grades with optional extra credit flag,
// weight is the range of grade (ususally grademax)
$weightsum = 0;
$sum = 0;
$sum = null;
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 ($items[$itemid]->aggregationcoef == 0) {
$weightsum += $weight;
}
$sum += $weight * $grade_value;
}
if ($weightsum == 0) {
$agg_grade = null;
$agg_grade = $sum; // only extra credits
} else {
$agg_grade = $sum / $weightsum;
}
break;

case GRADE_AGGREGATE_EXTRACREDIT_MEAN: // special average
$num = 0;
$sum = 0;
$sum = null;
foreach($grade_values as $itemid=>$grade_value) {
if ($items[$itemid]->aggregationcoef == 0) {
$num += 1;
Expand Down Expand Up @@ -806,6 +810,7 @@ function apply_limit_rules(&$grade_values) {
*/
function is_aggregationcoef_used() {
return ($this->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN
or $this->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN2
or $this->aggregation == GRADE_AGGREGATE_EXTRACREDIT_MEAN
or $this->aggregation == GRADE_AGGREGATE_SUM);

Expand Down Expand Up @@ -847,6 +852,8 @@ function get_coefstring($first=true) {
// No parent category is overriding this category's aggregation, return its string
if ($this->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN) {
$this->coefstring = 'aggregationcoefweight';
} else if ($this->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN2) {
$this->coefstring = 'aggregationcoefextrasum';
} else if ($this->aggregation == GRADE_AGGREGATE_EXTRACREDIT_MEAN) {
$this->coefstring = 'aggregationcoefextra';
} else if ($this->aggregation == GRADE_AGGREGATE_SUM) {
Expand Down

0 comments on commit 4ea98f4

Please sign in to comment.