Merge branch 'wip-MDL-49257-master' of git://github.com/marinaglancy/moodle

This commit is contained in:
Dan Poltawski 2015-06-23 11:20:08 +01:00
commit 20a16512ee
15 changed files with 935 additions and 13 deletions

View File

@ -999,6 +999,13 @@ class backup_gradebook_structure_step extends backup_structure_step {
$gradebook->add_child($grade_settings);
$grade_settings->add_child($grade_setting);
// Add attribute with gradebook calculation freeze date if needed.
$gradebookcalculationfreeze = get_config('core', 'gradebook_calculations_freeze_' . $this->get_courseid());
if ($gradebookcalculationfreeze) {
$gradebook->add_attributes(array('calculations_freeze'));
$gradebook->get_attribute('calculations_freeze')->set_value($gradebookcalculationfreeze);
}
// Define sources
//Include manual, category and the course grade item

View File

@ -142,6 +142,18 @@ class restore_gradebook_structure_step extends restore_structure_step {
}
protected function process_gradebook($data) {
// For non-merge restore types:
// Unset 'gradebook_calculations_freeze_' in the course and replace with the one from the backup.
$target = $this->get_task()->get_target();
if ($target == backup::TARGET_CURRENT_DELETING || $target == backup::TARGET_EXISTING_DELETING) {
set_config('gradebook_calculations_freeze_' . $this->get_courseid(), null);
}
if (!empty($data['calculations_freeze']) && $this->get_task()->get_target() == backup::TARGET_NEW_COURSE) {
if ($target == backup::TARGET_NEW_COURSE || $target == backup::TARGET_CURRENT_DELETING ||
$target == backup::TARGET_EXISTING_DELETING) {
set_config('gradebook_calculations_freeze_' . $this->get_courseid(), $data['calculations_freeze']);
}
}
}
protected function process_grade_item($data) {
@ -451,9 +463,30 @@ class restore_gradebook_structure_step extends restore_structure_step {
}
$rs->close();
// Freeze gradebook calculations if needed.
$this->gradebook_calculation_freeze();
// Restore marks items as needing update. Update everything now.
grade_regrade_final_grades($this->get_courseid());
}
/**
* Freeze gradebook calculation if needed.
*
* This is similar to various upgrade scripts that check if the freeze is needed.
*/
protected function gradebook_calculation_freeze() {
global $CFG;
$gradebookcalculationsfreeze = get_config('core', 'gradebook_calculations_freeze_' . $this->get_courseid());
preg_match('/(\d{8})/', $this->get_task()->get_info()->moodle_release, $matches);
$backupbuild = (int)$matches[1];
// Extra credits need adjustments only for backups made between 2.8 release (20141110) and the fix release (20150619).
if (!$gradebookcalculationsfreeze && $backupbuild >= 20141110 && $backupbuild < 20150619) {
require_once($CFG->libdir . '/db/upgradelib.php');
upgrade_extra_credit_weightoverride($this->get_courseid());
}
}
}
/**

View File

@ -515,6 +515,15 @@ function hide_aggregatesubcats_upgrade_notice($courseid) {
unset_config('show_aggregatesubcats_upgrade_' . $courseid);
}
/**
* Hide warning about changed grades due to bug fixes
*
* @param int $courseid The current course id.
*/
function hide_gradebook_calculations_freeze_notice($courseid) {
unset_config('gradebook_calculations_freeze_' . $courseid);
}
/**
* Print warning about changed grades during upgrade to 2.8.
*
@ -547,6 +556,9 @@ function print_natural_aggregation_upgrade_notice($courseid, $context, $thispage
$minmaxtouse = grade_get_setting($courseid, 'minmaxtouse', $CFG->grade_minmaxtouse);
$gradebookcalculationsfreeze = get_config('core', 'gradebook_calculations_freeze_' . $courseid);
$acceptgradebookchanges = optional_param('acceptgradebookchanges', false, PARAM_BOOL) && confirm_sesskey();
// Hide the warning if the user told it to go away.
if ($hidenaturalwarning) {
hide_natural_aggregation_upgrade_notice($courseid);
@ -641,6 +653,39 @@ function print_natural_aggregation_upgrade_notice($courseid, $context, $thispage
}
}
if ($gradebookcalculationsfreeze) {
if ($acceptgradebookchanges) {
// Accept potential changes in grades caused by extra credit bug MDL-49257.
hide_gradebook_calculations_freeze_notice($courseid);
$courseitem = grade_item::fetch_course_item($courseid);
$courseitem->force_regrading();
grade_regrade_final_grades($courseid);
$html .= $OUTPUT->notification(get_string('gradebookcalculationsuptodate', 'grades'), 'notifysuccess');
} else {
// Show the warning that there may be extra credit weights problems.
$a = new stdClass();
$a->gradebookversion = $gradebookcalculationsfreeze;
if (preg_match('/(\d{8,})/', $CFG->release, $matches)) {
$a->currentversion = $matches[1];
} else {
$a->currentversion = $CFG->release;
}
$a->url = get_docs_url('Gradebook_calculations_changes');
$message = get_string('gradebookcalculationswarning', 'grades', $a);
$fixmessage = get_string('gradebookcalculationsfixbutton', 'grades');
$urlparams = array('id' => $courseid,
'acceptgradebookchanges' => true,
'sesskey' => sesskey());
$fixurl = new moodle_url($thispage, $urlparams);
$fixbutton = $OUTPUT->single_button($fixurl, $fixmessage, 'get');
$html .= $OUTPUT->notification($message, 'notifywarning');
$html .= $fixbutton;
}
}
if (!empty($html)) {
$html = html_writer::tag('div', $html, array('class' => 'core_grades_notices'));
}

View File

@ -158,4 +158,18 @@ class behat_grade extends behat_base {
$steps[] = new Given('I click on "' . $this->escape($linktext) . '" "link"');
return $steps;
}
/**
* Step allowing to test before-the-fix behaviour of the gradebook
*
* @Given /^gradebook calculations for the course "(?P<coursename_string>(?:[^"]|\\")*)" are frozen at version "(?P<version_string>(?:[^"]|\\")*)"$/
* @param string $coursename
* @param string $version
* @return Given
*/
public function gradebook_calculations_for_the_course_are_frozen_at_version($coursename, $version) {
global $DB;
$courseid = $DB->get_field('course', 'id', array('shortname' => $coursename), MUST_EXIST);
set_config('gradebook_calculations_freeze_' . $courseid, $version);
}
}

View File

