Moodle

Check all the DB columns used to store grades, and make sure they all use a consistent type

Details

  • Type: Task Task
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 1.7, 1.8
  • Fix Version/s: 2.0
  • Component/s: Questions, Quiz
  • Labels:
    None
  • Database:
    Any
  • Affected Branches:
    MOODLE_17_STABLE, MOODLE_18_STABLE
  • Fixed Branches:
    MOODLE_20_STABLE

Description

At the moment it is not consistent, with a mixture of float, decimal and int. These colum types should all be the same.

Issue Links

Activity

Hide
Tim Hunt added a comment -

Too late to mess with the database in 1.8. Pushing to 1.9

Show
Tim Hunt added a comment - Too late to mess with the database in 1.8. Pushing to 1.9
Hide
Tim Hunt added a comment -

I am going to used NUMBER(10, 5), like in the gradebook, for the various quiz table columns that store aggregated grades. But in the question processing, which stores intermediate grades for individual questions that are latter added together, I am going to use more precision, probably NUMBER(12, 7).

The columns in the question bank that I think should be NUMBER(12, 7) are:

question.defaultgrade
question.penalty
question_answers.fraction
question_sessions.sumpenalty
question_states.grade
question_states.raw_grade
question_states.penalty

the columns in the quiz that I think should be NUMBER(10, 5) are

quiz.sumgrades
quiz.grade
quiz_attempts.sumgrades
quiz_feedback.
quiz_feedback.
quiz_grades.grade
quiz_question_instances.grade
quiz_question_statistics.maxgrade

Petr has just said in Moodle HQ chat, that I should break this down into lots of different upgrades, one per column, so that if something goes wrong half way, it is possible to resume at exactly the right point.

Show
Tim Hunt added a comment - I am going to used NUMBER(10, 5), like in the gradebook, for the various quiz table columns that store aggregated grades. But in the question processing, which stores intermediate grades for individual questions that are latter added together, I am going to use more precision, probably NUMBER(12, 7). The columns in the question bank that I think should be NUMBER(12, 7) are: question.defaultgrade question.penalty question_answers.fraction question_sessions.sumpenalty question_states.grade question_states.raw_grade question_states.penalty the columns in the quiz that I think should be NUMBER(10, 5) are quiz.sumgrades quiz.grade quiz_attempts.sumgrades quiz_feedback. quiz_feedback. quiz_grades.grade quiz_question_instances.grade quiz_question_statistics.maxgrade Petr has just said in Moodle HQ chat, that I should break this down into lots of different upgrades, one per column, so that if something goes wrong half way, it is possible to resume at exactly the right point.
Hide
Tim Hunt added a comment -

Actually, quiz_question_instances.grade had better by 12,7.

Show
Tim Hunt added a comment - Actually, quiz_question_instances.grade had better by 12,7.
Hide
Pierre Pichet added a comment -

Tim
On creating a new question the $question object contains only
stdClass Object
(
[category] => 1,5
[qtype] => shortanswer
[formoptions] => object Object
(
[repeatelements] => 1
[movecontext] =>
)

[returnurl] => http://132.208.141.198/moodle_head/question/edit.php?courseid=2
[movecontext] => 0
[courseid] => 2
[inpopup] => 0
)
So the trip unnecssary trailing 0s from the display of these numbers in the question editing
should be changed to something like
// Remove unnecessary trailing 0s form grade fields.
if(isset($question->defaultgrade)){ $question->defaultgrade = 0 + $question->defaultgrade; }
if(isset($question->penalty)){ $question->penalty = 0 + $question->penalty; }

I let you do the changes , perhaps you have a better solution.

Show
Pierre Pichet added a comment - Tim On creating a new question the $question object contains only stdClass Object ( [category] => 1,5 [qtype] => shortanswer [formoptions] => object Object ( [repeatelements] => 1 [movecontext] => ) [returnurl] => http://132.208.141.198/moodle_head/question/edit.php?courseid=2 [movecontext] => 0 [courseid] => 2 [inpopup] => 0 ) So the trip unnecssary trailing 0s from the display of these numbers in the question editing should be changed to something like // Remove unnecessary trailing 0s form grade fields. if(isset($question->defaultgrade)){ $question->defaultgrade = 0 + $question->defaultgrade; } if(isset($question->penalty)){ $question->penalty = 0 + $question->penalty; } I let you do the changes , perhaps you have a better solution.
Hide
Pierre Pichet added a comment - - edited

Tim,
If this can help you,
the preceeding lines in edit_question_form.php are

$QTYPES[$question->qtype]->set_default_options($question);
if (empty($question->image)){ unset($question->image); }
and the default questiontype.php set_default_options() is empty
function set_default_options(&$question) {
}
there is no other set_default_options() in code (i.e. tags file).

There is nothing about set_default_options() in the docs.

It seems that this function set_default_options() in edit_question_form.php is not used and the actual core questions set the default options values in there own edit_question_form (i.e. edit_shortanswer_form.php) function set_data($question) before calling the parent set_data($question).

Should we kept set_default_options()?

Show
Pierre Pichet added a comment - - edited Tim, If this can help you, the preceeding lines in edit_question_form.php are $QTYPES[$question->qtype]->set_default_options($question); if (empty($question->image)){ unset($question->image); } and the default questiontype.php set_default_options() is empty function set_default_options(&$question) { } there is no other set_default_options() in code (i.e. tags file). There is nothing about set_default_options() in the docs. It seems that this function set_default_options() in edit_question_form.php is not used and the actual core questions set the default options values in there own edit_question_form (i.e. edit_shortanswer_form.php) function set_data($question) before calling the parent set_data($question). Should we kept set_default_options()?
Hide
Tim Hunt added a comment -

Well noticed that set_default_options is not used, and not needed. I made a separate issue for removing it: MDL-16398.

Show
Tim Hunt added a comment - Well noticed that set_default_options is not used, and not needed. I made a separate issue for removing it: MDL-16398.
Hide
Tim Hunt added a comment -

And your fix for the notices when creating a new question are good. I committed them. Thanks.

Show
Tim Hunt added a comment - And your fix for the notices when creating a new question are good. I committed them. Thanks.

People

Vote (3)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: