Moodle 1.6 importing WEBCT calculated question

Moodle 1.6 importing WEBCT calculated question

ó $a->name - $a->date
Number of replies: 20

My university (Univerté du Québec à Montréal) will port from WEBCT 3.8 to moodle in 2007.
Importing questions and peculiarly calculated questions in moodle 1,6 is not working actually in either moodle 1,5 or 1,6.
I have solved the problem for 1,6 doing some patches but this is not an elegant solution.
1.The output from WEBCT must be first converted in utf8. Is there any policy where this conversion sould be done. In each import format.php module? in preprocessing?or elsewhere?

2.the function save_question() in question\questiontypes\datasetdependent\abstractqtype.php is tricky because it controls the three steps of defining the question, the options(the datatypedef, the data itself). "Therefore saving the question is delayed until we're through with the whole wizard."Could we put these three steps in three identified functions or by using an additional parameter in the function save_question() call?

3. the function save_dataset_definitions() in question\questiontypes\datasetdependent\abstractqtype.php always save with $datasetdef->options   = '';. There is an function update_dataset_options($datasetdefs, $form) in question\questiontypes\calculated\questiontype.php that fills the $datasetdef->options with the right values but you have to code yourself the saving of the updated dataset_definitions. Could we add a new function save_updated_dataset_definitions() in this questiontype.php file or elsewhere?

An example of modifications to the actual format/webct/format.php is attached.The webct ouptut question file was converted to utf8 preliminary to the import by my editor (uedit).

Meán na gcomhlán: -
In reply to Pierre Pichet

Re: Moodle 1.6 importing WEBCT calculated question

ó $a->name - $a->date
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Gustav can help on the quiz part of it, but in Moodle 1.6 the way to convert text to Unicode is as follows:

$textlib = textlib_get_instance();
$result = $textlib->convert($string, 'iso-8859-1'); // specify original encoding


Yes, your format.php should be doing it.  Thanks for working on this!


In reply to Martin Dougiamas

Re: Moodle 1.6 importing WEBCT calculated question

ó $a->name - $a->date

Thanks, your suggestion is working correctly!

textlib = textlib_get_instance();
$result = $textlib->convert($string, 'iso-8859-1'); // specify original encoding


In reply to Martin Dougiamas

Re: Moodle 1.6 importing WEBCT calculated question

ó $a->name - $a->date

On close examination the utf8 conversion problem was not really solved because in reading the text file the function file(&filename) returns an array of strings &lines .

So I have to do an array walk for example using the following code

  function utf8_encode_array(&$array) {
  if(is_array($array)) {
   array_walk ($array, 'utf8_encode_array');
  } else {
  $array = utf8_encode($array);

  }
}

utf8_encode_array(&$lines);

This solve my problem.(our WEBCT site is in french).

What will be the case for WEBCT sites in other languages?

Pierre Pichet

In reply to Martin Dougiamas

Re: Moodle 1.6 importing WEBCT calculated question

ó $a->name - $a->date
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
!!Panic!!

Martin, is this likely to be a problem for *all* quiz imports? (the unicode bit that is). My immediate worry is that in many cases it's just a text file and one doesn't neccessarily know what the encoding of the input file is. The old advice has been to make sure that your file is encoded the same as your language that Moodle is set to - this won't wash any more will it?

Do we need a drop-down box to specify the encoding, or is this an overreaction - what happens were other files are imported into the files area of Moodle?
In reply to Howard Miller

Re: Moodle 1.6 importing WEBCT calculated question

ó $a->name - $a->date
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Correct, all text being imported into a Unicode Moodle needs to be converted to Unicode if it isn't already.

An easy way might be to look into the "oldcharset" string of the current language pack  ...  get_string('oldcharset', 'langconfig')  ... and use that as the default.

A proper way to be to actually add a menu of all known character sets and perhaps do the above to set the default value.
In reply to Martin Dougiamas

Re: Moodle 1.6 importing WEBCT calculated question

ó $a->name - $a->date
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
** sigh **

More work... I think the list of encodings is the only answer. Does such a list exist anywhere in the bowels of Moodle?
In reply to Howard Miller

Re: Moodle 1.6 importing WEBCT calculated question

ó $a->name - $a->date
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
...having had a look around, this seems more problematic than I expected. You can get a list from mbstring (and without too much bother from typo3) but iconv and recode don't seem to support returning a list of available encodings.