@ -0,0 +1,270 @@
@core @core_grades
Feature: Weights in natural aggregation are adjusted if the items are excluded from user report
In order to correctly display user report
As a teacher
I need to be able to exclude hidden grades.
Background:
Given the following "courses" exist:
| fullname | shortname | category | groupmode |
| Course 1 | C1 | 0 | 1 |
And the following "users" exist:
| username | firstname | lastname | email | idnumber |
| teacher1 | Teacher | 1 | teacher1@example.com | t1 |
| student1 | Student | 1 | student1@example.com | s1 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
And the following "activities" exist:
| activity | course | idnumber | name | intro | grade |
| assign | C1 | a1 | Test assignment one | x | 100 |
| assign | C1 | a2 | Test assignment two | x | 50 |
| assign | C1 | a3 | Test assignment three | x | 200 |
| assign | C1 | a4 | Test assignment four (extra) | x | 20 |
| assign | C1 | a5 | Test assignment five (extra) | x | 10 |
And I log in as "teacher1"
And I follow "Course 1"
And I navigate to "Grades" node in "Course administration"
And I set the field "Grade report" to "Categories and items"
And I set the following settings for grade item "Test assignment four (extra)":
| Extra credit | 1 |
And I set the following settings for grade item "Test assignment five (extra)":
| Extra credit | 1 |
@javascript
Scenario: No weights are overridden and student has all grades present
When I navigate to "Grades" node in "Course administration"
And I turn editing mode on
And I give the grade "80.00" to the user "Student 1" for the grade item "Test assignment one"
And I give the grade "30.00" to the user "Student 1" for the grade item "Test assignment two"
And I give the grade "150.00" to the user "Student 1" for the grade item "Test assignment three"
And I give the grade "10.00" to the user "Student 1" for the grade item "Test assignment four (extra)"
And I give the grade "8.00" to the user "Student 1" for the grade item "Test assignment five (extra)"
And I press "Save changes"
And I set the field "Grade report" to "User report"
And I set the field "Select all or one user" to "Student 1"
Then the following should exist in the "user-grade" table:
| Grade item | Calculated weight | Grade | Range | Percentage | Contribution to course total |
| Test assignment one | 28.57 % | 80.00 | 0100 | 80.00 % | 22.86 % |
| Test assignment two | 14.29 % | 30.00 | 050 | 60.00 % | 8.57 % |
| Test assignment three | 57.14 % | 150.00 | 0200 | 75.00 % | 42.86 % |
| Test assignment four (extra) | 5.71 %( Extra credit ) | 10.00 | 020 | 50.00 % | 2.86 % |
| Test assignment five (extra) | 2.86 %( Extra credit ) | 8.00 | 010 | 80.00 % | 2.29 % |
| Course total | - | 278.00 | 0350 | 79.43 % | - |
And I log out
@javascript
Scenario: No weights are overridden, student has some grades present
When I navigate to "Grades" node in "Course administration"
And I turn editing mode on
And I give the grade "80.00" to the user "Student 1" for the grade item "Test assignment one"
And I give the grade "30.00" to the user "Student 1" for the grade item "Test assignment two"
And I give the grade "10.00" to the user "Student 1" for the grade item "Test assignment four (extra)"
And I give the grade "8.00" to the user "Student 1" for the grade item "Test assignment five (extra)"
And I press "Save changes"
And I set the field "Grade report" to "User report"
And I set the field "Select all or one user" to "Student 1"
Then the following should exist in the "user-grade" table:
| Grade item | Calculated weight | Grade | Range | Percentage | Contribution to course total |
| Test assignment one | 66.67 % | 80.00 | 0100 | 80.00 % | 53.33 % |
| Test assignment two | 33.33 % | 30.00 | 050 | 60.00 % | 20.00 % |
| Test assignment three | 0.00 %( Empty ) | - | 0200 | - | 0.00 % |
| Test assignment four (extra) | 13.33 %( Extra credit ) | 10.00 | 020 | 50.00 % | 6.67 % |
| Test assignment five (extra) | 6.67 %( Extra credit ) | 8.00 | 010 | 80.00 % | 5.33 % |
| Course total | - | 128.00 | 0150 | 85.33 % | - |
And I log out
@javascript
Scenario: No weights are overridden, student has none grades present except for extra credit
When I navigate to "Grades" node in "Course administration"
And I turn editing mode on
And I give the grade "10.00" to the user "Student 1" for the grade item "Test assignment four (extra)"
And I give the grade "8.00" to the user "Student 1" for the grade item "Test assignment five (extra)"
And I press "Save changes"
And I set the field "Grade report" to "User report"
And I set the field "Select all or one user" to "Student 1"
Then the following should exist in the "user-grade" table:
| Grade item | Calculated weight | Grade | Range | Percentage | Contribution to course total |
| Test assignment one | 0.00 %( Empty ) | - | 0100 | - | 0.00 % |
| Test assignment two | 0.00 %( Empty ) | - | 050 | - | 0.00 % |
| Test assignment three | 0.00 %( Empty ) | - | 0200 | - | 0.00 % |
| Test assignment four (extra) | 0.00 %( Extra credit ) | 10.00 | 020 | 50.00 % | 0.00 % |
| Test assignment five (extra) | 0.00 %( Extra credit ) | 8.00 | 010 | 80.00 % | 0.00 % |
| Course total | - | 0.00 | 00 | | - |
And I log out
@javascript
Scenario: Make sure there are no errors when all items are marked as extra credit
And I set the following settings for grade item "Test assignment one":
| Extra credit | 1 |
And I set the following settings for grade item "Test assignment two":
| Extra credit | 1 |
And I set the following settings for grade item "Test assignment three":
| Extra credit | 1 |
When I navigate to "Grades" node in "Course administration"
And I turn editing mode on
And I give the grade "80.00" to the user "Student 1" for the grade item "Test assignment one"
And I give the grade "30.00" to the user "Student 1" for the grade item "Test assignment two"
And I give the grade "10.00" to the user "Student 1" for the grade item "Test assignment four (extra)"
And I give the grade "8.00" to the user "Student 1" for the grade item "Test assignment five (extra)"
And I press "Save changes"
And I set the field "Grade report" to "User report"
And I set the field "Select all or one user" to "Student 1"
Then the following should exist in the "user-grade" table:
| Grade item | Calculated weight | Grade | Range | Percentage | Contribution to course total |
| Test assignment one | 0.00 %( Extra credit ) | 80.00 | 0100 | 80.00 % | 0.00 % |
| Test assignment two | 0.00 %( Extra credit ) | 30.00 | 050 | 60.00 % | 0.00 % |
| Test assignment three | 0.00 %( Empty ) | - | 0200 | - | 0.00 % |
| Test assignment four (extra) | 0.00 %( Extra credit ) | 10.00 | 020 | 50.00 % | 0.00 % |
| Test assignment five (extra) | 0.00 %( Extra credit ) | 8.00 | 010 | 80.00 % | 0.00 % |
| Course total | - | 0.0 | 00 | | - |
And I log out
@javascript
Scenario: Weights are overridden and student has all grades present
When I set the field "Override weight of Test assignment one" to "1"
And I set the field "Weight of Test assignment one" to "50"
And I press "Save changes"
When I navigate to "Grades" node in "Course administration"
And I turn editing mode on
And I give the grade "80.00" to the user "Student 1" for the grade item "Test assignment one"
And I give the grade "30.00" to the user "Student 1" for the grade item "Test assignment two"
And I give the grade "150.00" to the user "Student 1" for the grade item "Test assignment three"
And I give the grade "10.00" to the user "Student 1" for the grade item "Test assignment four (extra)"
And I give the grade "8.00" to the user "Student 1" for the grade item "Test assignment five (extra)"
And I press "Save changes"
And I set the field "Grade report" to "User report"
And I set the field "Select all or one user" to "Student 1"
Then the following should exist in the "user-grade" table:
| Grade item | Calculated weight | Grade | Range | Percentage | Contribution to course total |
| Test assignment one | 50.00 % | 80.00 | 0100 | 80.00 % | 40.00 % |
| Test assignment two | 10.00 % | 30.00 | 050 | 60.00 % | 6.00 % |
| Test assignment three | 40.00 % | 150.00 | 0200 | 75.00 % | 30.00 % |
| Test assignment four (extra) | 5.71 %( Extra credit ) | 10.00 | 020 | 50.00 % | 2.86 % |
| Test assignment five (extra) | 2.86 %( Extra credit ) | 8.00 | 010 | 80.00 % | 2.29 % |
| Course total | - | 284.00 | 0350 | 81.14 % | - |
And I log out
@javascript
Scenario: Weights are overridden and student has some grades present
When I set the field "Override weight of Test assignment one" to "1"
And I set the field "Weight of Test assignment one" to "50"
And I press "Save changes"
When I navigate to "Grades" node in "Course administration"
And I turn editing mode on
And I give the grade "80.00" to the user "Student 1" for the grade item "Test assignment one"
And I give the grade "30.00" to the user "Student 1" for the grade item "Test assignment two"
And I give the grade "10.00" to the user "Student 1" for the grade item "Test assignment four (extra)"
And I give the grade "8.00" to the user "Student 1" for the grade item "Test assignment five (extra)"
And I press "Save changes"
And I set the field "Grade report" to "User report"
And I set the field "Select all or one user" to "Student 1"
Then the following should exist in the "user-grade" table:
| Grade item | Calculated weight | Grade | Range | Percentage | Contribution to course total |
| Test assignment one | 83.33 % | 80.00 | 0100 | 80.00 % | 66.67 % |
| Test assignment two | 16.67 % | 30.00 | 050 | 60.00 % | 10.00 % |
| Test assignment three | 0.00 %( Empty ) | - | 0200 | - | 0.00 % |
| Test assignment four (extra) | 13.33 %( Extra credit ) | 10.00 | 020 | 50.00 % | 6.67 % |
| Test assignment five (extra) | 6.67 %( Extra credit ) | 8.00 | 010 | 80.00 % | 5.33 % |
| Course total | - | 133.00 | 0150 | 88.67 % | - |
And I log out
@javascript
Scenario: Weights are overridden, student has none grades present except for extra credit
When I set the field "Override weight of Test assignment one" to "1"
And I set the field "Weight of Test assignment one" to "50"
And I press "Save changes"
When I navigate to "Grades" node in "Course administration"
And I turn editing mode on
And I give the grade "10.00" to the user "Student 1" for the grade item "Test assignment four (extra)"
And I give the grade "8.00" to the user "Student 1" for the grade item "Test assignment five (extra)"
And I press "Save changes"
And I set the field "Grade report" to "User report"
And I set the field "Select all or one user" to "Student 1"
Then the following should exist in the "user-grade" table:
| Grade item | Calculated weight | Grade | Range | Percentage | Contribution to course total |
| Test assignment one | 0.00 %( Empty ) | - | 0100 | - | 0.00 % |
| Test assignment two | 0.00 %( Empty ) | - | 050 | - | 0.00 % |
| Test assignment three | 0.00 %( Empty ) | - | 0200 | - | 0.00 % |
| Test assignment four (extra) | 0.00 %( Extra credit ) | 10.00 | 020 | 50.00 % | 0.00 % |
| Test assignment five (extra) | 0.00 %( Extra credit ) | 8.00 | 010 | 80.00 % | 0.00 % |
| Course total | - | 0.00 | 00 | | - |
And I log out
@javascript
Scenario: Weights are overridden, including extra credit, and student has all grades present
When I set the field "Override weight of Test assignment one" to "1"
And I set the field "Weight of Test assignment one" to "50"
And I set the field "Override weight of Test assignment four (extra)" to "1"
And I set the field "Weight of Test assignment four (extra)" to "10"
And I press "Save changes"
When I navigate to "Grades" node in "Course administration"
And I turn editing mode on
And I give the grade "80.00" to the user "Student 1" for the grade item "Test assignment one"
And I give the grade "30.00" to the user "Student 1" for the grade item "Test assignment two"
And I give the grade "150.00" to the user "Student 1" for the grade item "Test assignment three"
And I give the grade "10.00" to the user "Student 1" for the grade item "Test assignment four (extra)"
And I give the grade "8.00" to the user "Student 1" for the grade item "Test assignment five (extra)"
And I press "Save changes"
And I set the field "Grade report" to "User report"
And I set the field "Select all or one user" to "Student 1"
Then the following should exist in the "user-grade" table:
| Grade item | Calculated weight | Grade | Range | Percentage | Contribution to course total |
| Test assignment one | 50.00 % | 80.00 | 0100 | 80.00 % | 40.00 % |
| Test assignment two | 10.00 % | 30.00 | 050 | 60.00 % | 6.00 % |
| Test assignment three | 40.00 % | 150.00 | 0200 | 75.00 % | 30.00 % |
| Test assignment four (extra) | 10.00 %( Extra credit ) | 10.00 | 020 | 50.00 % | 5.00 % |
| Test assignment five (extra) | 2.86 %( Extra credit ) | 8.00 | 010 | 80.00 % | 2.29 % |
| Course total | - | 291.50 | 0350 | 83.29 % | - |
And I log out
@javascript
Scenario: Weights are overridden, including extra credit, and student has some grades present
When I set the field "Override weight of Test assignment one" to "1"
And I set the field "Weight of Test assignment one" to "50"
And I set the field "Override weight of Test assignment four (extra)" to "1"
And I set the field "Weight of Test assignment four (extra)" to "10"
And I press "Save changes"
When I navigate to "Grades" node in "Course administration"
And I turn editing mode on
And I give the grade "80.00" to the user "Student 1" for the grade item "Test assignment one"
And I give the grade "30.00" to the user "Student 1" for the grade item "Test assignment two"
And I give the grade "10.00" to the user "Student 1" for the grade item "Test assignment four (extra)"
And I give the grade "8.00" to the user "Student 1" for the grade item "Test assignment five (extra)"
And I press "Save changes"
And I set the field "Grade report" to "User report"
And I set the field "Select all or one user" to "Student 1"
Then the following should exist in the "user-grade" table:
| Grade item | Calculated weight | Grade | Range | Percentage | Contribution to course total |
| Test assignment one | 83.33 % | 80.00 | 0100 | 80.00 % | 66.67 % |
| Test assignment two | 16.67 % | 30.00 | 050 | 60.00 % | 10.00 % |
| Test assignment three | 0.00 %( Empty ) | - | 0200 | - | 0.00 % |
| Test assignment four (extra) | 16.67 %( Extra credit ) | 10.00 | 020 | 50.00 % | 8.33 % |
| Test assignment five (extra) | 6.67 %( Extra credit ) | 8.00 | 010 | 80.00 % | 5.33 % |
| Course total | - | 135.50 | 0150 | 90.33 % | - |
And I log out
@javascript
Scenario: Weights are overridden, including extra credit, student has none grades present except for extra credit
When I set the field "Override weight of Test assignment one" to "1"
And I set the field "Weight of Test assignment one" to "50"
And I set the field "Override weight of Test assignment four (extra)" to "1"
And I set the field "Weight of Test assignment four (extra)" to "10"
And I press "Save changes"
When I navigate to "Grades" node in "Course administration"
And I turn editing mode on
And I give the grade "10.00" to the user "Student 1" for the grade item "Test assignment four (extra)"
And I give the grade "8.00" to the user "Student 1" for the grade item "Test assignment five (extra)"
And I press "Save changes"
And I set the field "Grade report" to "User report"
And I set the field "Select all or one user" to "Student 1"
Then the following should exist in the "user-grade" table:
| Grade item | Calculated weight | Grade | Range | Percentage | Contribution to course total |
| Test assignment one | 0.00 %( Empty ) | - | 0100 | - | 0.00 % |
| Test assignment two | 0.00 %( Empty ) | - | 050 | - | 0.00 % |
| Test assignment three | 0.00 %( Empty ) | - | 0200 | - | 0.00 % |
| Test assignment four (extra) | 0.00 %( Extra credit ) | 10.00 | 020 | 50.00 % | 0.00 % |
| Test assignment five (extra) | 0.00 %( Extra credit ) | 8.00 | 010 | 80.00 % | 0.00 % |
| Course total | - | 0.00 | 00 | | - |
And I log out

