I have now implemented calculated columns in the gradebook. Here is the text from the corresponding help file:
You can have additional columns in the gradebook whose entries are calculated from those in other columns according to a formula provided by you. The "Total" grade column is an example of this. The students will be able to see their grades from calculated columns alongside their other grades. They will also be shown the formula used.
To refer back to other columns in your formula you use the following notation:
A1, A2, ... The grades from activities 1, 2, ... PA1, PA2, ... The percentage points for activities 1, 2, ... C1, C2, ... The grades from previous calculated columns 1, 2, ...
If you need to refer to a whole range of grades you can use a shorthand notation, for example A2:4 stands for the list A2,A3,A4 and similarly for C and PA. You can also use all to denote the list of all activity grades (including grades from hidden activities).
You can combine the grades using:
+, -, *, /, (, ) with their usual arithmetical meanings min(a,b,...) the minimum of a set of values max(a,b,...) the maximum of a set of values best(n,a,b,...) the sum of the best n values among a,b,... round(a) the value of a rounded to the nearest integer floor(a) the largest integer not larger than a ceil(a) the smallest integer not smaller than a
An example: if the final grade should be on a scale of 0 to 10 and should be obtained as the best 4 of the first 7 assignments then you could use the formularound(best(4,PA1:7)/40).
The calculated grades are floating point numbers. Only the first digit after the decimal point will be displayed but all digits are used for calculations.
You can choose any name for a calculated column. However if you choose the name Total then the corresponding entry in the student's grade table will be presented in bold face.
Note: The ordering of the activity columns in the grade book are determined by the ordering of the activities on the course page. Thus if you change the order on the course page then the labeling of the activity columns may change and you will have to change the formulas by hand.
The old Total column is now also just a calculated column. So you can change it or get rid of it if just summing up the grades makes no sense in your course. When you upgrade to the new version of the gradebook then initially a Total column is created automatically for each course so that existing users will see no difference (apart from a new link "Add a calculated column" and little [Edit] and [Del] links in the heading of the Totals column).
Clearly one could think of hundreds of ways to improve things (like allowing the order of columns to be changed) but I nevertheless hope that what is there is good enough to get into CVS. It certainly offers all that flexibility that we need at our Department.
The code is unclean in two respects: it uses explicit strings instead of the get_string function and it uses explicit CSS style instructions in the code rather than placing them in a style sheet. Perhaps someone else can clear up after me .
The code uses the new grade table in the form proposed by Martin, see http://moodle.org/mod/forum/discuss.php?d=3743, to hold the calculated columns. But it does not yet implement the grade_user table but continues to fetch the grades directly from the activity modules. This is ugly and inefficient and someone might want to volunteer to change that so that all activity modules write their grades directly into grade_user. See http://moodle.org/mod/forum/discuss.php?d=3725 for more related discussions.
The attached .zip file contains new versions of:
If you just drop these into the correct location in your moodle installation and visit the admin page then the database should be updated automatically and afterwards you should be able to use the new calculated columns.
Only the files grades.php and grade.php have changed substantially, for the others it was just a matter of adding something on to the end, so for those I have also included diff files that demonstrate this.
The above is the theory, let me know how it works in practice.
P.S.: the new grades.php rotates the table headers by 90 degrees to save space, see http://moodle.org/mod/forum/discuss.php?d=3201. This only happens in IE browsers. If you don't like your headings to be rotated then search for and remove all occurences of