Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Natural weighting

From MoodleDocs
Natural Weighting
Project state Specification
Tracker issue https://tracker.moodle.org/browse/MDL-43378
Discussion https://moodle.org/mod/forum/discuss.php?d=245442
Assignee Moodle HQ

Note: This page is a work-in-progress. Feedback and suggested improvements are welcome. Please join the discussion on moodle.org or use the page comments.



Natural weighting is a modification to how grades are combined.

When 'Sum of Grades' aggregation is chosen (and natural weighting is active), there will be a weight column with form fields, looking like "Weighted mean" is in 2.7. By default, the weight column shows the natural weights given to all categories and items based on gradebook structure.

Weights can be overridden by modifying the values in the form fields.

A "Reset weights" button in each category resets the weights to their defaults.


Rationale

This interface is expected to suit the needs of most teachers, and will allow them to avoid using other aggregations. Admins can therefore hide the aggregation menu and simplify the interface. If it turns out that this is enough for everyone then we can potentially remove quite a lot of aggregation code from the gradebook at a later stage, improving speed and readability.

Upgrading from other aggregation types:

Sum of grades
Leave all the weightings to be the same (as what?)
Mean of grades
Set all weights equal (to what?)
Weighted mean of grades
No change
Simple weighted mean of grades
Leave all the weights to be the same (same as Sum except it now provides for accurate category and course totals) (??)
Mean of grades (with extra credits)
Extra credit has a natural weight that takes the total container (category/ course) weight above 100% (hence, 'extra')
Lowest / Highest grades
Not possible using natural weights, but it can be replaced by a calculation into a new item.
Median / Mode of grades
Not possible using natural weights, but it's doubtful anyone uses these anyway so perhaps this can be deprecated entirely.

Implementation stages

To be safe, we plan to implement this in stages:

STAGE 1) Implement natural weighting as part of the Sum of Grades aggregation type, with admin settings that allow them to disable all other aggregations if they choose. (Moodle 2.8)

STAGE 2) Once people have been using this for a while, explore the possibility of removing other aggregation code or making them into optional plugins. (Moodle 3.0 perhaps)


Interfaces

Category editing

Prototype from luther.edu: NaturalWeights.png

Admin settings

New setting to "Force Natural Weighting" (on/off). This would default to OFF on upgraded sites and ON for new sites.

ON: this will hide the aggregation menu and all new categories will default to "Sum of grades" and natural weights. It will not affect existing gradebooks with other aggregations set (see upgrade script below for a conversion strategy).

OFF: aggregation menu is shown, but will Sum of Grades will still contain new natural weighting UI.

Upgrade script

If a site is switching to forced natural weights, they will probably want to upgrade all existing categories.

This new optional upgrade script will examine all grade categories looking at aggregation methods. It should report on what exists and allow the admin to perform an automated upgrade as follows:

  1. If GRADE_AGGREGATE_WEIGHTED_MEAN then:
    • Store value of 'aggregationcoef' fields to 'weight' fields in grade_items
    • Set 'weightoverride' field in grade_items

(We need descriptions here for ALL aggregation types)

Database changes

Add three fields to grade_items
  1. extracredit, tinyint, notnull, default: 0
  2. weight, decimal(10,5), notnull, default: 0
  3. weightoverride, tinyint, notnull, default: 0
Add one field to grade_grades
  1. weight, decimal(10,5), notnull, default: 0
This fixes the use of aggregationcoef representing both extra credit and weight in 2.7.

Unit test changes

Functional test changes

Logic changes

Sum of Grades aggregation must be fixed to exclude hidden items and to exclude non-graded items

Determination of range (in Grader and User report) and Max grade (in Setup screen) must be fixed to exclude extra credit items

Natural weights must be saved and applied to the form.

Natural weights are calculated for the Setup screen, the Grader report, and the User report. The calculation for the User report is different than that used for the Setup screen and Grader report.

Weights should be stored in grade_items for the Setup screen and the Grader report and in the grade_grades table for the User report.

The sum of weights for all containers (categories and course) add up to 100% except in the case where extra credit is used in which case 100% is exceeded by the weight of the extra credit

Setup screen and Grader report For the purposes of the calculations below the total category or course points is its total maximum points - (all of the below)

  1. extra credit items' points
  2. hidden items' points (unless hidetotalsthatcontainhiddenitems = GRADE_REPORT_SHOW_REAL_TOTAL_IF_CONTAINS_HIDDEN)
  3. all points associated with contained items or categories who've had their weights overridden

User report For the purposes of the calculations below the total category or course points is its total maximum points - (all of the below)

  1. extra credit items' points
  2. hidden items' points (unless hidetotalsthatcontainhiddenitems = GRADE_REPORT_SHOW_REAL_TOTAL_IF_CONTAINS_HIDDEN)
  3. ungraded items' points (if aggregateonlygraded is on))
  4. any items dropped through container's drop lowest or keep highest conditions
  5. all points associated with contained items or categories who've had their weights overridden
A multiplicator is used when some natural weights have been manually adjusted = sum(all adjusted weights) / 100
The natural weight for each item contained in a category or course (including extra credit items) is 'item maximum points' / 'total category or course points' (in which the item is contained) * multiplicator (if any)
The natural weight for each category (including extra credit categories) is 'total category points' / 'total category or course points' (in which the category is contained) * multiplicator (if any)


Calculation examples

Example 1 simple sum

In this case you have three assignments: A (10 points), B (10 points) and C (10 points) plus a final quiz D (20 points), and you just want their scores added together (out of 50).

Example 2 simple mean

In this case you have three assignments: A (10 points), B (10 points) and C (10 points) plus a final quiz D (20 points), and you want the final grade to be the simple mean percentage of all these scores.

Example 3 (complex)

Category 1 contains seven items

  1. Item A = 20 points
  2. Item B = 10 points is extra credit
  3. Item C = 30 points
  4. Item D = 40 points is extra credit
  5. Item E = 50 points is hidden
  6. Item F = 50 points is ungraded
  7. Item G = 10 points whose natural weight has been adjusted to 50% of the category grade
In the Setup screen and the Grader report the following conditions will exist
- Category grademax = 120 (10 + 50 + 30 + 10 + 20)
- Remainder minus adjusted weights = 110 (50 + 30 + 10 + 20) the 10 points adjusted out represent 50% of the final category grade
- Multiplicator for each weight calculation to adjust for the 50% of weight already accounted for = .5 (50% / 100%)
- A weight = 8.33% (20 / 120 * .5)
- B weight = 4.16% (10 / 120 * .5)
- C weight = 12.5% (30 / 120 * .5)
- D weight = 33.33% (40 / 120) extra credit is not adjust, retains its value regardless of weights being overridden
- E weight = 0%
- F weight = 25% (50 / 120 * .5)
- G weight = 50% (adjusted)
In the User report the following conditions will exist
- Category grademax = 70 (10 + 30 + 10 + 20)
- Remainder minus adjusted weights = 60 (30 + 10 + 20) the 10 points adjusted out represent 50% of the final category grade
- Multiplicator for each weight calculation to adjust for the 50% of weight already accounted for = .5 (50% / 100%)
- A weight = 16.66% (20 / 60 * .5)
- B weight = 8.33% (10 / 60 * .5)
- C weight = 25% (30 / 60 * .5)
- D weight = 66.66% (40 / 60) extra credit is not adjust, retains its value regardless of weights being overridden
- E weight = 0%
- F weight = 0%
- G weight = 50% (adjusted)

See also