View File

@ -0,0 +1,275 @@
@core @core_grades
Feature: Gradebook calculations for extra credit items before the fix 20150619
In order to make sure the grades are not changed after upgrade
As a teacher
I need to be able to freeze gradebook calculations
Background:
Given the following "courses" exist:
| fullname | shortname | category | groupmode |
| Course 1 | C1 | 0 | 1 |
And gradebook calculations for the course "C1" are frozen at version "20150619"
And the following "users" exist:
| username | firstname | lastname | email | idnumber |
| teacher1 | Teacher | 1 | teacher1@example.com | t1 |
| student1 | Student | 1 | student1@example.com | s1 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
And the following "activities" exist:
| activity | course | idnumber | name | intro | grade |
| assign | C1 | a1 | Test assignment one | x | 100 |
| assign | C1 | a2 | Test assignment two | x | 50 |
| assign | C1 | a3 | Test assignment three | x | 200 |
| assign | C1 | a4 | Test assignment four (extra) | x | 20 |
| assign | C1 | a5 | Test assignment five (extra) | x | 10 |
And I log in as "teacher1"
And I follow "Course 1"
And I navigate to "Grades" node in "Course administration"
And I set the field "Grade report" to "Categories and items"
And I set the following settings for grade item "Test assignment four (extra)":
| Extra credit | 1 |
And I set the following settings for grade item "Test assignment five (extra)":
| Extra credit | 1 |
@javascript
Scenario: No weights are overridden and student has all grades present (before the fix 20150619)
When I navigate to "Grades" node in "Course administration"
And I turn editing mode on
And I give the grade "80.00" to the user "Student 1" for the grade item "Test assignment one"
And I give the grade "30.00" to the user "Student 1" for the grade item "Test assignment two"
And I give the grade "150.00" to the user "Student 1" for the grade item "Test assignment three"
And I give the grade "10.00" to the user "Student 1" for the grade item "Test assignment four (extra)"
And I give the grade "8.00" to the user "Student 1" for the grade item "Test assignment five (extra)"
And I press "Save changes"
And I set the field "Grade report" to "User report"
And I set the field "Select all or one user" to "Student 1"
Then the following should exist in the "user-grade" table:
| Grade item | Calculated weight | Grade | Range | Percentage | Contribution to course total |
| Test assignment one | 28.57 % | 80.00 | 0100 | 80.00 % | 22.86 % |
| Test assignment two | 14.29 % | 30.00 | 050 | 60.00 % | 8.57 % |
| Test assignment three | 57.14 % | 150.00 | 0200 | 75.00 % | 42.86 % |
| Test assignment four (extra) | 5.71 %( Extra credit ) | 10.00 | 020 | 50.00 % | 2.86 % |
| Test assignment five (extra) | 2.86 %( Extra credit ) | 8.00 | 010 | 80.00 % | 2.29 % |
| Course total | - | 278.00 | 0350 | 79.43 % | - |
And I log out
@javascript
Scenario: No weights are overridden, student has some grades present (before the fix 20150619)
When I navigate to "Grades" node in "Course administration"
And I turn editing mode on
And I give the grade "80.00" to the user "Student 1" for the grade item "Test assignment one"
And I give the grade "30.00" to the user "Student 1" for the grade item "Test assignment two"
And I give the grade "10.00" to the user "Student 1" for the grade item "Test assignment four (extra)"
And I give the grade "8.00" to the user "Student 1" for the grade item "Test assignment five (extra)"
And I press "Save changes"
And I set the field "Grade report" to "User report"
And I set the field "Select all or one user" to "Student 1"
Then the following should exist in the "user-grade" table:
| Grade item | Calculated weight | Grade | Range | Percentage | Contribution to course total |
| Test assignment one | 66.67 % | 80.00 | 0100 | 80.00 % | 53.33 % |
| Test assignment two | 33.33 % | 30.00 | 050 | 60.00 % | 20.00 % |
| Test assignment three | 0.00 %( Empty ) | - | 0200 | - | 0.00 % |
| Test assignment four (extra) | 13.33 %( Extra credit ) | 10.00 | 020 | 50.00 % | 6.67 % |
| Test assignment five (extra) | 6.67 %( Extra credit ) | 8.00 | 010 | 80.00 % | 5.33 % |
| Course total | - | 128.00 | 0150 | 85.33 % | - |
And I log out
@javascript
Scenario: No weights are overridden, student has none grades present except for extra credit (before the fix 20150619)
When I navigate to "Grades" node in "Course administration"
And I turn editing mode on
And I give the grade "10.00" to the user "Student 1" for the grade item "Test assignment four (extra)"
And I give the grade "8.00" to the user "Student 1" for the grade item "Test assignment five (extra)"
And I press "Save changes"
And I set the field "Grade report" to "User report"
And I set the field "Select all or one user" to "Student 1"
Then the following should exist in the "user-grade" table:
| Grade item | Calculated weight | Grade | Range | Percentage | Contribution to course total |
| Test assignment one | 0.00 %( Empty ) | - | 0100 | - | 0.00 % |
| Test assignment two | 0.00 %( Empty ) | - | 050 | - | 0.00 % |
| Test assignment three | 0.00 %( Empty ) | - | 0200 | - | 0.00 % |
| Test assignment four (extra) | 0.00 %( Extra credit ) | 10.00 | 020 | 50.00 % | 0.00 % |
| Test assignment five (extra) | 0.00 %( Extra credit ) | 8.00 | 010 | 80.00 % | 0.00 % |
| Course total | - | 0.00 | 00 | | - |
And I log out
@javascript
Scenario: Make sure there are no errors when all items are marked as extra credit (before the fix 20150619)
And I set the following settings for grade item "Test assignment one":
| Extra credit | 1 |
And I set the following settings for grade item "Test assignment two":
| Extra credit | 1 |
And I set the following settings for grade item "Test assignment three":
| Extra credit | 1 |
When I navigate to "Grades" node in "Course administration"
And I turn editing mode on
And I give the grade "80.00" to the user "Student 1" for the grade item "Test assignment one"
And I give the grade "30.00" to the user "Student 1" for the grade item "Test assignment two"
And I give the grade "10.00" to the user "Student 1" for the grade item "Test assignment four (extra)"
And I give the grade "8.00" to the user "Student 1" for the grade item "Test assignment five (extra)"
And I press "Save changes"
And I set the field "Grade report" to "User report"
And I set the field "Select all or one user" to "Student 1"
Then the following should exist in the "user-grade" table:
| Grade item | Calculated weight | Grade | Range | Percentage | Contribution to course total |
| Test assignment one | 0.00 %( Extra credit ) | 80.00 | 0100 | 80.00 % | 0.00 % |
| Test assignment two | 0.00 %( Extra credit ) | 30.00 | 050 | 60.00 % | 0.00 % |
| Test assignment three | 0.00 %( Empty ) | - | 0200 | - | 0.00 % |
| Test assignment four (extra) | 0.00 %( Extra credit ) | 10.00 | 020 | 50.00 % | 0.00 % |
| Test assignment five (extra) | 0.00 %( Extra credit ) | 8.00 | 010 | 80.00 % | 0.00 % |
| Course total | - | 0.0 | 00 | | - |
And I log out
@javascript
Scenario: Weights are overridden and student has all grades present (before the fix 20150619)
When I set the field "Override weight of Test assignment one" to "1"
And I set the field "Weight of Test assignment one" to "50"
And I press "Save changes"
When I navigate to "Grades" node in "Course administration"
And I turn editing mode on
And I give the grade "80.00" to the user "Student 1" for the grade item "Test assignment one"
And I give the grade "30.00" to the user "Student 1" for the grade item "Test assignment two"
And I give the grade "150.00" to the user "Student 1" for the grade item "Test assignment three"
And I give the grade "10.00" to the user "Student 1" for the grade item "Test assignment four (extra)"
And I give the grade "8.00" to the user "Student 1" for the grade item "Test assignment five (extra)"
And I press "Save changes"
And I set the field "Grade report" to "User report"
And I set the field "Select all or one user" to "Student 1"
Then the following should exist in the "user-grade" table:
| Grade item | Calculated weight | Grade | Range | Percentage | Contribution to course total |
| Test assignment one | 50.00 % | 80.00 | 0100 | 80.00 % | 40.00 % |
| Test assignment two | 10.00 % | 30.00 | 050 | 60.00 % | 6.00 % |
| Test assignment three | 40.00 % | 150.00 | 0200 | 75.00 % | 30.00 % |
| Test assignment four (extra) | 4.00 %( Extra credit ) | 10.00 | 020 | 50.00 % | 2.00 % |
| Test assignment five (extra) | 2.00 %( Extra credit ) | 8.00 | 010 | 80.00 % | 1.60 % |
| Course total | - | 278.60 | 0350 | 79.60 % | - |
# Contributions of extra credit "four" should be 20/350=5.71% and "five" 10/350=2.86% (350 is max grade for the course, 20 and 10 are max grades of "four" and "five")
And I log out
@javascript
Scenario: Weights are overridden and student has some grades present (before the fix 20150619)
When I set the field "Override weight of Test assignment one" to "1"
And I set the field "Weight of Test assignment one" to "50"
And I press "Save changes"
When I navigate to "Grades" node in "Course administration"
And I turn editing mode on
And I give the grade "80.00" to the user "Student 1" for the grade item "Test assignment one"
And I give the grade "30.00" to the user "Student 1" for the grade item "Test assignment two"
And I give the grade "10.00" to the user "Student 1" for the grade item "Test assignment four (extra)"
And I give the grade "8.00" to the user "Student 1" for the grade item "Test assignment five (extra)"
And I press "Save changes"
And I set the field "Grade report" to "User report"
And I set the field "Select all or one user" to "Student 1"
Then the following should exist in the "user-grade" table:
| Grade item | Calculated weight | Grade | Range | Percentage | Contribution to course total |
| Test assignment one | 83.33 % | 80.00 | 0100 | 80.00 % | 66.67 % |
| Test assignment two | 16.67 % | 30.00 | 050 | 60.00 % | 10.00 % |
| Test assignment three | 0.00 %( Empty ) | - | 0200 | - | 0.00 % |
| Test assignment four (extra) | 6.67 %( Extra credit ) | 10.00 | 020 | 50.00 % | 3.33 % |
| Test assignment five (extra) | 3.33 %( Extra credit ) | 8.00 | 010 | 80.00 % | 2.67 % |
| Course total | - | 124.00 | 0150 | 82.67 % | - |
# Contributions of extra credit "four" should be 20/150=13.33% and "five" 10/150=6.67% (150 is max grade for the course, 20 and 10 are max grades of "four" and "five")
And I log out
@javascript
Scenario: Weights are overridden, student has none grades present except for extra credit (before the fix 20150619)
When I set the field "Override weight of Test assignment one" to "1"
And I set the field "Weight of Test assignment one" to "50"
And I press "Save changes"
When I navigate to "Grades" node in "Course administration"
And I turn editing mode on
And I give the grade "10.00" to the user "Student 1" for the grade item "Test assignment four (extra)"
And I give the grade "8.00" to the user "Student 1" for the grade item "Test assignment five (extra)"
And I press "Save changes"
And I set the field "Grade report" to "User report"
And I set the field "Select all or one user" to "Student 1"
Then the following should exist in the "user-grade" table:
| Grade item | Calculated weight | Grade | Range | Percentage | Contribution to course total |
| Test assignment one | 0.00 %( Empty ) | - | 0100 | - | 0.00 % |
| Test assignment two | 0.00 %( Empty ) | - | 050 | - | 0.00 % |
| Test assignment three | 0.00 %( Empty ) | - | 0200 | - | 0.00 % |
| Test assignment four (extra) | 0.00 %( Extra credit ) | 10.00 | 020 | 50.00 % | 0.00 % |
| Test assignment five (extra) | 0.00 %( Extra credit ) | 8.00 | 010 | 80.00 % | 0.00 % |
| Course total | - | 0.00 | 00 | | - |
And I log out
@javascript
Scenario: Weights are overridden, including extra credit, and student has all grades present (before the fix 20150619)
When I set the field "Override weight of Test assignment one" to "1"
And I set the field "Weight of Test assignment one" to "50"
And I set the field "Override weight of Test assignment four (extra)" to "1"
And I set the field "Weight of Test assignment four (extra)" to "10"
And I press "Save changes"
When I navigate to "Grades" node in "Course administration"
And I turn editing mode on
And I give the grade "80.00" to the user "Student 1" for the grade item "Test assignment one"
And I give the grade "30.00" to the user "Student 1" for the grade item "Test assignment two"
And I give the grade "150.00" to the user "Student 1" for the grade item "Test assignment three"
And I give the grade "10.00" to the user "Student 1" for the grade item "Test assignment four (extra)"
And I give the grade "8.00" to the user "Student 1" for the grade item "Test assignment five (extra)"
And I press "Save changes"
And I set the field "Grade report" to "User report"
And I set the field "Select all or one user" to "Student 1"
Then the following should exist in the "user-grade" table:
| Grade item | Calculated weight | Grade | Range | Percentage | Contribution to course total |
| Test assignment one | 50.00 % | 80.00 | 0100 | 80.00 % | 40.00 % |
| Test assignment two | 8.70 % | 30.00 | 050 | 60.00 % | 5.22 % |
| Test assignment three | 34.78 % | 150.00 | 0200 | 75.00 % | 26.09 % |
| Test assignment four (extra) | 10.00 %( Extra credit ) | 10.00 | 020 | 50.00 % | 5.00 % |
| Test assignment five (extra) | 1.74 %( Extra credit ) | 8.00 | 010 | 80.00 % | 1.39 % |
| Course total | - | 271.93 | 0350 | 77.70 % | - |
# Which is absolutely terrible because weights of normal items do not add up to 100%
And I log out
@javascript
Scenario: Weights are overridden, including extra credit, and student has some grades present (before the fix 20150619)
When I set the field "Override weight of Test assignment one" to "1"
And I set the field "Weight of Test assignment one" to "50"
And I set the field "Override weight of Test assignment four (extra)" to "1"
And I set the field "Weight of Test assignment four (extra)" to "10"
And I press "Save changes"
When I navigate to "Grades" node in "Course administration"
And I turn editing mode on
And I give the grade "80.00" to the user "Student 1" for the grade item "Test assignment one"
And I give the grade "30.00" to the user "Student 1" for the grade item "Test assignment two"
And I give the grade "10.00" to the user "Student 1" for the grade item "Test assignment four (extra)"
And I give the grade "8.00" to the user "Student 1" for the grade item "Test assignment five (extra)"
And I press "Save changes"
And I set the field "Grade report" to "User report"
And I set the field "Select all or one user" to "Student 1"
Then the following should exist in the "user-grade" table:
| Grade item | Calculated weight | Grade | Range | Percentage | Contribution to course total |
| Test assignment one | 83.33 % | 80.00 | 0100 | 80.00 % | 66.67 % |
| Test assignment two | 0.00 % | 30.00 | 050 | 60.00 % | 0.00 % |
| Test assignment three | 0.00 %( Empty ) | - | 0200 | - | 0.00 % |
| Test assignment four (extra) | 16.67 %( Extra credit ) | 10.00 | 020 | 50.00 % | 8.33 % |
| Test assignment five (extra) | 0.00 %( Extra credit ) | 8.00 | 010 | 80.00 % | 0.00 % |
| Course total | - | 112.50 | 0150 | 75.00 % | - |
# This is just ridiculous, the grades for "two" and "five" are 0 without any reason, and sum weight of normal items is not 100% again.
And I log out
@javascript
Scenario: Weights are overridden, including extra credit, student has none grades present except for extra credit (before the fix 20150619)
When I set the field "Override weight of Test assignment one" to "1"
And I set the field "Weight of Test assignment one" to "50"
And I set the field "Override weight of Test assignment four (extra)" to "1"
And I set the field "Weight of Test assignment four (extra)" to "10"
And I press "Save changes"
When I navigate to "Grades" node in "Course administration"
And I turn editing mode on
And I give the grade "10.00" to the user "Student 1" for the grade item "Test assignment four (extra)"
And I give the grade "8.00" to the user "Student 1" for the grade item "Test assignment five (extra)"
And I press "Save changes"
And I set the field "Grade report" to "User report"
And I set the field "Select all or one user" to "Student 1"
Then the following should exist in the "user-grade" table:
| Grade item | Calculated weight | Grade | Range | Percentage | Contribution to course total |
| Test assignment one | 0.00 %( Empty ) | - | 0100 | - | 0.00 % |
| Test assignment two | 0.00 %( Empty ) | - | 050 | - | 0.00 % |
| Test assignment three | 0.00 %( Empty ) | - | 0200 | - | 0.00 % |
| Test assignment four (extra) | 0.00 %( Extra credit ) | 10.00 | 020 | 50.00 % | 0.00 % |
| Test assignment five (extra) | 0.00 %( Extra credit ) | 8.00 | 010 | 80.00 % | 0.00 % |
| Course total | - | 0.00 | 00 | | - |
And I log out