Perhaps there is a better place to post this question.... Aoibh
In reply to Howard Miller

Re: Moodle 1.6 importing WEBCT calculated question

ó $a->name - $a->date

It could be useful if, after loading the file and  transforming it to utf8, we present to the user the translated question text so he can approved the translation or go back and try another format.

The kind of interface you have with microsoft excel when you import *.txt files with various possible delimiters.

In reply to Pierre Pichet

Re: Moodle 1.6 importing WEBCT calculated question

ó $a->name - $a->date
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Yes - thanks I will take a look. It would be useful if you could post a report in the bug tracker (referencing this discussion). Could you please supply some example WebCT exports for testing - I do not have ready access to WebCT!

Your points 2 and 3. Could you be more specific as to why there is a problem and/or you would like the function changes/additions?

Could you also say what didn't work about it in the first place?

Thanks Aoibh
In reply to Howard Miller

Re: Moodle 1.6 importing WEBCT calculated question

ó $a->name - $a->date

I installed moodle 1,6 on my computer and try to import a quite simple calculated problem. I included one in the attachment.
I found that the actual impletation was not modified when ported from 1,5 to 1,6. and Gustav Delus confirm that the last csv was in 2004.
The last line of the actual question/format/webct/format.php is
echo "<pre>"; print_r( $questions );  die;
So I inspect the code to understand the structure and finally have a somewhat working module whic can realy import calculated problems and other  more simple.
Actually the version I include in the posting does not take account correctly of some variables ( i.e category). This is why I am consulting before finishing the module. 

You will also find the parameters definition from WEBCT in the next message.

Pierre Pichet

In reply to Howard Miller

Re: Moodle 1.6 importing WEBCT calculated question

ó $a->name - $a->date

WEBCT format are included.

In 1,6 some parameters have been rename (min  = calcmin, max = calcmax etc.) and the questions modules reorganized . This was confirm by Gustav Delius.
Pierre

In reply to Pierre Pichet

Re: Moodle 1.6 importing WEBCT calculated question

ó $a->name - $a->date
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Sorry? What is this file?

I think the French may be throwing me off Aoibh Don't speak a word.
In reply to Howard Miller

Re: Moodle 1.6 importing WEBCT calculated question

ó $a->name - $a->date

The last part of the text is for the calculated question

:TYPE:C ( calculated)
 :TITRE:texte (facultatif) Title
:QUESTION:{H|T} HTML (H) ou texte (T)
followed in the next lines by the question text.
IMAGE:nom de fichier (facultatif)

:FORMULE:texte (FORMULA)
values for the variables (here {x} and {y})
:x-MIN:nombre
:x-MAX:nombre
:x-DEC: number of decimal figures
:y-MIN:nombre
:y-MAX:nombre
:x-DEC: number of decimal figures

number of data set values max 100
:VALEURS:nombre
dataset values
:x-VAL1:nombre
:y-VAL1:nombre
:x-VAL2:nombre
:y-VAL2:nombre

specification for the answer
:ANS-DEC: number of figures in the response
:TOL: (facultatif) TOLERANCE
Spécifiez une tolérance pour la réponse de vos étudiants. Ceci donne la variation ± de la réponse calculée.

:TYPETOL:{percent|units}

