Skip to content

Commit

Permalink
Discovered a bug with lesson grades. While calculating the grade, int…
Browse files Browse the repository at this point in the history
…val was used to truncate the decimals from the grade. intavl is now replaced with round. round will now round the grade to 5 decimal places. The database only holds int(3). So, this has been changed to float to hold decimal numbers. We have found this to be much more accurate when converting the stored percentage in the database back to a point value (before this fix, users were getting numbers like 46.5 points instead of their original 47 points due to an inaccurate percent value). Files changed for this fix include:

locallib.php
report.php
version.php
view.php
db/mysql.php
db/mysql.sql
db/postgres7.php
db/postgres7.sql
  • Loading branch information
michaelpenne committed Jun 9, 2005
1 parent 338cfbb commit 71ba4dc
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 10 deletions.
4 changes: 3 additions & 1 deletion mod/lesson/db/mysql.php
Expand Up @@ -164,7 +164,9 @@ function lesson_upgrade($oldversion) {
modify_database('','ALTER TABLE prefix_lesson_pages ADD INDEX lessonid (lessonid);');
}


if ($oldversion < 2005060900) {
table_column('lesson_grades', 'grade', 'grade', 'float', '', 'unsigned', '0', 'not null');
}

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion mod/lesson/db/mysql.sql
Expand Up @@ -98,7 +98,7 @@ CREATE TABLE `prefix_lesson_grades` (
`id` int(10) unsigned NOT NULL auto_increment,
`lessonid` int(10) unsigned NOT NULL default '0',
`userid` int(10) unsigned NOT NULL default '0',
`grade` int(3) unsigned NOT NULL default '0',
`grade` float unsigned NOT NULL default '0',
`late` int(3) unsigned NOT NULL default '0',
`completed` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`id`),
Expand Down
4 changes: 4 additions & 0 deletions mod/lesson/db/postgres7.php
Expand Up @@ -211,6 +211,10 @@ function lesson_upgrade($oldversion) {
modify_database('','CREATE INDEX prefix_lesson_grades_userid_idx ON prefix_lesson_grades (userid);');
modify_database('','CREATE INDEX prefix_lesson_pages_lessonid_idx ON prefix_lesson_pages (lessonid);');
}

if ($oldversion < 2005060900) {
table_column('lesson_grades', 'grade', 'grade', 'real', '', 'unsigned', '0', 'not null');
}

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion mod/lesson/db/postgres7.sql
Expand Up @@ -87,7 +87,7 @@ CREATE TABLE prefix_lesson_grades (
id SERIAL8 PRIMARY KEY,
lessonid INT8 NOT NULL default '0',
userid INT8 NOT NULL default '0',
grade INT NOT NULL default '0',
grade real NOT NULL default '0',
late INT NOT NULL default '0',
completed INT8 NOT NULL default '0'
) ;
Expand Down
4 changes: 2 additions & 2 deletions mod/lesson/locallib.php
Expand Up @@ -1028,7 +1028,7 @@ function lesson_calculate_ongoing_score($lesson, $userid, $retries, $return=fals
}
$nviewed = count($temp); // this counts number of Questions the user viewed
if ($nviewed != 0) {
$thegrade = intval(100 * $ncorrect / $nviewed);
$thegrade = round(100 * $ncorrect / $nviewed, 5);
} else {
$thegrade = 0;
}
Expand Down Expand Up @@ -1093,7 +1093,7 @@ function lesson_calculate_ongoing_score($lesson, $userid, $retries, $return=fals
}

$bestscore = array_sum($bestscores);
$thegrade = intval(100 * $score / $bestscore);
$thegrade = round(100 * $score / $bestscore, 5);
}


Expand Down
4 changes: 2 additions & 2 deletions mod/lesson/report.php
Expand Up @@ -101,7 +101,7 @@
// see if n is = to the retry
if ($n == $attempt->retry) {
// get grade info
$usergrade = $grade->grade;
$usergrade = round($grade->grade, 2); // round it here so we only have to do it once
break;
}
$n++; // if not equal, then increment n
Expand Down Expand Up @@ -802,7 +802,7 @@
$grade = -1;
} else {
$grade = current($grades);
$grade = $grade->grade;
$grade = round($grade->grade, 2);
}
if (!$times = get_records_select("lesson_timer", "lessonid = $lesson->id and userid = $userid", "starttime", "*", $try, 1)) {
$timetotake = -1;
Expand Down
2 changes: 1 addition & 1 deletion mod/lesson/version.php
Expand Up @@ -5,7 +5,7 @@
/// This fragment is called by moodle_needs_upgrading() and /admin/index.php
/////////////////////////////////////////////////////////////////////////////////

$module->version = 2005021600; // The current module version (Date: YYYYMMDDXX)
$module->version = 2005060900; // The current module version (Date: YYYYMMDDXX)
$module->requires = 2005021600; // Requires this Moodle version
$module->cron = 0; // Period for cron to check this module (secs)

Expand Down
4 changes: 2 additions & 2 deletions mod/lesson/view.php
Expand Up @@ -935,7 +935,7 @@
}
echo "<p align=\"center\">".get_string("numberofcorrectanswers", "lesson", $ncorrect).
"</p>\n";
$thegrade = intval(100 * $ncorrect / $nviewed);
$thegrade = round(100 * $ncorrect / $nviewed, 5);
echo "<p align=\"center\">".get_string("gradeis", "lesson",
number_format($thegrade * $lesson->grade / 100, 1)).
" (".get_string("outof", "lesson", $lesson->grade).")</p>\n";
Expand Down Expand Up @@ -991,7 +991,7 @@
$bestscore = array_sum($bestscores);
}

$thegrade = intval(100 * $score / $bestscore);
$thegrade = round(100 * $score / $bestscore, 5);
$a = new stdClass;
if ($essayquestions > 0) {
$a->score = $score;
Expand Down

0 comments on commit 71ba4dc

Please sign in to comment.