Calculated question bugs and new features proposal

Jump to: navigation, search

This page will be used as a TODO-List in relation to the bug tracker tasks

Main objectives

The actual plan is to

  • Improve the actual calculated question
    • Correct the minor problems of the new 1.8 interface and add some features
      • Adding a display of the available category wild cards
        • before the question text when editing the question
        • in the datasetdefinition form
    • Improving the code flow so that if something is badly set (datadesf, dataitems) the calculated question default to a numerical one with a warning in the quiz display (and in the question name so it appears clrealy in the questions display in the question or quiz edit form).
    • Adding the possibility to show calculated results in the question as data
    Given {m} and {x} and {b} ask for the slope of
    X1 = {x}  , Y1 = {= {x}*{m}+ {b})          
    X2 = {=2*{x}}  , Y2 = {= 2*{x}*{m}+ {b})
    Calculate the slope of the line
    So if in one set of data {x} = 2 , {m}= 1 and {b}= 3
    The question display will be 
    X1 = 2 , Y1 = 5
    X2 = 4 , Y2 = 7
    Calculate the slope of the curve ?
    • Extending the actual php math function (sin(), cos() etc.) to complex function using php mathlibs
  • Develop the calculated questiontype
    • Adding multiples answers with different grade.
     So to be able to grade correctly typical errors related to units (i.e.10 times more or less)    
    • Using these multiple answers to create a multiple choice calculated question
     The user could select either type when creating the question  or saving it as new question
    • Going further and create a cloze version of the calculated question
   allowing to have multiple questions 
   and either 
     multiple answers or
     as a multiple choice calculated question

Improvement of the user interface

  1. Correct the minor problems of the new 1.8 interface and add some features. The interface should give consistent results independent of the question status
  • creating a new question
  • editing an existing question
  • saving an existing questiuon as a new question
    1. Removing the side effects when typing the enter key in dataitems_form.php input fields
      1. Verify that there is at least one wild card in either the question or the answer text.
        1. If so saving the datasetdefs with either
          1. default value ( new question)
          2. copy of the already defined datasetdefs when saving an existing question as a new one.
      2. change the code so that generating datatitems value ( for a quiz or preview) can handle this without error ( or possibly a warning) and send back a value on the fly.
    2. adding a table showing the shareable category wild cards available in the first page of question creation or edition
    3. identifying more clearly which of the wild cards has an already defined shareable category wild cards available
  1. ...

Adding new class functions or make substantial change to existing one

  1. adding a table display function showing the shareable category wild cards available in the first page of question creation or edition
    1. a general function for the abstractype class (showing only the name and nb of items)
    2. a specific function for the calculatedquestion class showing the definition (min:max:type) in a user readable format.
  2. ...

Modifying the code flow to remove the use of $SESSION to save data in the three steps question creation process

Check that there is at least one wild card {param} before leaving calculated_question_form

Use the moodleform->validate for the presence of at least one wild card

        $possibledatasets = $this->qtypeobj->find_dataset_names($data['questiontext']);
       $mandatorydatasets = array();
       foreach ($answers as $key => $answer){
           $mandatorydatasets += $this->qtypeobj->find_dataset_names($data['questiontext']);
       if (count($possibledatasets) == 0 && count($mandatorydatasets )==0){
           $errors['questiontext']=get_string('atleastonedataset', 'qtype_calculated');
           foreach ($answers as $key => $answer){
               $errors['answers['.$key.']'] = get_string('atleastonedataset', 'qtype_calculated');

Save the question data (text, answers, units) on leaving calculated_question_form

Doing this, on return from parent:save_question there will be a valid question->id

Discriminate saving a new question, editing an actual question or saving as new an actual question

  1. When creating a new question the $form->id == 0
  2. When saving as a new question $form->makecopy exist and $form->id contains the id of the original question.
  3. Editing an actual question is the last option

Save wild cards on processing calculated_question_form

The resulting code flow when saving the question and the wild cards.

There are two new functions added in datasetdependent/abstractype.php
The function preparedatasets($form,$question->id) build a dataset structure similar to the datasetdefinitions_form.php
in the new question case, the mandatory datasetdefs (those in the answers) are defined as private to the question.
The possible datasetdefs(only in question text) are default as not a dataset.
The function save_as_new_dataset_definitions copy the datadefs and data items from the initial question if they are used in the new one.
       switch($wizardnow) {
           case  :
           case 'question': // coming from the first page, creating the second                
               if (empty($form->id)) { // for a new question $form->id is empty
                  $question = parent::save_question($question, $form, $course); 
                  //prepare the datasets using default $questionfromid
                  $form->datasets = $this->preparedatasets($form);
                  $form->id = $question->id;
               } else if (!empty($form->makecopy)){ 
                  $questionfromid =  $form->id ;
                  $question = parent::save_question($question, $form, $course);
                   //prepare the datasets
                   $form->datasets = $this->preparedatasets($form,$questionfromid);                   
                   $form->id = $question->id;
                   $this->save_as_new_dataset_definitions($form,$questionfromid );
               }  else {// editing a question 
                   $question = parent::save_question($question, $form, $course);
                   //prepare the datasets
                   $form->datasets = $this->preparedatasets($form,$question->id);
                   $form->id = $question->id; 
           case 'datasetdefinitions':
           case 'datasetitems':
               $this->save_dataset_items($question, $form);

Use the datasetdefinition_form to correct the datadefs type (private, category or not a datadef)=

Improve the display by using grouping mandatory and possible datasets in 2 groups
Give infos on available category datasets with the same name
Testing that there is at least on dataset remaining on the output
(i.e. the user has not set all the datadefs to not a dataset

Use the datasetitem_form to define the wild cards and add dataitems

the actual display has some bugs to be solved elsewhere[ MDL-8391]

Removal of references to $SESSION data related to datasetdefs or data items

  1. line 29 , 38- in datasetdependent/datasetdefinitions.form.php
  2. numerous lines in datasetdependent/abstractype.php
  3. line 31, 36- in datasetdependent/datasetitems_form.php

List of files modified in the project

  1. calculated/edit_calculated_form.php
  2. calculated/questiontype.php
  3. datasetdependent/abstractype.php
  4. datasetdependent/datasetdefinitions.form.php
  5. datasetdependent/datasetitems_form.php

Improvement to import-export process and question category moving

  1. There is no way to import calculated questions in Moodle actually.The steps to correct this are:
    1. Adding an importdatadef() function and import dataitem function() to calculated questiontype class
    2. adding a preliminary verifyimporteddata() function to calculated questiontype class
    3. modify the savequestion() and saveoptions() function to accept import data.
    4. ...

Working list of bugs solved but not transfered to Moodle code

Here is a continuously updated list of the bugs (or improvements ) reported on the Moodle tracker with a working solution and waiting for approval and transfer to Moodle by Tim Hunt. This working list facilitates the collaboration between the author ( Pierre Pichet) and Tim .

MDL-8552 The dataitem number is not choosen correctly when using a calculated question in a quiz

MDL-8432 The checking that there is at least one dataset item to allow back to quiz when editing calculated question is not working properly

MDL-8447 The default answer fraction is not settled correctly on the edit_calculated form, a solution is proposed

MDL-8478 Small numerical answers i.e. 1e-18 are not graded correctly

(to be continued)Pierre Pichet 17 February 2007