View File

@ -97,7 +97,7 @@ Feature: We can use natural aggregation and weights will be normalised to a tota
And the field "Weight of Test assignment seven" matches value "0.0"
@javascript
Scenario: Grade items weights are normalised when all grade item weights are overridden (sum exactly 100). Extra credit is set to zero.
Scenario: Grade items weights are not normalised when all grade item weights are overridden (sum exactly 100). Extra credit is set respectful to number of items.
When I set the following settings for grade item "Test assignment seven":
| Extra credit | 1 |
@ -110,17 +110,17 @@ Feature: We can use natural aggregation and weights will be normalised to a tota
And I set the field "Weight of Test assignment six" to "40"
And I press "Save changes"
Then I should see "Your weights have been adjusted to total 100."
Then I should not see "Your weights have been adjusted to total 100."
And the field "Weight of Test assignment five" matches value "60.000"
And the field "Weight of Test assignment six" matches value "40.000"
And the field "Weight of Test assignment seven" matches value "0.0"
And the field "Weight of Test assignment seven" matches value "50.0"
And I reset weights for grade category "Sub category 1"
And the field "Weight of Test assignment five" matches value "66.667"
And the field "Weight of Test assignment six" matches value "33.333"
And the field "Weight of Test assignment seven" matches value "50.0"
@javascript
Scenario: Grade items weights are normalised when all grade item weights are overridden (sum over 100). Extra credit is set to zero.
Scenario: Grade items weights are normalised when all grade item weights are overridden (sum over 100). Extra credit is set respectful to number of items.
When I set the following settings for grade item "Test assignment seven":
| Extra credit | 1 |
@ -133,14 +133,14 @@ Feature: We can use natural aggregation and weights will be normalised to a tota
Then I should see "Your weights have been adjusted to total 100."
And the field "Weight of Test assignment five" matches value "54.545"
And the field "Weight of Test assignment six" matches value "45.455"
And the field "Weight of Test assignment seven" matches value "0.0"
And the field "Weight of Test assignment seven" matches value "50.0"
And I reset weights for grade category "Sub category 1"
And the field "Weight of Test assignment five" matches value "66.667"
And the field "Weight of Test assignment six" matches value "33.333"
And the field "Weight of Test assignment seven" matches value "50.0"
@javascript
Scenario: Grade items weights are normalised when all grade item weights are overridden (sum under 100). Extra credit is set to zero.
Scenario: Grade items weights are normalised when all grade item weights are overridden (sum under 100). Extra credit is set respectful to number of items.
When I set the following settings for grade item "Test assignment seven":
| Extra credit | 1 |
@ -153,14 +153,14 @@ Feature: We can use natural aggregation and weights will be normalised to a tota
Then I should see "Your weights have been adjusted to total 100."
And the field "Weight of Test assignment five" matches value "57.143"
And the field "Weight of Test assignment six" matches value "42.857"
And the field "Weight of Test assignment seven" matches value "0.0"
And the field "Weight of Test assignment seven" matches value "50.0"
And I reset weights for grade category "Sub category 1"
And the field "Weight of Test assignment five" matches value "66.667"
And the field "Weight of Test assignment six" matches value "33.333"
And the field "Weight of Test assignment seven" matches value "50.0"
@javascript
Scenario: Grade items weights are normalised when not all grade item weights are overridden. Extra credit is set respectful to non-overridden items.
Scenario: Grade items weights are normalised when not all grade item weights are overridden. Extra credit is set respectful to number of items.
When I set the following settings for grade item "Test assignment seven":
| Extra credit | 1 |
@ -171,7 +171,7 @@ Feature: We can use natural aggregation and weights will be normalised to a tota
Then I should see "Your weights have been adjusted to total 100."
And the field "Weight of Test assignment five" matches value "40.00"
And the field "Weight of Test assignment six" matches value "60.000"
And the field "Weight of Test assignment seven" matches value "90.0"
And the field "Weight of Test assignment seven" matches value "50.0"
And I reset weights for grade category "Sub category 1"
And the field "Weight of Test assignment five" matches value "66.667"
And the field "Weight of Test assignment six" matches value "33.333"

