From 21dd6842079bd71c3e7fa22f45c86dae64046906 Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Mon, 13 Oct 2014 15:51:55 +0800 Subject: [PATCH 1/1] MDL-47463 core_grades: Behat checks the contribution of scales --- grade/tests/behat/grade_scales.feature | 57 ++++++++++++++------------ lib/grade/grade_category.php | 7 ++-- 2 files changed, 34 insertions(+), 30 deletions(-) diff --git a/grade/tests/behat/grade_scales.feature b/grade/tests/behat/grade_scales.feature index 1421da7e8c0..c884ba856dd 100644 --- a/grade/tests/behat/grade_scales.feature +++ b/grade/tests/behat/grade_scales.feature @@ -63,6 +63,11 @@ Feature: View gradebook when scales are used And I press "Save changes" And I follow "Course 1" And I follow "Grades" + And I navigate to "Course grade settings" node in "Grade administration > Setup" + And I set the field "Show weightings" to "Show" + And I set the field "Show contribution to course total" to "Show" + And I press "Save changes" + And I follow "Grader report" And I turn editing mode on @javascript @@ -83,10 +88,10 @@ Feature: View gradebook when scales are used And I set the field "Select all or one user" to "Student 3" And I click on "Select all or one user" "select" And the following should exist in the "user-grade" table: - | Grade item | Grade | Range | Percentage | - | Test assignment one | C | F–A | 50.00 % | - | Category total | 3.00 | 0–5 | 60.00 % | - | Course total | 3.00 | 0–5 | 60.00 % | + | Grade item | Grade | Range | Percentage | Contribution to course total | + | Test assignment one | C | F–A | 50.00 % | 3.00 | + | Category total | 3.00 | 0–5 | 60.00 % | - | + | Course total | 3.00 | 0–5 | 60.00 % | - | And I set the field "jump" to "Categories and items" And the following should exist in the "grade_edit_tree_table" table: | Name | Max grade | @@ -98,10 +103,10 @@ Feature: View gradebook when scales are used And I follow "Course 1" And I follow "Grades" And the following should exist in the "user-grade" table: - | Grade item | Grade | Range | Percentage | - | Test assignment one | B | F–A | 75.00 % | - | Category total | 4.00 | 0–5 | 80.00 % | - | Course total | 4.00 | 0–5 | 80.00 % | + | Grade item | Grade | Range | Percentage | Contribution to course total | + | Test assignment one | B | F–A | 75.00 % | 4.00 | + | Category total | 4.00 | 0–5 | 80.00 % | - | + | Course total | 4.00 | 0–5 | 80.00 % | - | @javascript Scenario Outline: Test displaying scales in gradebook in all other aggregation methods @@ -131,10 +136,10 @@ Feature: View gradebook when scales are used And I set the field "Select all or one user" to "Student 3" And I click on "Select all or one user" "select" And the following should exist in the "user-grade" table: - | Grade item | Grade | Range | Percentage | - | Test assignment one | C | F–A | 50.00 % | - | Category total. | 3.00 | 1–5 | 50.00 % | - | Course total. | | 0–100 | | + | Grade item | Grade | Range | Percentage | Contribution to course total | + | Test assignment one | C | F–A | 50.00 % | | + | Category total. | 3.00 | 1–5 | 50.00 % | - | + | Course total. | | 0–100 | | - | And I set the field "jump" to "Categories and items" And the following should exist in the "grade_edit_tree_table" table: | Name | Max grade | @@ -146,18 +151,18 @@ Feature: View gradebook when scales are used And I follow "Course 1" And I follow "Grades" And the following should exist in the "user-grade" table: - | Grade item | Grade | Range | Percentage | - | Test assignment one | B | F–A | 75.00 % | - | Category total. | 4.00 | 1–5 | 75.00 % | - | Course total. | | 0–100 | | + | Grade item | Grade | Range | Percentage | Contribution to course total | + | Test assignment one | B | F–A | 75.00 % | | + | Category total. | 4.00 | 1–5 | 75.00 % | - | + | Course total. | | 0–100 | | - | - Examples: - | aggregation | coursetotal1 | coursetotal2 | coursetotal3 | coursetotal4 | coursetotal5 |overallavg | courseperc2 | courseperc3 | - | Mean of grades | 100.00 | 75.00 | 50.00 | 25.00 | 0.00 | 50.00 | 75.00 % | 50.00 % | - | Weighted mean of grades | - | - | - | - | - | - | - | - | - | Simple weighted mean of grades | 100.00 | 75.00 | 50.00 | 25.00 | 0.00 | 50.00 | 75.00 % | 50.00 % | - | Mean of grades (with extra credits) | 100.00 | 75.00 | 50.00 | 25.00 | 0.00 | 50.00 | 75.00 % | 50.00 % | - | Median of grades | 100.00 | 75.00 | 50.00 | 25.00 | 0.00 | 50.00 | 75.00 % | 50.00 % | - | Lowest grade | 100.00 | 75.00 | 50.00 | 25.00 | 0.00 | 50.00 | 75.00 % | 50.00 % | - | Highest grade | 100.00 | 75.00 | 50.00 | 25.00 | 0.00 | 50.00 | 75.00 % | 50.00 % | - | Mode of grades | 100.00 | 75.00 | 50.00 | 25.00 | 0.00 | 50.00 | 75.00 % | 50.00 % | + Examples: + | aggregation | coursetotal1 | coursetotal2 | coursetotal3 | coursetotal4 | coursetotal5 |overallavg | courseperc2 | courseperc3 | contrib2 | contrib3 | + | Mean of grades | 100.00 | 75.00 | 50.00 | 25.00 | 0.00 | 50.00 | 75.00 % | 50.00 % | 75.00 | 50.00 | + | Weighted mean of grades | - | - | - | - | - | - | - | - | 0.00 | 0.00 | + | Simple weighted mean of grades | 100.00 | 75.00 | 50.00 | 25.00 | 0.00 | 50.00 | 75.00 % | 50.00 % | 75.00 | 50.00 | + | Mean of grades (with extra credits) | 100.00 | 75.00 | 50.00 | 25.00 | 0.00 | 50.00 | 75.00 % | 50.00 % | 75.00 | 50.00 | + | Median of grades | 100.00 | 75.00 | 50.00 | 25.00 | 0.00 | 50.00 | 75.00 % | 50.00 % | 75.00 | 50.00 | + | Lowest grade | 100.00 | 75.00 | 50.00 | 25.00 | 0.00 | 50.00 | 75.00 % | 50.00 % | 75.00 | 50.00 | + | Highest grade | 100.00 | 75.00 | 50.00 | 25.00 | 0.00 | 50.00 | 75.00 % | 50.00 % | 75.00 | 50.00 | + | Mode of grades | 100.00 | 75.00 | 50.00 | 25.00 | 0.00 | 50.00 | 75.00 % | 50.00 % | 75.00 | 50.00 | diff --git a/lib/grade/grade_category.php b/lib/grade/grade_category.php index b70030cead0..05385c9389a 100644 --- a/lib/grade/grade_category.php +++ b/lib/grade/grade_category.php @@ -966,15 +966,14 @@ class grade_category extends grade_object { $sum = 0; foreach ($grade_values as $itemid=>$grade_value) { - + if ($weights !== null) { + $weights[$itemid] = $items[$itemid]->aggregationcoef; + } if ($items[$itemid]->aggregationcoef <= 0) { continue; } $weightsum += $items[$itemid]->aggregationcoef; $sum += $items[$itemid]->aggregationcoef * $grade_value; - if ($weights !== null) { - $weights[$itemid] = $items[$itemid]->aggregationcoef; - } } if ($weightsum == 0) { $agg_grade = null; -- 2.43.0