// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
- * Aggregates the grades for submission and grades for assessments and calculates the total grade for workshop
+ * Aggregates the grades for submission and grades for assessments
*
* @package mod-workshop
* @copyright 2009 David Mudrak <david.mudrak@gmail.com>
$workshop->aggregate_submission_grades(); // updates 'grade' in {workshop_submissions}
$evaluator->update_grading_grades($settingsdata); // updates 'gradinggrade' in {workshop_assessments}
$workshop->aggregate_grading_grades(); // updates 'gradinggrade' in {workshop_aggregations}
- $workshop->aggregate_total_grades(); // updates 'totalgrade' in {workshop_aggregations}
redirect(new moodle_url($workshop->view_url(), compact('page', 'sortby', 'sorthow')));
}
<?xml version="1.0" encoding="UTF-8" ?>
-<XMLDB PATH="mod/workshop/db" VERSION="20091028" COMMENT="XMLDB file for Moodle mod/workshop"
+<XMLDB PATH="mod/workshop/db" VERSION="20091029" COMMENT="XMLDB file for Moodle mod/workshop"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
<FIELD NAME="gradeover" TYPE="number" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" DECIMALS="5" COMMENT="Grade for the submission manually overridden by a teacher. Grade is always from interval 0..100. If NULL then the grade is not overriden." PREVIOUS="grade" NEXT="gradeoverby"/>
<FIELD NAME="gradeoverby" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" COMMENT="The id of the user who has overridden the grade for submission." PREVIOUS="gradeover" NEXT="feedbackauthor"/>
<FIELD NAME="feedbackauthor" TYPE="text" LENGTH="big" NOTNULL="false" SEQUENCE="false" COMMENT="Teacher comment/feedback for the author of the submission, for example describing the reasons for the grade overriding" PREVIOUS="gradeoverby" NEXT="feedbackauthorformat"/>
- <FIELD NAME="feedbackauthorformat" TYPE="int" LENGTH="3" NOTNULL="false" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="feedbackauthor"/>
+ <FIELD NAME="feedbackauthorformat" TYPE="int" LENGTH="3" NOTNULL="false" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="feedbackauthor" NEXT="timegraded"/>
+ <FIELD NAME="timegraded" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" COMMENT="The timestamp when grade or gradeover was recently modified" PREVIOUS="feedbackauthorformat"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="workshop_fk"/>
<KEY NAME="formfield_uk" TYPE="unique" FIELDS="assessmentid, strategy, dimensionid" COMMENT="The combination of assessmentid, strategy and dimensionid must be unique" PREVIOUS="assessment_fk"/>
</KEYS>
</TABLE>
- <TABLE NAME="workshop_aggregations" COMMENT="Aggregated grade for assessment and total grade calculated for workshop participants are stored here. The aggregated grade for submission is stored in workshop_submissions" PREVIOUS="workshop_grades">
+ <TABLE NAME="workshop_aggregations" COMMENT="Aggregated grades for assessment are stored here. The aggregated grade for submission is stored in workshop_submissions" PREVIOUS="workshop_grades">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="workshopid"/>
<FIELD NAME="workshopid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" COMMENT="the id of the workshop instance" PREVIOUS="id" NEXT="userid"/>
<FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" COMMENT="The id of the user which aggregated grades are calculated for" PREVIOUS="workshopid" NEXT="gradinggrade"/>
- <FIELD NAME="gradinggrade" TYPE="number" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" DECIMALS="5" COMMENT="The aggregated grade for all assessments made by this reviewer. The grade is a number from interval 0..100. If NULL then the grade for assessments has not been aggregated yet." PREVIOUS="userid" NEXT="totalgrade"/>
- <FIELD NAME="totalgrade" TYPE="number" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" DECIMALS="5" COMMENT="The total grade for this workshop to be pushed into the gradebook" PREVIOUS="gradinggrade" NEXT="timetotalgraded"/>
- <FIELD NAME="timetotalgraded" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" COMMENT="The timestamp of when the participant's totalgrade was recently aggregated. If there are some modifications of any assessment of his/her submission after this time, the aggregation shall be marked as possibly out-dated" PREVIOUS="totalgrade"/>
+ <FIELD NAME="gradinggrade" TYPE="number" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" DECIMALS="5" COMMENT="The aggregated grade for all assessments made by this reviewer. The grade is a number from interval 0..100. If NULL then the grade for assessments has not been aggregated yet." PREVIOUS="userid" NEXT="timegraded"/>
+ <FIELD NAME="timegraded" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" COMMENT="The timestamp of when the participant's gradinggrade was recently aggregated." PREVIOUS="gradinggrade"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="workshop_fk"/>
$string['assignedassessmentsnone'] = 'You have no assigned submission to assess';
$string['backtoeditform'] = 'Back to editing form';
$string['byfullname'] = 'by <a href=\"{$a->url}\">{$a->name}</a>';
-$string['calculatetotalgrades'] = 'Calculate total grades';
-$string['calculatetotalgradesdetails'] = 'expected: $a->expected<br />calculated: $a->known';
+$string['calculategradinggrades'] = 'Calculate assessment grades';
+$string['calculategradinggradesdetails'] = 'expected: $a->expected<br />calculated: $a->calculated';
+$string['calculatesubmissiongrades'] = 'Calculate submission grades';
+$string['calculatesubmissiongradesdetails'] = 'expected: $a->expected<br />calculated: $a->calculated';
$string['configexamplesmode'] = 'Default mode of examples assessment in workshops';
$string['configgradedecimals'] = 'Default number of digits that should be shown after the decimal point when displaying grades.';
$string['configgrade'] = 'Default maximum grade for submission in workshops';
$string['editingsubmission'] = 'Editing submission';
$string['editsubmission'] = 'Edit submission';
$string['err_removegrademappings'] = 'Unable to remove the unused grade mappings';
-$string['evaluategradeswait'] = 'Please wait until the assessments are evaluated and total grades are calculated';
+$string['evaluategradeswait'] = 'Please wait until the assessments are evaluated and the grades are calculated';
$string['evaluation'] = 'Grading evaluation';
$string['evaluationmethod'] = 'Grading evaluation method';
$string['examplesbeforeassessment'] = 'Examples are available after own submission and must be assessed before assessment phase';
$string['taskinstructreviewers'] = 'Provide instructions for assessing';
$string['taskintro'] = 'Set the workshop introduction';
$string['tasksubmit'] = 'Submit your work';
-$string['totalgradeof'] = 'Total grade (of $a)';
-$string['totalgradesmissing'] = 'Unable to calculate some total grades - they will have to be set manually in Gradebook';
-$string['totalgrade'] = 'Total grade';
$string['undersetup'] = 'The workshop is currently under setup. Please wait until it is switched to the next phase.';
$string['useexamplesdesc'] = 'Users practise evaluating on example submissions';
$string['useexamples'] = 'Use examples';
$phase->title = get_string('phaseevaluation', 'workshop');
$phase->tasks = array();
if (has_capability('mod/workshop:overridegrades', $this->context)) {
- $authors = $this->get_potential_authors(false);
- $reviewers = $this->get_potential_reviewers(false);
- $expected = count($authors + $reviewers);
- unset($authors);
- unset($reviewers);
- $known = $DB->count_records_select('workshop_aggregations', 'workshopid = ? AND totalgrade IS NOT NULL',
- array($this->id));
+ $expected = count($this->get_potential_authors(false));
+ $calculated = $DB->count_records_select('workshop_submissions',
+ 'workshopid = ? AND (grade IS NOT NULL OR gradeover IS NOT NULL)', array($this->id));
$task = new stdClass();
- $task->title = get_string('calculatetotalgrades', 'workshop');
+ $task->title = get_string('calculategrades', 'workshop');
$a = new stdClass();
$a->expected = $expected;
- $a->known = $known;
- $task->details = get_string('calculatetotalgradesdetails', 'workshop', $a);
- if ($known >= $expected) {
+ $a->calculated = $calculated;
+ $task->details = get_string('calculategradesdetails', 'workshop', $a);
+ if ($calculated >= $expected) {
$task->completed = true;
} elseif ($this->phase > self::PHASE_EVALUATION) {
$task->completed = false;
}
- $phase->tasks['calculatetotalgrade'] = $task;
- if ($known > 0 and $known < $expected) {
- $task = new stdClass();
- $task->title = get_string('totalgradesmissing', 'workshop');
- $task->completed = 'info';
- $phase->tasks['totalgradesmissinginfo'] = $task;
+ $phase->tasks['calculategradinggrade'] = $task;
+
+ $expected = count($this->get_potential_reviewers(false));
+ $calculated = $DB->count_records_select('workshop_aggregations',
+ 'workshopid = ? AND gradinggrade IS NOT NULL', array($this->id));
+ $task = new stdClass();
+ $task->title = get_string('calculategradinggrades', 'workshop');
+ $a = new stdClass();
+ $a->expected = $expected;
+ $a->calculated = $calculated;
+ $task->details = get_string('calculategradinggradesdetails', 'workshop', $a);
+ if ($calculated >= $expected) {
+ $task->completed = true;
+ } elseif ($this->phase > self::PHASE_EVALUATION) {
+ $task->completed = false;
}
+ $phase->tasks['calculategradinggrade'] = $task;
+
} elseif ($this->phase == self::PHASE_EVALUATION) {
$task = new stdClass();
$task->title = get_string('evaluategradeswait', 'workshop');
}
if (self::PHASE_CLOSED == $newphase) {
- // push the total grades into the gradebook
+ // push the grades into the gradebook
}
* @param mixed $groups single group or array of groups - only show users who are in one of these group(s). Defaults to all
* @param int $page the current page (for the pagination)
* @param int $perpage participants per page (for the pagination)
- * @param string $sortby lastname|firstname|submissiontitle|submissiongrade|gradinggrade|totalgrade
+ * @param string $sortby lastname|firstname|submissiontitle|submissiongrade|gradinggrade
* @param string $sorthow ASC|DESC
* @return stdClass data for the renderer
*/
return array();
}
- if (!in_array($sortby, array('lastname','firstname','submissiontitle','submissiongrade','gradinggrade','totalgrade'))) {
+ if (!in_array($sortby, array('lastname','firstname','submissiontitle','submissiongrade','gradinggrade'))) {
$sortby = 'lastname';
}
$params['workshopid2'] = $this->id;
$sqlsort = $sortby . ' ' . $sorthow . ',u.lastname,u.firstname,u.id';
$sql = "SELECT u.id AS userid,u.firstname,u.lastname,u.picture,u.imagealt,
- s.title AS submissiontitle, s.grade AS submissiongrade, ag.gradinggrade, ag.totalgrade
+ s.title AS submissiontitle, s.grade AS submissiongrade, ag.gradinggrade
FROM {user} u
LEFT JOIN {workshop_submissions} s ON (s.authorid = u.id AND s.workshopid = :workshopid1 AND s.example = 0)
LEFT JOIN {workshop_aggregations} ag ON (ag.userid = u.id AND ag.workshopid = :workshopid2)
foreach ($grades as $grade) {
$grade->gradinggrade = $this->real_grading_grade($grade->gradinggrade);
- $grade->totalgrade = $this->format_total_grade($grade->totalgrade);
}
$data = new stdClass();
$data->totalcount = $numofparticipants;
$data->maxgrade = $this->real_grade(100);
$data->maxgradinggrade = $this->real_grading_grade(100);
- $data->maxtotalgrade = $this->format_total_grade($data->maxgrade + $data->maxgradinggrade);
return $data;
}
return grade_floatval($p);
}
- /**
- * Rounds the value from DB to be displayed
- *
- * @param float $raw value from {workshop_aggregations}
- * @return string
- */
- public function format_total_grade($raw) {
- if (is_null($raw) or $raw === '') {
- return null;
- }
- return format_float($raw, $this->gradedecimals, true);
- }
-
/**
* Calculates the real value of grade for submission
*
$rs->close();
}
- /**
- * Calculates the workshop total grades for the given participant(s)
- *
- * @param null|int|array $restrict If null, update all reviewers, otherwise update just grades for the given reviewer(s)
- * @return void
- */
- public function aggregate_total_grades($restrict=null) {
- global $DB;
-
- // fetch a recordset with all assessments to process
- $sql = 'SELECT s.grade, s.gradeover, s.authorid AS userid,
- ag.id AS agid, ag.gradinggrade, ag.totalgrade
- FROM {workshop_submissions} s
- INNER JOIN {workshop_aggregations} ag ON (ag.userid = s.authorid)
- WHERE s.example=0 AND s.workshopid=:workshopid'; // to be cont.
- $params = array('workshopid' => $this->id);
-
- if (is_null($restrict)) {
- // update all users - no more conditions
- } elseif (!empty($restrict)) {
- list($usql, $uparams) = $DB->get_in_or_equal($restrict, SQL_PARAMS_NAMED);
- $sql .= " AND ag.userid $usql";
- $params = array_merge($params, $uparams);
- } else {
- throw new coding_exception('Empty value is not a valid parameter here');
- }
-
- $sql .= ' ORDER BY ag.userid'; // this is important for bulk processing
-
- $rs = $DB->get_recordset_sql($sql, $params);
-
- foreach ($rs as $current) {
- $this->aggregate_total_grades_process($current);
- }
- $rs->close();
- }
-
/**
* Returns the mform the teachers use to put a feedback for the reviewer
*
}
}
- /**
- * Given an object with final grade for submission and final grade for assessment, updates the total grade in DB
- *
- * @param stdClass $data
- * @return void
- */
- protected function aggregate_total_grades_process(stdClass $data) {
- global $DB;
-
- if (!is_null($data->gradeover)) {
- $submissiongrade = $data->gradeover;
- } else {
- $submissiongrade = $data->grade;
- }
-
- // If we do not have enough information to update totalgrade, do not do
- // anything. Please note there may be a lot of reasons why the workshop
- // participant does not have one of these grades - maybe she was ill or
- // just did not reach the deadlines. Teacher has to fix grades in
- // gradebook manually.
-
- if (is_null($submissiongrade) or (!empty($this->gradinggrade) and is_null($this->gradinggrade))) {
- return;
- }
-
- $totalgrade = $this->grade * $submissiongrade / 100 + $this->gradinggrade * $data->gradinggrade / 100;
-
- // check if the new total grade differs from the one stored in the database
- if (grade_floats_different($totalgrade, $data->totalgrade)) {
- // we need to save new calculation into the database
- if (is_null($data->agid)) {
- // no aggregation record yet
- $record = new stdClass();
- $record->workshopid = $this->id;
- $record->userid = $data->userid;
- $record->totalgrade = $totalgrade;
- $DB->insert_record('workshop_aggregations', $record);
- } else {
- $DB->set_field('workshop_aggregations', 'totalgrade', $totalgrade, array('id' => $data->agid));
- }
- }
- }
-
/**
* Given a list of user ids, returns the filtered one containing just ids of users with own submission
*
*
* @param stdClass $data prepared by {@link workshop::prepare_grading_report()}
* @param stdClass $options display options object with properties ->showauthornames ->showreviewernames ->sortby ->sorthow
- * ->showsubmissiongrade ->showgradinggrade ->showtotalgrade
+ * ->showsubmissiongrade ->showgradinggrade
* @return string html code
*/
public function grading_report(stdClass $data, stdClass $options) {
$table->head[] = $this->sortable_heading(get_string('gradinggradeof', 'workshop', $data->maxgradinggrade),
'gradinggrade', $options->sortby, $options->sorthow);
}
- if ($options->showtotalgrade) {
- $table->head[] = $this->sortable_heading(get_string('totalgradeof', 'workshop', $data->maxtotalgrade),
- 'totalgrade', $options->sortby, $options->sorthow);
- }
$table->rowclasses = array();
$table->colclasses = array();
$cell->add_class('gradinggrade');
$row->cells[] = $cell;
}
- // column #7 - total grade for assessment
- if ($options->showtotalgrade and $tr == 0) {
- $cell = new html_table_cell();
- if (is_null($participant->totalgrade)) {
- $cell->text = get_string('nullgrade', 'workshop');
- } else {
- $cell->text = $participant->totalgrade;
- }
- $cell->text = $this->grading_report_grade($participant->totalgrade);
- $cell->rowspan = $numoftrs;
- $cell->add_class('totalgrade');
- $row->cells[] = $cell;
- }
+
$table->data[] = $row;
}
}
parent::aggregate_grading_grades_process($assessments);
}
- public function aggregate_total_grades_process(stdClass $data) {
- parent::aggregate_total_grades_process($data);
- }
}
/**
$this->workshop->aggregate_grading_grades_process($batch);
}
- public function test_aggregate_total_grades_process_normal_new() {
- global $DB;
-
- // fixture set-up
- $this->workshop->grade = 85;
- $this->workshop->gradinggrade = 15;
-
- $data = new stdClass();
- $data->agid = 1;
- $data->grade = 95.00000;
- $data->gradeover = null;
- $data->gradinggrade = 67.34500;
- $data->totalgrade = null;
-
- $expected = grade_floatval(0.95 * 85 + 0.67345 * 15);
- $DB->expectOnce('set_field', array('workshop_aggregations', 'totalgrade', $expected, array('id' => 1)));
- // excercise SUT
- $this->workshop->aggregate_total_grades_process($data);
- }
-
- public function test_aggregate_total_grades_process_overriden_new() {
- global $DB;
-
- // fixture set-up
- $this->workshop->grade = 80;
- $this->workshop->gradinggrade = 20;
-
- $data = new stdClass();
- $data->agid = 2;
- $data->grade = 95.00000;
- $data->gradeover = 87.5;
- $data->gradinggrade = 67.34500;
- $data->totalgrade = null;
-
- $expected = grade_floatval(0.875 * 80 + 0.67345 * 20);
- $DB->expectOnce('set_field', array('workshop_aggregations', 'totalgrade', $expected, array('id' => 2)));
- // excercise SUT
- $this->workshop->aggregate_total_grades_process($data);
- }
-
- public function test_aggregate_total_grades_process_uptodate() {
- global $DB;
-
- // fixture set-up
- $this->workshop->grade = 100;
- $this->workshop->gradinggrade = 100;
-
- $data = new stdClass();
- $data->agid = 3;
- $data->grade = 45.00000;
- $data->gradeover = null;
- $data->gradinggrade = 40.00000;
- $data->totalgrade = 85.00000;
-
- $DB->expectNever('set_field');
- // excercise SUT
- $this->workshop->aggregate_total_grades_process($data);
- }
-
- public function test_aggregate_total_grades_process_null_grade() {
- global $DB;
-
- // fixture set-up
- $this->workshop->grade = 70;
- $this->workshop->gradinggrade = 30;
-
- $data = new stdClass();
- $data->agid = 4;
- $data->grade = null;
- $data->gradeover = null;
- $data->gradinggrade = 95.00000;
- $data->totalgrade = null;
-
- $DB->expectNever('set_field');
- // excercise SUT
- $this->workshop->aggregate_total_grades_process($data);
- }
-
- /*
- public function test_aggregate_total_grades_process_null_gradinggrade() {
- global $DB;
-
- // fixture set-up
- $this->workshop->grade = 70;
- $this->workshop->gradinggrade = 30;
-
- $data = new stdClass();
- $data->agid = 5;
- $data->grade = 12.12345;
- $data->gradeover = null;
- $data->gradinggrade = null;
- $data->totalgrade = null;
-
- $DB->expectNever('set_field');
- // excercise SUT
- $this->workshop->aggregate_total_grades_process($data);
- }
-
- public function test_aggregate_total_grades_process_null_gradinggrade_of_zero() {
- global $DB;
-
- // fixture set-up
- $this->workshop->grade = 100;
- $this->workshop->gradinggrade = 0;
-
- $data = new stdClass();
- $data->agid = 6;
- $data->grade = 56.00000;
- $data->gradeover = null;
- $data->gradinggrade = null;
- $data->totalgrade = null;
-
- $DB->expectOnce('set_field', array('workshop_aggregations', 'totalgrade', 56.00000, array('id' => 1)));
- // excercise SUT
- $this->workshop->aggregate_total_grades_process($data);
- }
- */
public function test_percent_to_value() {
// fixture setup
$total = 185;
.mod-workshop .grading-report .submissiongrade,
.mod-workshop .grading-report .gradinggrade {
text-align: center;
- font-size: 160%;
+ font-size: 200%;
white-space: nowrap;
}
color: #ee0000;
}
-.mod-workshop .grading-report .totalgrade {
- text-align: center;
- font-size: 220%;
-}
-
/**
* Edit assessment form
*/
defined('MOODLE_INTERNAL') || die();
-$module->version = 2009101500;
+$module->version = 2009102900;
$module->requires = 2009090400; // Requires this Moodle version
$module->cron = 60;
$reportopts->sorthow = $sorthow;
$reportopts->showsubmissiongrade = false;
$reportopts->showgradinggrade = false;
- $reportopts->showtotalgrade = false;
echo $OUTPUT->paging_bar($pagingbar);
echo $wsoutput->grading_report($data, $reportopts);
$reportopts->sorthow = $sorthow;
$reportopts->showsubmissiongrade = true;
$reportopts->showgradinggrade = true;
- $reportopts->showtotalgrade = false; // todo totalgrade to be dropped completely
echo $OUTPUT->paging_bar($pagingbar);
echo $wsoutput->grading_report($data, $reportopts);