View File

@ -0,0 +1,118 @@
@core @core_grades
Feature: Gradebook calculations for natural weights normalisation before the fix 20150619
In order to make sure the grades are not changed after upgrade
As a teacher
I need to be able to freeze gradebook calculations
Background:
Given the following "courses" exist:
| fullname | shortname | category | groupmode |
| Course 1 | C1 | 0 | 1 |
And gradebook calculations for the course "C1" are frozen at version "20150619"
And the following "users" exist:
| username | firstname | lastname | email | idnumber |
| teacher1 | Teacher | 1 | teacher1@example.com | t1 |
| student1 | Student | 1 | student1@example.com | s1 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
And the following "grade categories" exist:
| fullname | course |
| Sub category 1 | C1 |
And the following "activities" exist:
| activity | course | idnumber | name | intro | grade |
| assign | C1 | a1 | Test assignment one | Submit something! | 300 |
| assign | C1 | a2 | Test assignment two | Submit something! | 100 |
| assign | C1 | a3 | Test assignment three | Submit something! | 150 |
| assign | C1 | a4 | Test assignment four | Submit nothing! | 150 |
And the following "activities" exist:
| activity | course | idnumber | name | intro | gradecategory | grade |
| assign | C1 | a5 | Test assignment five | Submit something! | Sub category 1 | 20 |
| assign | C1 | a6 | Test assignment six | Submit something! | Sub category 1 | 10 |
| assign | C1 | a7 | Test assignment seven | Submit nothing! | Sub category 1 | 15 |
And I log in as "teacher1"
And I follow "Course 1"
And I navigate to "Grades" node in "Course administration"
And I set the field "Grade report" to "Categories and items"
@javascript
Scenario: Grade items weights are normalised when all grade item weights are overridden (sum exactly 100). Extra credit is set to zero (before the fix 20150619).
When I set the following settings for grade item "Test assignment seven":
| Extra credit | 1 |
And the field "Weight of Test assignment five" matches value "66.667"
And the field "Weight of Test assignment six" matches value "33.333"
And the field "Weight of Test assignment seven" matches value "50.0"
And I set the field "Override weight of Test assignment five" to "1"
And I set the field "Override weight of Test assignment six" to "1"
And I set the field "Weight of Test assignment five" to "60"
And I set the field "Weight of Test assignment six" to "40"
And I press "Save changes"
Then I should see "Your weights have been adjusted to total 100."
And the field "Weight of Test assignment five" matches value "60.000"
And the field "Weight of Test assignment six" matches value "40.000"
And the field "Weight of Test assignment seven" matches value "0.0"
# The weight of "seven" should be 15/30=50% (15 is the maxgrade for "seven" and 30 are max grades for this category (max grade of "five" plus max grade of "six")
And I reset weights for grade category "Sub category 1"
And the field "Weight of Test assignment five" matches value "66.667"
And the field "Weight of Test assignment six" matches value "33.333"
And the field "Weight of Test assignment seven" matches value "50.0"
@javascript
Scenario: Grade items weights are normalised when all grade item weights are overridden (sum over 100). Extra credit is set to zero (before the fix 20150619).
When I set the following settings for grade item "Test assignment seven":
| Extra credit | 1 |
And I set the field "Override weight of Test assignment five" to "1"
And I set the field "Override weight of Test assignment six" to "1"
And I set the field "Weight of Test assignment five" to "60"
And I set the field "Weight of Test assignment six" to "50"
And I press "Save changes"
Then I should see "Your weights have been adjusted to total 100."
And the field "Weight of Test assignment five" matches value "54.545"
And the field "Weight of Test assignment six" matches value "45.455"
And the field "Weight of Test assignment seven" matches value "0.0"
# The weight of "seven" should be 15/30=50% (15 is the maxgrade for "seven" and 30 are max grades for this category (max grade of "five" plus max grade of "six")
And I reset weights for grade category "Sub category 1"
And the field "Weight of Test assignment five" matches value "66.667"
And the field "Weight of Test assignment six" matches value "33.333"
And the field "Weight of Test assignment seven" matches value "50.0"
@javascript
Scenario: Grade items weights are normalised when all grade item weights are overridden (sum under 100). Extra credit is set to zero (before the fix 20150619).
When I set the following settings for grade item "Test assignment seven":
| Extra credit | 1 |
And I set the field "Override weight of Test assignment five" to "1"
And I set the field "Override weight of Test assignment six" to "1"
And I set the field "Weight of Test assignment five" to "40"
And I set the field "Weight of Test assignment six" to "30"
And I press "Save changes"
Then I should see "Your weights have been adjusted to total 100."
And the field "Weight of Test assignment five" matches value "57.143"
And the field "Weight of Test assignment six" matches value "42.857"
And the field "Weight of Test assignment seven" matches value "0.0"
# The weight of "seven" should be 15/30=50% (15 is the maxgrade for "seven" and 30 are max grades for this category (max grade of "five" plus max grade of "six")
And I reset weights for grade category "Sub category 1"
And the field "Weight of Test assignment five" matches value "66.667"
And the field "Weight of Test assignment six" matches value "33.333"
And the field "Weight of Test assignment seven" matches value "50.0"
@javascript
Scenario: Grade items weights are normalised when not all grade item weights are overridden. Extra credit is set respectful to non-overridden items (before the fix 20150619).
When I set the following settings for grade item "Test assignment seven":
| Extra credit | 1 |
And I set the field "Override weight of Test assignment five" to "1"
And I set the field "Weight of Test assignment five" to "40"
And I press "Save changes"
Then I should see "Your weights have been adjusted to total 100."
And the field "Weight of Test assignment five" matches value "40.00"
And the field "Weight of Test assignment six" matches value "60.000"
And the field "Weight of Test assignment seven" matches value "90.0"
# The weight of "seven" should be 15/30=50% (15 is the maxgrade for "seven" and 30 are max grades for this category (max grade of "five" plus max grade of "six")
And I reset weights for grade category "Sub category 1"
And the field "Weight of Test assignment five" matches value "66.667"
And the field "Weight of Test assignment six" matches value "33.333"
And the field "Weight of Test assignment seven" matches value "50.0"