:UNITS:texte (facultatif) (ex. g/L

:UNITÉREQ:{0|1} (0 =no , 1 = yes ) in this case units must be in the answer
:UNITÉESPACE:{0|1} (0 =no , 1 = yes )
:UNITÉMAJ/MIN:{0|1} (0 =no , 1 = yes )
:UNITÉVAL:% valeur (what is the answer value % in the quiz)
:TYPERÉP:{déc|sig} (Is the ANS-DÉC parameteris decimal figures or significant figures?)

:APPRÉCIATION (feedback)
:CAT:texte (category)

In reply to Howard Miller

Re: Moodle 1.6 importing WEBCT calculated question

ó $a->name - $a->date

I have attached the messages exchange with Gustav.

If we want ot have good code we should respect the class system so that if there is a change in a class eveything continue to work and the 1,6 question modules are better than the 1,5 but more work need to be done using the classes.

Pierre

In reply to Pierre Pichet

Re: Moodle 1.6 importing WEBCT calculated question

ó $a->name - $a->date
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Yes I agree. I've never really looked at this import format, but writing directly to the database shouldn't happen. The idea is the the information is written to the functions in the appropriate questiontype via the parent format.php class.

I clearly need to have a closer look at this code and bring it in to line. Your help here is (and will be) much appreciated.
In reply to Howard Miller

Re: Moodle 1.6 importing WEBCT calculated question

ó $a->name - $a->date
I will suggest (in the following days) modifications to the various classes format.php, questiontype.php, abstractype.php.
In reply to Pierre Pichet

Re: Moodle 1.6 importing WEBCT calculated question

ó $a->name - $a->date
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Pierre,

I am having a little trouble following your postings, however it is great that you are working on this Aoibh

Can I anticpate that you will be producing a new webct/format.php in the near future? I am less sure why you want to modify questiontype.php and abstractype.php - that's more Gustav's department though.

If possible it would be better to modify webct/format so that it does not directly write to the database. It should simply return an array of correctly formatted question objects to the calling class.

Please don't worry about the UTF8 conversion. That, now that you have made me think about it, will be an issue for all import formats and I will endevour to deal with it before it reaches the import routine.

I'm looking forward to seeing your results!
In reply to Howard Miller

Re: Moodle 1.6 importing WEBCT calculated question

ó $a->name - $a->date

I dont want to interfere with anybody.I willcontinue to discuss with you because I dont know how to contact Gustav in this forum in an another way.

I post this webct problem in the quiz question forum because Gustav ask me to do so. Furthermore he wrote me that he was sending an email to you because your were the man in charge of these kind of problems.

I just want to suggest that to respect the class philosophy, each class or subclass should be able to know in what stage is the other class.

This is why we have some function which ask the other class if the object can be exported for example.

Because of the complexity of calculated question the calculated/questiontype.php or the abstractype.php used a function save_question() that is at least a four-way switch wich used the form-name parameter to switch to different pages for different options processing.

This switching is not transparent and it is why we have difficulty in programming the import function.

Say in an another way, the primary function abstractype.php is designed knowing what will be the users that used it. This is not a good design and Gustav is aware of the problem and ask me to work on it. 

So I will just suggest to you and evidently to Gustav  what is my comprehension of the problems and one or two possible solutions.

Who find the final solution is not important for me.

For example the abstractype.php save_question() could return a parameter giving information of what parts of the problems have been completed and save so we could reuse the  save_question() until it returns that everything is OK.

Or calculated/question_type.php could declare all the necessary subfunctions to save all the parts of a calculated problem.

The redesign of these function from 1,5 to 1,6 addressed some but not all of those problems.

In reply to Howard Miller

A new webct/format.php for 1,5_STABLE and a testing site

ó $a->name - $a->date

You will find as an attachment a zip file containing a quiz/format/webct/format.php file that seems to work well in moddle 1,5_STABLE ,four different simple question type examples exported from webct and a export file containing the 4 questions.

The site for 1.5 is located at

www.chimie.uqam.ca/moodle

You log as teacher and password teacher to the

Test import import webct moodle 1.5 course 

I try to use the available classes functions to do the work but some seems to be missing like saving the dataset items. datasetitems.php file just write in the database.

A version for 1.6 is coming soon (when we have finished migrating to mysql 5.0)

In reply to Pierre Pichet

An updated webct/format.php for 1.6 beta

ó $a->name - $a->date

You will find as attachment a format_new.php to replace the webct/format.php for moodle 1.6 beta (after renaming to format.php ).

Also included are the original format.php and four different types of simple questions from webct. They are partly in french to test the accents é or è and the utf8 conversion.There is also a diff file.

If you change the line
if (eregi("^GruamaTYPE|EOF):",$line)) {   to
if (eregi("^GruamaTYPE|EOF):",$line) and $nLineCounter > 3) and add the utf8 conversion,you would be able to import all questions but the calculated one.
I use a local conversion to utf8 because I don't know what is the policy (where and with which function) the utf8 conversion is done in format.php files.

If you are a little adventurous, you add the other lines so that the calculated questions could be import. I had to rewrite the saving of options and datasetitems because of the new functions on quiz from Gustav Delius and his group.

I will post later today the address of a 1.6 beta installation where you could see this new webct/format.php in action...