Grade calculations: Difference between revisions
(Replaced wikipedia link to Decimal separator in Moodle Docs) |
m (Minor edits to make the text clearer) |
||
(13 intermediate revisions by 2 users not shown) | |||
Line 11: | Line 11: | ||
# Click on Grades in the course administration block | # Click on Grades in the course administration block | ||
# Click the 'Categories and items' | # Click the 'Categories and items' | ||
# Click the 'Edit settings' and then 'Edit calculation'. | # Click the 'Edit settings' and then 'Edit calculation'. Note: if you don't see this, then it must be enabled in ''Site administration>Grades>Report settings>Grader report'' | ||
# Start with an equal sign (=) | # Start with an equal sign (=) | ||
# | # Type an expression using numbers, arithmetic opertors, mathematical functions and ID numbers | ||
# Plug in your ID numbers enclosed in double square brackets, for example <nowiki>= | # Plug in your ID numbers (see below) enclosed in double square brackets, for example <nowiki>=[[item1]]+[[item2]]</nowiki> | ||
# | # Function arguments are encolosed within brackets and separated with a comma, for example <nowiki>=average([[item1]], [[item2]], [[item3]])</nowiki> | ||
# Click the "Save Changes" button | # Click the "Save Changes" button | ||
==Assigning ID numbers== | ==Assigning ID numbers== | ||
You can include the values of other grade items by using their ID number as references in your formulas. | You can include the values of other grade items by using their ID number as references in your formulas. Each ID number is surrounded by double square brackets, for example if you have a grade item with ID number "Quiz.3", you will refer to this item as <nowiki>[[Quiz.3]]</nowiki> in your calculation. | ||
Below the calculation field is a list | Below the calculation field there is a list with its grade categories and grade items of your course. Next to each item or category's total is displayed the ID number you can use in your calculation (already surrounded with double square brackets). However, since the ID number is optional, some items may not yet have one. These items without an ID number have instead a form field which lets you enter an ID number directly. | ||
As soon as you have assigned the ID numbers you need, you can click the "Add ID numbers" button, and the page will reload and show | As soon as you have assigned the ID numbers you need, you can click the "Add ID numbers" button, and the page will reload and show the same list with the ID numbers you have just assigned. Now you can use them in your formulas. | ||
==Calculation functions== | ==Calculation functions== | ||
Every calculation must start with an equal sign (=). Following is | Every calculation must start with an equal sign (=). Following is an expression using operators and functions supported by the system. | ||
All common arithmetic operators are supported: | |||
* average<nowiki>([[item1]], [[item2]]...)</nowiki>: Returns the average of a | * addition, using the plus (+) sign | ||
* subtraction, using the minus (-) sign | |||
* multiplication, using the asterisk (*) character | |||
* division, using the slash (/) character | |||
* exponentiation, using the caret (^) character | |||
All arithmetic operators follow their usual precedence rules: exponentiations are evaluated first, then multiplications and divisions are performed, finally additions and subtraction are carried out; so, the expression =1+2-3*4/5^6 gives almost 3 (2,999232). Precedences can be forced using parentheses, as in the expression =((((1+2)-3)*4)/5)^6 which yields 0. | |||
'''Note''': Moodle does not allow calculations involving no ID numbers. | |||
Functions can also appear in expressions, using the comma (,) character to separate their arguments listed within function (round) brackets. (The separator character could be a semicolon (;) in other [[Language|languages]], see below). | |||
* average<nowiki>([[item1]], [[item2]]...)</nowiki>: Returns the average of the values in a list of arguments | |||
* max<nowiki>([[item1]], [[item2]]...)</nowiki>: Returns the maximum value in a list of arguments | * max<nowiki>([[item1]], [[item2]]...)</nowiki>: Returns the maximum value in a list of arguments | ||
* min<nowiki>([[item1]], [[item2]]...):</nowiki> Returns the minimum value in a list of arguments | * min<nowiki>([[item1]], [[item2]]...):</nowiki> Returns the minimum value in a list of arguments | ||
Line 36: | Line 49: | ||
* pi(): Returns the value of the number Pi | * pi(): Returns the value of the number Pi | ||
* power(base, power): Raises a number to the power of another | * power(base, power): Raises a number to the power of another | ||
* round(number, count): Rounds | * round(number, count): Rounds number to count decimal digits | ||
* floor(number): Maps a real number to the largest previous integer | * floor(number): Maps a real number to the largest previous integer | ||
* ceil(number): Maps a real number to the smallest following integer | * ceil(number): Maps a real number to the smallest following integer | ||
* sum(<nowiki>[[item1]], [[item2]]...)</nowiki>: Returns the sum of all arguments | * sum(<nowiki>[[item1]], [[item2]]...)</nowiki>: Returns the sum of all arguments | ||
Many other mathematical functions are also supported: | |||
* sin | * sin() | ||
* sinh | * sinh() | ||
* arcsin | * arcsin() | ||
* asin | * asin() | ||
* arcsinh | * arcsinh() | ||
* asinh | * asinh() | ||
* cos | * cos() | ||
* cosh | * cosh() | ||
* arccos | * arccos() | ||
* acos | * acos() | ||
* arccosh | * arccosh() | ||
* acosh | * acosh() | ||
* tan | * tan() | ||
* tanh | * tanh() | ||
* arctan | * arctan() | ||
* atan | * atan() | ||
* arctanh | * arctanh() | ||
* atanh | * atanh() | ||
* sqrt | * sqrt() | ||
* abs | * abs() | ||
* ln | * ln() | ||
* log | * log() | ||
* exp | * exp() | ||
==Example calculations== | ==Example calculations== | ||
* <nowiki>= | * <nowiki>=max([[Quiz.1]], [[Quiz.4]], [[Assignment.1]])</nowiki> - Returns the maximum value of Quiz.1, Quiz.4 and Assignment.1 | ||
* <nowiki>=average(max([[Quiz.1]], [[Quiz.4]], [[Assignment.1]]), min([[Quiz.1]], [[Quiz.4]], [[Assignment.1]]))</nowiki> | * <nowiki>=average(max([[Quiz.1]], [[Quiz.4]], [[Assignment.1]]), min([[Quiz.1]], [[Quiz.4]], [[Assignment.1]]))</nowiki> - Returns the average of the maximum and the minimum values among Quiz.1, Quiz.4 and Assignment.1 (functions can be nested) | ||
* <nowiki>=sum([[1]]*0.3, [[2]]*0.6, [[3]]*2)</nowiki> - Returns a weighted grade calculations where item 1 is weighted 30%, item 2 is weighted at 60% and item 3 is weighted at 200% | |||
==Calculations when user language is not English== | ==Calculations when user language is not English== | ||
Calculation formulas use decimal and list separators as defined in the [https://docs.moodle.org/dev/Translation_langconfig langconfig.php] file of each language pack. | Calculation formulas use decimal and list separators as defined in the [https://docs.moodle.org/dev/Translation_langconfig langconfig.php] file of each [[Language packs|language pack]]. | ||
The [[Decimal separator]] (a symbol used to mark the boundary between the integral and the fractional parts of a decimal number) is a point (.) in English. In other languages it may be a comma (,). | The [[Decimal separator|decimal separator]] (a symbol used to mark the boundary between the integral and the fractional parts of a decimal number) is a point (.) in English. In other languages it may be a comma (,). | ||
The list separator (a symbol used to separate a list of | The list separator (a symbol used to separate the items within a list, such as the arguments of a function) is a comma (,) in English. In other languages it may be a semicolon (;). | ||
==See also== | ==See also== |
Latest revision as of 01:16, 8 March 2017
A grade calculation is a formula used to determine grades, based (optionally) on other grade items. Note that this is not the same as Calculated question types.
Calculations for the gradebook follow the pattern of formulas/functions in popular spreadsheet programs. They start with an equal (=) sign, and use common mathematical operators and functions to produce a single numerical output. This output is then used as the computed value for the grade item you are editing.
Setting a grade calculation
To set a grade calculation:
- Login as teacher or other user with permission to edit grades
- Click on Grades in the course administration block
- Click the 'Categories and items'
- Click the 'Edit settings' and then 'Edit calculation'. Note: if you don't see this, then it must be enabled in Site administration>Grades>Report settings>Grader report
- Start with an equal sign (=)
- Type an expression using numbers, arithmetic opertors, mathematical functions and ID numbers
- Plug in your ID numbers (see below) enclosed in double square brackets, for example =[[item1]]+[[item2]]
- Function arguments are encolosed within brackets and separated with a comma, for example =average([[item1]], [[item2]], [[item3]])
- Click the "Save Changes" button
Assigning ID numbers
You can include the values of other grade items by using their ID number as references in your formulas. Each ID number is surrounded by double square brackets, for example if you have a grade item with ID number "Quiz.3", you will refer to this item as [[Quiz.3]] in your calculation.
Below the calculation field there is a list with its grade categories and grade items of your course. Next to each item or category's total is displayed the ID number you can use in your calculation (already surrounded with double square brackets). However, since the ID number is optional, some items may not yet have one. These items without an ID number have instead a form field which lets you enter an ID number directly.
As soon as you have assigned the ID numbers you need, you can click the "Add ID numbers" button, and the page will reload and show the same list with the ID numbers you have just assigned. Now you can use them in your formulas.
Calculation functions
Every calculation must start with an equal sign (=). Following is an expression using operators and functions supported by the system. All common arithmetic operators are supported:
- addition, using the plus (+) sign
- subtraction, using the minus (-) sign
- multiplication, using the asterisk (*) character
- division, using the slash (/) character
- exponentiation, using the caret (^) character
All arithmetic operators follow their usual precedence rules: exponentiations are evaluated first, then multiplications and divisions are performed, finally additions and subtraction are carried out; so, the expression =1+2-3*4/5^6 gives almost 3 (2,999232). Precedences can be forced using parentheses, as in the expression =((((1+2)-3)*4)/5)^6 which yields 0.
Note: Moodle does not allow calculations involving no ID numbers.
Functions can also appear in expressions, using the comma (,) character to separate their arguments listed within function (round) brackets. (The separator character could be a semicolon (;) in other languages, see below).
- average([[item1]], [[item2]]...): Returns the average of the values in a list of arguments
- max([[item1]], [[item2]]...): Returns the maximum value in a list of arguments
- min([[item1]], [[item2]]...): Returns the minimum value in a list of arguments
- mod(dividend, divisor): Calculates the remainder of a division
- pi(): Returns the value of the number Pi
- power(base, power): Raises a number to the power of another
- round(number, count): Rounds number to count decimal digits
- floor(number): Maps a real number to the largest previous integer
- ceil(number): Maps a real number to the smallest following integer
- sum([[item1]], [[item2]]...): Returns the sum of all arguments
Many other mathematical functions are also supported:
- sin()
- sinh()
- arcsin()
- asin()
- arcsinh()
- asinh()
- cos()
- cosh()
- arccos()
- acos()
- arccosh()
- acosh()
- tan()
- tanh()
- arctan()
- atan()
- arctanh()
- atanh()
- sqrt()
- abs()
- ln()
- log()
- exp()
Example calculations
- =max([[Quiz.1]], [[Quiz.4]], [[Assignment.1]]) - Returns the maximum value of Quiz.1, Quiz.4 and Assignment.1
- =average(max([[Quiz.1]], [[Quiz.4]], [[Assignment.1]]), min([[Quiz.1]], [[Quiz.4]], [[Assignment.1]])) - Returns the average of the maximum and the minimum values among Quiz.1, Quiz.4 and Assignment.1 (functions can be nested)
- =sum([[1]]*0.3, [[2]]*0.6, [[3]]*2) - Returns a weighted grade calculations where item 1 is weighted 30%, item 2 is weighted at 60% and item 3 is weighted at 200%
Calculations when user language is not English
Calculation formulas use decimal and list separators as defined in the langconfig.php file of each language pack.
The decimal separator (a symbol used to mark the boundary between the integral and the fractional parts of a decimal number) is a point (.) in English. In other languages it may be a comma (,).
The list separator (a symbol used to separate the items within a list, such as the arguments of a function) is a comma (,) in English. In other languages it may be a semicolon (;).