View File

@ -239,6 +239,9 @@ $string['gradeadministration'] = 'Grade administration';
$string['gradealreadyupdated'] = '{$a} grades have not been imported because the grades in the import file are older than in the grader report. To proceed with the grade import anyway, use the force import option.';
$string['gradeanalysis'] = 'Grade analysis';
$string['gradebook'] = 'Gradebook';
$string['gradebookcalculationsuptodate'] = 'The calculations in the gradebook are up to date. You may need to reload this page to see changes.';
$string['gradebookcalculationsfixbutton'] = 'Accept the changes and recalculate grades';
$string['gradebookcalculationswarning'] = 'Note: Some errors have been detected in gradebook calculations that affect this course. The errors have been fixed but the fix was not yet applied to this course since it may lead to the changes in existing grades. You can review the changes on <a href="{$a->url}">this documentation page</a>. Look for the changes between versions {$a->gradebookversion} and {$a->currentversion}';
$string['gradebookhiddenerror'] = 'The gradebook is currently set to hide everything from students.';
$string['gradebookhistories'] = 'Grade histories';
$string['gradeboundary'] = 'Letter grade boundary';

View File

@ -131,6 +131,7 @@ function xmldb_main_install() {
'filterall' => 0, // setting page, so have to be initialised here.
'texteditors' => 'atto,tinymce,textarea',
'upgrade_minmaxgradestepignored' => 1, // New installs should not run this upgrade step.
'upgrade_extracreditweightsstepignored' => 1, // New installs should not run this upgrade step.
);
foreach($defaults as $key => $value) {
set_config($key, $value);

View File

@ -4399,5 +4399,25 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2015060400.02);
}
if ($oldversion < 2015061900.00) {
// MDL-49257. Changed the algorithm of calculating automatic weights of extra credit items.
// Before the change, in case when grade category (in "Natural" agg. method) had items with
// overridden weights, the automatic weight of extra credit items was illogical.
// In order to prevent grades changes after the upgrade we need to freeze gradebook calculation
// for the affected courses.
// This script in included in each major version upgrade process so make sure we don't run it twice.
if (empty($CFG->upgrade_extracreditweightsstepignored)) {
upgrade_extra_credit_weightoverride();
// To skip running the same script on the upgrade to the next major release.
set_config('upgrade_extracreditweightsstepignored', 1);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2015061900.00);
}
return true;
}

