Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Discovered a bug with lesson grades. While calculating the grade, int…

…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...
commit ebe63af2239a190390fd8205d9520515d1823ac5 1 parent 24fc7d2
michaelpenne authored
View
4 mod/lesson/db/mysql.php
@@ -163,6 +163,10 @@ function lesson_upgrade($oldversion) {
modify_database('','ALTER TABLE prefix_lesson_grades ADD INDEX userid (userid);');
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');
+ }
View
2  mod/lesson/db/mysql.sql
@@ -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`),
View
4 mod/lesson/db/postgres7.php
@@ -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;
}
View
2  mod/lesson/db/postgres7.sql
@@ -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'
) ;
View
4 mod/lesson/locallib.php
@@ -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;
}
@@ -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);
}
View
4 mod/lesson/report.php
@@ -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
@@ -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;
View
2  mod/lesson/version.php
@@ -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)
View
4 mod/lesson/view.php
@@ -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";
@@ -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;
Please sign in to comment.
Something went wrong with that request. Please try again.