Skip to content

Commit

Permalink
MDL-48239 gradebook: Change to calculated grade item min and max.
Browse files Browse the repository at this point in the history
Regardless of the setting 'Min and max grades used in calculation'
Calculated grade items will always update the min and max raw grade.
  • Loading branch information
abgreeve committed Jul 2, 2015
1 parent 9b84c81 commit 5ab9f04
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 25 deletions.
10 changes: 5 additions & 5 deletions grade/tests/behat/grade_calculated_grade_items.feature
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ Feature: Calculated grade items can be used in the gradebook
And the following should exist in the "user-grade" table:
| Grade item | Calculated weight | Grade | Range | Percentage | Contribution to course total |
| grade item 1 | - | 75.00 | 0100 | 75.00 % | - |
| Calc cat totalInclude empty grades. | 100.00 % | 37.50 | 050 | 75.00 % | - |
| Course total | - | 37.50 | 050 | 75.00 % | - |
| Calc cat totalInclude empty grades. | 100.00 % | 37.50 | 040 | 93.75 % | - |
| Course total | - | 37.50 | 040 | 93.75 % | - |
And I select "Student 2" from the "Select all or one user" singleselect
And the following should exist in the "user-grade" table:
| Grade item | Calculated weight | Grade | Range | Percentage | Contribution to course total |
Expand Down Expand Up @@ -153,9 +153,9 @@ Feature: Calculated grade items can be used in the gradebook
And I select "Student 1" from the "Select all or one user" singleselect
And the following should exist in the "user-grade" table:
| Grade item | Calculated weight | Grade | Range | Percentage | Contribution to course total |
| grade item 1 | 66.67 % | 75.00 | 0100 | 75.00 % | 50.00 % |
| calc item | 33.33 % | 37.50 | 050 | 75.00 % | 25.00 % |
| Course total | - | 112.50 | 0150 | 75.00 % | - |
| grade item 1 | 71.43 % | 75.00 | 0100 | 75.00 % | 53.57 % |
| calc item | 28.57 % | 37.50 | 040 | 93.75 % | 26.79 % |
| Course total | - | 112.50 | 0140 | 80.36 % | - |
And I select "Student 2" from the "Select all or one user" singleselect
And the following should exist in the "user-grade" table:
| Grade item | Calculated weight | Grade | Range | Percentage | Contribution to course total |
Expand Down
24 changes: 12 additions & 12 deletions grade/tests/behat/grade_minmax.feature
Original file line number Diff line number Diff line change
Expand Up @@ -148,20 +148,20 @@ Feature: We can choose what min or max grade to use when aggregating grades.
And I select "Student 1" from the "Select all or one user" singleselect
Then the following should exist in the "user-grade" table:
| Grade item | Calculated weight | Grade | Range | Percentage | Contribution to course total |
| MI 1 | 20.00 % | 75.00 | 0100 | 75.00 % | 15.00 % |
| MI 2 | 20.00 % | 25.00 | 0100 | 25.00 % | 5.00 % |
| MI 3 | 50.00 % | 50.00 | 0100 | 50.00 % | 10.00 % |
| MI 4 | 50.00 % | 100.00 | 0100 | 100.00 % | 20.00 % |
| MI 5 | 20.00 % | 150.00 | 0100 | 100.00 % | 30.00 % |
| CAT1 total | 40.00 % | 150.00 | 0200 | 75.00 % | - |
| Course total | - | 400.00 | 0500 | 80.00 % | - |
| MI 1 | 16.67 % | 75.00 | 0100 | 75.00 % | 12.50 % |
| MI 2 | 16.67 % | 25.00 | 0100 | 25.00 % | 4.17 % |
| MI 3 | 50.00 % | 50.00 | 0100 | 50.00 % | 8.33 % |
| MI 4 | 50.00 % | 100.00 | 0100 | 100.00 % | 16.67 % |
| MI 5 | 33.33 % | 150.00 | 0200 | 75.00 % | 25.00 % |
| CAT1 total | 33.33 % | 150.00 | 0200 | 75.00 % | - |
| Course total | - | 400.00 | 0600 | 66.67 % | - |
And I select "Student 2" from the "Select all or one user" singleselect
And the following should exist in the "user-grade" table:
| Grade item | Calculated weight | Grade | Range | Percentage | Contribution to course total |
| MI 1 | 33.33 % | 20.00 | 0100 | 20.00 % | 6.67 % |
| MI 1 | 25.00 % | 20.00 | 0100 | 20.00 % | 5.00 % |
| MI 2 | 0.00 % | - | 0100 | - | 0.00 % |
| MI 3 | 100.00 % | 10.00 | 0100 | 10.00 % | 3.33 % |
| MI 3 | 100.00 % | 10.00 | 0100 | 10.00 % | 2.50 % |
| MI 4 | 0.00 % | - | 0100 | - | 0.00 % |
| MI 5 | 33.33 % | 30.00 | 0100 | 30.00 % | 10.00 % |
| CAT1 total | 33.33 % | 10.00 | 0100 | 10.00 % | - |
| Course total | - | 60.00 | 0300 | 20.00 % | - |
| MI 5 | 50.00 % | 30.00 | 0200 | 15.00 % | 7.50 % |
| CAT1 total | 25.00 % | 10.00 | 0100 | 10.00 % | - |
| Course total | - | 60.00 | 0400 | 15.00 % | - |
29 changes: 21 additions & 8 deletions lib/grade/grade_item.php
Original file line number Diff line number Diff line change
Expand Up @@ -2013,17 +2013,30 @@ public function use_formula($userid, $params, $useditems, $oldgrade) {
// normalize
$grade->finalgrade = $this->bounded_grade($result);
}

}

// update in db if changed
if (grade_floats_different($grade->finalgrade, $oldfinalgrade)) {
$grade->timemodified = time();
$success = $grade->update('compute');
// Only run through this code if the gradebook isn't frozen.
if ($gradebookcalculationsfreeze && (int)$gradebookcalculationsfreeze <= 20150627) {
// Update in db if changed.
if (grade_floats_different($grade->finalgrade, $oldfinalgrade)) {
$grade->timemodified = time();
$success = $grade->update('compute');

// If successful trigger a user_graded event.
if ($success) {
\core\event\user_graded::create_from_grade($grade)->trigger();
// If successful trigger a user_graded event.
if ($success) {
\core\event\user_graded::create_from_grade($grade)->trigger();
}
}
} else {
// Update in db if changed.
if (grade_floats_different($grade->finalgrade, $oldfinalgrade) || $rawminandmaxchanged) {
$grade->timemodified = time();
$success = $grade->update('compute');

// If successful trigger a user_graded event.
if ($success) {
\core\event\user_graded::create_from_grade($grade)->trigger();
}
}
}

Expand Down

0 comments on commit 5ab9f04

Please sign in to comment.