View File

@ -529,4 +529,39 @@ function upgrade_mimetypes($filetypes) {
array($extension)
);
}
}
/**
* Marks all courses with changes in extra credit weight calculation
*
* Used during upgrade and in course restore process
*
* This upgrade script is needed because we changed the algorithm for calculating the automatic weights of extra
* credit items and want to prevent changes in the existing student grades.
*
* @param int $onlycourseid
*/
function upgrade_extra_credit_weightoverride($onlycourseid = 0) {
global $DB;
// Find all courses that have categories in Natural aggregation method where there is at least one extra credit
// item and at least one item with overridden weight.
$courses = $DB->get_fieldset_sql(
"SELECT DISTINCT gc.courseid
FROM {grade_categories} gc
INNER JOIN {grade_items} gi ON gc.id = gi.categoryid AND gi.weightoverride = :weightoverriden
INNER JOIN {grade_items} gie ON gc.id = gie.categoryid AND gie.aggregationcoef = :extracredit
WHERE gc.aggregation = :naturalaggmethod" . ($onlycourseid ? " AND gc.courseid = :onlycourseid" : ''),
array('naturalaggmethod' => 13,
'weightoverriden' => 1,
'extracredit' => 1,
'onlycourseid' => $onlycourseid,
)
);
foreach ($courses as $courseid) {
$gradebookfreeze = get_config('core', 'gradebook_calculations_freeze_' . $courseid);
if (!$gradebookfreeze) {
set_config('gradebook_calculations_freeze_' . $courseid, 20150619);
}
}
}

