Moodle
  1. Moodle
  2. MDL-12421

When a create a data set for a calculated question with 1 decimal, whole numbers don't keep the decimal.

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.8.3
    • Fix Version/s: 1.8.5, 1.9.1, 2.0
    • Component/s: Questions, Quiz
    • Labels:
      None
    • Affected Branches:
      MOODLE_18_STABLE
    • Fixed Branches:
      MOODLE_18_STABLE, MOODLE_19_STABLE, MOODLE_20_STABLE

      Description

      When a new data set is created for a calculated question with a data range of 0 - 50 with 1 decimal, it works fine unless the value is 40 in which case it makes a 40 instead of a 40.0 which messes up my students when they see that and are expected to follow significant figure rules.

        Gliffy Diagrams

          Activity

          Hide
          Pierre Pichet added a comment -

          Effectively the number 40.0 (or other x.0 are displayed without the 0.
          I will work on this.

          Show
          Pierre Pichet added a comment - Effectively the number 40.0 (or other x.0 are displayed without the 0. I will work on this.
          Hide
          Pierre Pichet added a comment -

          round() function always cut the 000s if the result is an integer.
          I switch to sprintf() whicih seems to be ok.
          further testing necessary

          Show
          Pierre Pichet added a comment - round() function always cut the 000s if the result is an integer. I switch to sprintf() whicih seems to be ok. further testing necessary
          Hide
          Pierre Pichet added a comment -

          Tim
          I am changing an old sql to get the additional parameter d.options
          line +- 566 in datasetdependet/abstractype.php

          if (!$dataset = get_records_sql(
          "SELECT d.name, i.value, d.options
          FROM {$CFG->prefix}question_dataset_definitions d,
          {$CFG->prefix}question_dataset_items i,
          {$CFG->prefix}question_datasets q
          WHERE q.question = $question->id
          AND q.datasetdefinition = d.id
          AND d.id = i.definition
          AND i.itemnumber = $datasetitem")) {
          error("Couldn't get the specified dataset for a dataset dependent " .
          "question! (question: {$question->id}, " .
          "datasetitem: {$datasetitem})");
          }

          how should it be written under the standardized sql calls

          Show
          Pierre Pichet added a comment - Tim I am changing an old sql to get the additional parameter d.options line +- 566 in datasetdependet/abstractype.php if (!$dataset = get_records_sql( "SELECT d.name, i.value, d.options FROM {$CFG->prefix}question_dataset_definitions d, {$CFG->prefix}question_dataset_items i, {$CFG->prefix}question_datasets q WHERE q.question = $question->id AND q.datasetdefinition = d.id AND d.id = i.definition AND i.itemnumber = $datasetitem")) { error("Couldn't get the specified dataset for a dataset dependent " . "question! (question: {$question->id}, " . "datasetitem: {$datasetitem})"); } how should it be written under the standardized sql calls
          Hide
          Pierre Pichet added a comment -

          This rounding problem extends also to the dataset_items_form because the
          foreach ($this->datasetdefs as $defkey => $datasetdef){
          $mform->addElement('text', "number[$j]", get_string('param', 'qtype_datasetdependent', $datasetdef->name));
          the Type was only defined as
          $mform->setType('number', PARAM_NUMBER);
          this was modified by adding
          $mform->setType("number[$j]", PARAM_NUMBER);
          similarly to the other elements so
          foreach ($this->datasetdefs as $defkey => $datasetdef)

          { $mform->addElement('text', "number[$j]", get_string('param', 'qtype_datasetdependent', $datasetdef->name)); $mform->setType("number[$j]", PARAM_NUMBER); $mform->addElement('hidden', "itemid[$j]"); $mform->setType("itemid[$j]", PARAM_INT); $mform->addElement('hidden', "definition[$j]"); $mform->setType("definition[$j]", PARAM_NOTAGS); }

          otherwise a 2.0 in the upper generation tool was transtered as 2 when adding the item.
          this correct the problem at least when generating.

          Show
          Pierre Pichet added a comment - This rounding problem extends also to the dataset_items_form because the foreach ($this->datasetdefs as $defkey => $datasetdef){ $mform->addElement('text', "number [$j] ", get_string('param', 'qtype_datasetdependent', $datasetdef->name)); the Type was only defined as $mform->setType('number', PARAM_NUMBER); this was modified by adding $mform->setType("number [$j] ", PARAM_NUMBER); similarly to the other elements so foreach ($this->datasetdefs as $defkey => $datasetdef) { $mform->addElement('text', "number[$j]", get_string('param', 'qtype_datasetdependent', $datasetdef->name)); $mform->setType("number[$j]", PARAM_NUMBER); $mform->addElement('hidden', "itemid[$j]"); $mform->setType("itemid[$j]", PARAM_INT); $mform->addElement('hidden', "definition[$j]"); $mform->setType("definition[$j]", PARAM_NOTAGS); } otherwise a 2.0 in the upper generation tool was transtered as 2 when adding the item. this correct the problem at least when generating.
          Hide
          Tim Hunt added a comment -

          In reply to "how should it be written under the standardized sql calls". The answer is that it is already written the right way. It needs to pull data from a combination of three different tables, and it is doing that efficiently with a single SQL statement. Since it is a complicated query, the only way to do it is with the get_records_sql function. there is no simpler equivalent using get_records in this case.

          Show
          Tim Hunt added a comment - In reply to "how should it be written under the standardized sql calls". The answer is that it is already written the right way. It needs to pull data from a combination of three different tables, and it is doing that efficiently with a single SQL statement. Since it is a complicated query, the only way to do it is with the get_records_sql function. there is no simpler equivalent using get_records in this case.
          Hide
          Pierre Pichet added a comment -

          The custom_generator_tools_part() of calculated/questiontype.php has been changed accordingly.
          a first version has been CVS to HEAD and the merges will be done after more testing.

          Show
          Pierre Pichet added a comment - The custom_generator_tools_part() of calculated/questiontype.php has been changed accordingly. a first version has been CVS to HEAD and the merges will be done after more testing.
          Hide
          Pierre Pichet added a comment -

          Merged to 1.9 without adding the correction to old values in abstractype.php.
          If the problem happens in old question the teacher just reedit the question and add the necessary round value.
          i.e if the ol value 2.0 was truncated to 2, he just change manually to 2.0.
          automatic correction was not a good idea as the teacher could also have changed manually the value of 2.0 to 2 .
          This have been merged to 1.9 will go down to older versions in the next days

          Show
          Pierre Pichet added a comment - Merged to 1.9 without adding the correction to old values in abstractype.php. If the problem happens in old question the teacher just reedit the question and add the necessary round value. i.e if the ol value 2.0 was truncated to 2, he just change manually to 2.0. automatic correction was not a good idea as the teacher could also have changed manually the value of 2.0 to 2 . This have been merged to 1.9 will go down to older versions in the next days
          Hide
          Pierre Pichet added a comment -

          Merged from HEAD to 1.9 STABLE and 1.8 STABLE

          Show
          Pierre Pichet added a comment - Merged from HEAD to 1.9 STABLE and 1.8 STABLE

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: