MDL-20058 totalgrade stuff removed from workshop code

This commit is contained in:
David Mudrak
2010-01-04 18:24:03 +00:00
parent 365c2cc22a
commit f27b70fbbc
9 changed files with 44 additions and 277 deletions
+1 -2
View File
@@ -16,7 +16,7 @@
// 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 <[email protected]>
@@ -55,7 +55,6 @@ if ($settingsform->is_cancelled()) {
$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')));
}
+6 -6
View File
@@ -1,5 +1,5 @@
<?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"
>
@@ -56,7 +56,8 @@
<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"/>
@@ -105,14 +106,13 @@
<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"/>
+5 -6
View File
@@ -60,8 +60,10 @@ $string['assignedassessments'] = 'Assigned submissions to assess';
$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';
@@ -74,7 +76,7 @@ $string['editingassessmentform'] = 'Editing assessment form';
$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';
@@ -168,9 +170,6 @@ $string['taskinstructauthors'] = 'Provide instructions for submitting';
$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';
+28 -116
View File
@@ -906,31 +906,38 @@ class workshop {
$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');
@@ -998,7 +1005,7 @@ class workshop {
}
if (self::PHASE_CLOSED == $newphase) {
// push the total grades into the gradebook
// push the grades into the gradebook
}
@@ -1033,7 +1040,7 @@ class workshop {
* @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
*/
@@ -1048,7 +1055,7 @@ class workshop {
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';
}
@@ -1075,7 +1082,7 @@ class workshop {
$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)
@@ -1217,7 +1224,6 @@ class workshop {
foreach ($grades as $grade) {
$grade->gradinggrade = $this->real_grading_grade($grade->gradinggrade);
$grade->totalgrade = $this->format_total_grade($grade->totalgrade);
}
$data = new stdClass();
@@ -1226,7 +1232,6 @@ class workshop {
$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;
}
@@ -1271,19 +1276,6 @@ class workshop {
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
*
@@ -1416,43 +1408,6 @@ class workshop {
$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
*
@@ -1621,49 +1576,6 @@ class workshop {
}
}
/**
* 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
*
+2 -18
View File
@@ -402,7 +402,7 @@ class moodle_mod_workshop_renderer extends moodle_renderer_base {
*
* @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) {
@@ -438,10 +438,6 @@ class moodle_mod_workshop_renderer extends moodle_renderer_base {
$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();
@@ -536,19 +532,7 @@ class moodle_mod_workshop_renderer extends moodle_renderer_base {
$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;
}
}
-120
View File
@@ -50,9 +50,6 @@ class testable_workshop extends workshop {
parent::aggregate_grading_grades_process($assessments);
}
public function aggregate_total_grades_process(stdClass $data) {
parent::aggregate_total_grades_process($data);
}
}
/**
@@ -327,123 +324,6 @@ class workshop_internal_api_test extends UnitTestCase {
$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;
+1 -6
View File
@@ -446,7 +446,7 @@
.mod-workshop .grading-report .submissiongrade,
.mod-workshop .grading-report .gradinggrade {
text-align: center;
font-size: 160%;
font-size: 200%;
white-space: nowrap;
}
@@ -455,11 +455,6 @@
color: #ee0000;
}
.mod-workshop .grading-report .totalgrade {
text-align: center;
font-size: 220%;
}
/**
* Edit assessment form
*/
+1 -1
View File
@@ -28,6 +28,6 @@
defined('MOODLE_INTERNAL') || die();
$module->version = 2009101500;
$module->version = 2009102900;
$module->requires = 2009090400; // Requires this Moodle version
$module->cron = 60;
-2
View File
@@ -145,7 +145,6 @@ case workshop::PHASE_ASSESSMENT:
$reportopts->sorthow = $sorthow;
$reportopts->showsubmissiongrade = false;
$reportopts->showgradinggrade = false;
$reportopts->showtotalgrade = false;
echo $OUTPUT->paging_bar($pagingbar);
echo $wsoutput->grading_report($data, $reportopts);
@@ -232,7 +231,6 @@ case workshop::PHASE_EVALUATION:
$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);