View File

@ -1166,6 +1166,12 @@ class grade_category extends grade_object {
$this->load_grade_item();
$num = count($grade_values);
$sum = 0;
// This setting indicates if we should use algorithm prior to MDL-49257 fix for calculating extra credit weights.
// Even though old algorith has bugs in it, we need to preserve existing grades.
$gradebookcalculationfreeze = (int)get_config('core', 'gradebook_calculations_freeze_' . $this->courseid);
$oldextracreditcalculation = $gradebookcalculationfreeze && ($gradebookcalculationfreeze <= 20150619);
$sumweights = 0;
$grademin = 0;
$grademax = 0;
@ -1205,7 +1211,11 @@ class grade_category extends grade_object {
$userweights[$itemid] = 0;
continue;
}
$userweights[$itemid] = $items[$itemid]->aggregationcoef2 / $sumweights;
$userweights[$itemid] = $sumweights ? ($items[$itemid]->aggregationcoef2 / $sumweights) : 0;
if (!$oldextracreditcalculation && isset($extracredititems[$itemid])) {
// Extra credit items do not affect totals.
continue;
}
$totaloverriddenweight += $userweights[$itemid];
$usergrademax = $items[$itemid]->grademax;
if (isset($grademaxoverrides[$itemid])) {
@ -1216,9 +1226,9 @@ class grade_category extends grade_object {
}
$nonoverriddenpoints = $grademax - $totaloverriddengrademax;
// Then we need to recalculate the automatic weights.
// Then we need to recalculate the automatic weights except for extra credit items.
foreach ($grade_values as $itemid => $gradevalue) {
if (!$items[$itemid]->weightoverride) {
if (!$items[$itemid]->weightoverride && ($oldextracreditcalculation || !isset($extracredititems[$itemid]))) {
$usergrademax = $items[$itemid]->grademax;
if (isset($grademaxoverrides[$itemid])) {
$usergrademax = $grademaxoverrides[$itemid];
@ -1236,6 +1246,19 @@ class grade_category extends grade_object {
}
}
// Now when we finally know the grademax we can adjust the automatic weights of extra credit items.
if (!$oldextracreditcalculation) {
foreach ($grade_values as $itemid => $gradevalue) {
if (!$items[$itemid]->weightoverride && isset($extracredititems[$itemid])) {
$usergrademax = $items[$itemid]->grademax;
if (isset($grademaxoverrides[$itemid])) {
$usergrademax = $grademaxoverrides[$itemid];
}
$userweights[$itemid] = $grademax ? ($usergrademax / $grademax) : 0;
}
}
}
// We can use our freshly corrected weights below.
foreach ($grade_values as $itemid => $gradevalue) {
if (isset($extracredititems[$itemid])) {
@ -1517,6 +1540,11 @@ class grade_category extends grade_object {
$totalnonoverriddengrademax = $totalgrademax - $totaloverriddengrademax;
// This setting indicates if we should use algorithm prior to MDL-49257 fix for calculating extra credit weights.
// Even though old algorith has bugs in it, we need to preserve existing grades.
$gradebookcalculationfreeze = (int)get_config('core', 'gradebook_calculations_freeze_' . $this->courseid);
$oldextracreditcalculation = $gradebookcalculationfreeze && ($gradebookcalculationfreeze <= 20150619);
reset($children);
foreach ($children as $sortorder => $child) {
$gradeitem = null;
@ -1539,6 +1567,16 @@ class grade_category extends grade_object {
continue;
}
if (!$oldextracreditcalculation && $gradeitem->aggregationcoef > 0) {
// For an item with extra credit ignore other weigths and overrides.
// Do not change anything at all if it's weight was already overridden.
if (!$gradeitem->weightoverride) {
$gradeitem->aggregationcoef2 = $totalgrademax ? ($gradeitem->grademax / $totalgrademax) : 0;
$gradeitem->update();
}
continue;
}
if (!$gradeitem->weightoverride) {
// Calculations with a grade maximum of zero will cause problems. Just set the weight to zero.
if ($totaloverriddenweight >= 1 || $totalnonoverriddengrademax == 0 || $gradeitem->grademax == 0) {

View File

@ -482,4 +482,67 @@ class core_upgradelib_testcase extends advanced_testcase {
// Restore value.
$CFG->grade_minmaxtouse = $initialminmax;
}
public function test_upgrade_extra_credit_weightoverride() {
global $DB, $CFG;
$this->resetAfterTest(true);
$c = array();
$a = array();
$gi = array();
for ($i=0; $i<5; $i++) {
$c[$i] = $this->getDataGenerator()->create_course();
$a[$i] = array();
$gi[$i] = array();
for ($j=0;$j<3;$j++) {
$a[$i][$j] = $this->getDataGenerator()->create_module('assign', array('course' => $c[$i], 'grade' => 100));
$giparams = array('itemtype' => 'mod', 'itemmodule' => 'assign', 'iteminstance' => $a[$i][$j]->id,
'courseid' => $c[$i]->id, 'itemnumber' => 0);
$gi[$i][$j] = grade_item::fetch($giparams);
}
}
// Case 1: Course $c[0] has aggregation method different from natural.
$coursecategory = grade_category::fetch_course_category($c[0]->id);
$coursecategory->aggregation = GRADE_AGGREGATE_WEIGHTED_MEAN;
$coursecategory->update();
$gi[0][1]->aggregationcoef = 1;
$gi[0][1]->update();
$gi[0][2]->weightoverride = 1;
$gi[0][2]->update();
// Case 2: Course $c[1] has neither extra credits nor overrides
// Case 3: Course $c[2] has extra credits but no overrides
$gi[2][1]->aggregationcoef = 1;
$gi[2][1]->update();
// Case 4: Course $c[3] has no extra credits and has overrides
$gi[3][2]->weightoverride = 1;
$gi[3][2]->update();
// Case 5: Course $c[4] has both extra credits and overrides
$gi[4][1]->aggregationcoef = 1;
$gi[4][1]->update();
$gi[4][2]->weightoverride = 1;
$gi[4][2]->update();
// Run the upgrade script and make sure only course $c[4] was marked as needed to be fixed.
upgrade_extra_credit_weightoverride();
$this->assertTrue(empty($CFG->{'gradebook_calculations_freeze_' . $c[0]->id}));
$this->assertTrue(empty($CFG->{'gradebook_calculations_freeze_' . $c[1]->id}));
$this->assertTrue(empty($CFG->{'gradebook_calculations_freeze_' . $c[2]->id}));
$this->assertTrue(empty($CFG->{'gradebook_calculations_freeze_' . $c[3]->id}));
$this->assertEquals(20150619, $CFG->{'gradebook_calculations_freeze_' . $c[4]->id});
set_config('gradebook_calculations_freeze_' . $c[4]->id, null);
// Run the upgrade script for a single course only.
upgrade_extra_credit_weightoverride($c[0]->id);
$this->assertTrue(empty($CFG->{'gradebook_calculations_freeze_' . $c[0]->id}));
upgrade_extra_credit_weightoverride($c[4]->id);
$this->assertEquals(20150619, $CFG->{'gradebook_calculations_freeze_' . $c[4]->id});
}
}

View File

@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
$version = 2015061800.00; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2015061900.00; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.