A very very rough first stab at a Questionmark Perception importer

A very very rough first stab at a Questionmark Perception importer

av Howard Miller -
Antall svar: 15
Bilde av Core developers Bilde av Documentation writers Bilde av Particularly helpful Moodlers Bilde av Peer reviewers Bilde av Plugin developers
I have thrown together this importer - it only works with Multiple Choice questions - but everything seems to be a multiple choice question in QM - and Essay type questions. It uses the .qml type files exported from QM.

To install create a directory called 'questionmark' in question/format and dump the format.php file. You should then have the option in the import list.

Please don't use this for anything serious - it's only to get some feedback and to try and guilt QM users into sending me some .qml files so that I can do further development.

If anybody who can be bothered to try it, I would appreciate any feedback - good or bad smiler
Gjennomsnittlig vurdering: -
Som svar til Howard Miller

Re: A very very rough first stab at a Questionmark Perception importer

av Howard Miller -
Bilde av Core developers Bilde av Documentation writers Bilde av Particularly helpful Moodlers Bilde av Peer reviewers Bilde av Plugin developers
I've made some updates (short answer questions and essay questions are supported) and added it the the Modules and Plugins Database...

http://moodle.org/mod/data/view.php?d=13&rid=756
Som svar til Howard Miller

Re: A very very rough first stab at a Questionmark Perception importer

av Andy Striemer -

Howard,

Have you seen this post? Someone submitted some qml files

http://moodle.org/mod/forum/discuss.php?d=67429&parent=332772

One of the people at our site is trying to import qml into moodle. She's going to take a look at what you've done so far and will hopefully be able to give you some feedback and qml files so that you can continue to work on the plugin.

Thanks!

Som svar til Andy Striemer

Re: A very very rough first stab at a Questionmark Perception importer

av Howard Miller -
Bilde av Core developers Bilde av Documentation writers Bilde av Particularly helpful Moodlers Bilde av Peer reviewers Bilde av Plugin developers
Thanks, yes.

I've been totally tied up with other stuff but I do mean to get back to it when I get a minute smiler
Som svar til Howard Miller

Re: A very very rough first stab at a Questionmark Perception importer

av Richard van Iwaarden -
Bilde av Particularly helpful Moodlers

Dear Howard,

Do you have a minute yet grijns

We seriously need to get QMP questions to Moodle. I don't care which format: Qpack, QML, XML, IMS-QTI 2.0, whatever it takes.

We have about 10.000 questions that need to be imported.

Som svar til Richard van Iwaarden

Re: A very very rough first stab at a Questionmark Perception importer

av Yulia I -
http://www.questionmark.com/us/connectors/moodle.aspx

Have you tried Questionmark Moodle Connector?
Som svar til Yulia I

Re: A very very rough first stab at a Questionmark Perception importer

av Richard van Iwaarden -
Bilde av Particularly helpful Moodlers
Yes, we have. However, when you have a lot of tests in QMP you will get a giant list of tests to add as an activity.

We also don't manage the QMP server, so we can not tweak it the right way.

And... QMP needs a license. It's not free-open source like Moodle.

The QMP conncetor is a very good backup idea though. We might have to fall back on that idea if we can't get the questions imported to Moodle.

Our preference though is to use one piece of software. We rather have our teacher learn all there is about Moodle then to tell them they need to work in Moodle except for tests... and that they need to make the tests in QMP.

After all, I'l final goal is to make Moodle the centre workspace for teachers. Connecting to get content from elsewhere is possible, but creating new content.. please do that in Moodle and not in other software.
Som svar til Richard van Iwaarden

Re: A very very rough first stab at a Questionmark Perception importer

av Tim Hunt -
Bilde av Core developers Bilde av Documentation writers Bilde av Particularly helpful Moodlers Bilde av Peer reviewers Bilde av Plugin developers
If you look at the code (http://cvs.moodle.org/contrib/plugins/question/format/questionmark/format.php?view=markup) you will see that it is really not rocket science to make a new importer. You just have to do some simple text processing to get from the XML format to the data structure that Moodle wants. It is just a matter of having enough examples of the format you want to import in order to cover all the options.

Also, I discovered recently that the way Moodle question importers work makes it really easy to write automated tests for them. For example, have a look at http://github.com/timhunt/Moodle-Question-Engine-2/blob/new_qe/question/format/xml/simpletest/testxmlformat.php, which are some tests I made for the Moodle XML format - and I found that a really helpful way to develop some changes to the format.

If you have a lot of example questions, and a PHP developer for a few days, it would be pretty easy to make the QuestionMark importer much better.
Som svar til Tim Hunt

Re: A very very rough first stab at a Questionmark Perception importer

av Richard van Iwaarden -
Bilde av Particularly helpful Moodlers

Well, I'm trying to find out some stuff now. I already fixed an error in the QMP importer.

But now I'm stuck.. perhaps anyone can help:

<QUESTION ID="9621106044997714" DESCRIPTION="TC-8501-00040 preventie" TOPIC="lokaal\Thema Tuincentrum\10 Algemene zaken\01 Arbeidsomstandigheden" STATUS="Normal">
  <CONTENT TYPE="text/html"><![CDATA[<h3>Veiligheid</h3>]]></CONTENT>
  <CONTENT TYPE="image/" WIDTH="217" HEIGHT="167" BORDER="1"><![CDATA[topicresources/911682863/01oe15-Veiligheid_011.jpg]]></CONTENT>
  <CONTENT TYPE="text/html"><![CDATA[<BR>]]></CONTENT>
  <CONTENT TYPE="text/html"><![CDATA[Als je tijdens werkoverleg over veiligheid spreekt kom je al snel het woord preventie tegen.  <BR><BR> Wat betekent dit woord?  ]]></CONTENT>
  <ANSWER QTYPE="MC" SHUFFLE="YES">
    <CHOICE ID="0">
      <CONTENT TYPE="text/html"><![CDATA[genezen]]></CONTENT>
    </CHOICE>
    <CHOICE ID="1">
      <CONTENT TYPE="text/html"><![CDATA[bestrijden]]></CONTENT>
    </CHOICE>
    <CHOICE ID="2">
      <CONTENT TYPE="text/html"><![CDATA[voorkomen]]></CONTENT>
    </CHOICE>
    <CHOICE ID="3">
      <CONTENT TYPE="text/html"><![CDATA[veroorzaken]]></CONTENT>
    </CHOICE>
  </ANSWER>
  <OUTCOME ID="2 voorkomen" SCORE="10">
    <CONDITION>"2"</CONDITION>
    <CONTENT TYPE="text/html"><![CDATA[Goed.]]></CONTENT>
  </OUTCOME>
  <OUTCOME ID="fout" SCORE="0">
    <CONDITION>OTHER</CONDITION>
    <CONTENT TYPE="text/html"><![CDATA[Fout.<BR> Preventie betekent: voorkomen]]></CONTENT>
  </OUTCOME>
</QUESTION>

This will not be converted because the importer doesn't understand the condition 'OTHER' every other answer:

       // run through outcomes
        $outcomes = $question['#']['OUTCOME']; 
        foreach ($outcomes as $outcome) {
            $condition = $outcome['#']['CONDITION'][0]['#'];
            $id = intval( trim($condition,'"' ));
            $qo->fraction[$id] = $outcome['@']['SCORE'] / 10;
            $qo->feedback[$id] = $this->import_text($outcome['#']['CONTENT'][0]['#']);
        }

Does anyone know how to fix this?

Som svar til Richard van Iwaarden

Re: A very very rough first stab at a Questionmark Perception importer

av Tim Hunt -
Bilde av Core developers Bilde av Documentation writers Bilde av Particularly helpful Moodlers Bilde av Peer reviewers Bilde av Plugin developers
I am guessing a bit here, but I think we need an if statement inside the loop, to recognise the special 'OTHER' value, and if it is present, then set $qo->fraction and $qo->feedback for all the options where those values have not been set.

That is a rather brief description. I can write more if you like.

It would be really great if you could submit any fixes or improvements you can make to this importer to http://tracker.moodle.org/ attaching a patch or other description of the change.
Som svar til Tim Hunt

Re: A very very rough first stab at a Questionmark Perception importer

av Richard van Iwaarden -
Bilde av Particularly helpful Moodlers

I will, don't worry. This will take some time but the summer holiday will be here soon and I have the time to sink my teeth in this problem.

I know we need an if statement in there. It needs something like:

      if  ($condition == 'OTHER') {

            $id = $choice['@']['ID']; }

ELSE {

$id = intval( trim($condition,'"' ));

}

But I'm not a php-programmer by far. I know what it need to do (Set all ID's feedback if condition is OTHER) but I have no clue as to how translate this into PHP.

If you could point any PHP programmer to this topic I'd be very happy!

Som svar til Tim Hunt

Re: A very very rough first stab at a Questionmark Perception importer

av Richard van Iwaarden -
Bilde av Particularly helpful Moodlers

I can't get it done... seems I really need someone who knows PHP here. I got to this part:

        // run through outcomes
        $outcomes = $question['#']['OUTCOME']; 
        $teller == 0;

         $condition = $outcome['#']['CONDITION'][0]['#'];
         print $condition;
         if ($condition == 'OTHER') {
           $id == $teller;
              $qo->fraction[$teller] = $outcome['@']['SCORE'] / 10;
            $qo->feedback[$teller] = $this->import_text($outcome['#']['CONTENT'][0]['#']);
          } else {
             $id = intval( trim($condition,'"' ));
             $qo->fraction[$id] = $outcome['@']['SCORE'] / 10;
            $qo->feedback[$id] = $this->import_text($outcome['#']['CONTENT'][0]['#']);
           }
          $teller++;

But this doesn't work, because it will find only one time 'OTHER' and I need to put the feedback + answers found in the 'OTHER' condition in all not-creect answers.

Som svar til Tim Hunt

Re: A very very rough first stab at a Questionmark Perception importer

av Richard van Iwaarden -
Bilde av Particularly helpful Moodlers

This any better? Stil not working though:

        // run through the answers - choice bit
        $teller == 0;
        $choices = $question['#']['ANSWER'][0]['#']['CHOICE']; 
        foreach ($choices as $choice) {
            $id = $choice['@']['ID'];
            $qo->answer[$id] = $this->import_text($choice['#']['CONTENT'][0]['#']);
            $teller++;
        }

        // run through outcomes
        $outcomes = $question['#']['OUTCOME'];
        $i == 0;
        print_r($outcomes);
        while($i<=$teller) {
            $condition = $outcome['#']['CONDITION'][0]['#'];
      if ($condition == 'OTHER') {
              $id == $i;
               $qo->fraction[$id] = $outcome['@']['SCORE'] / 10;
              $qo->feedback[$id] = $this->import_text($outcome['#']['CONTENT'][0]['#']);
           } else {
               $id = intval( trim($condition,'"' ));
               $qo->fraction[$id] = $outcome['@']['SCORE'] / 10;
              $qo->feedback[$id] = $this->import_text($outcome['#']['CONTENT'][0]['#']);
           }

           $i++;   
        }

Som svar til Richard van Iwaarden

Re: A very very rough first stab at a Questionmark Perception importer

av Tim Hunt -
Bilde av Core developers Bilde av Documentation writers Bilde av Particularly helpful Moodlers Bilde av Peer reviewers Bilde av Plugin developers
I would probably write code the code like this: http://pastebin.com/NrsPqfe3

(Moodle forums always mess up the whitespace when I paste code here, hence the use of pastebin.)


Som svar til Tim Hunt

Re: A very very rough first stab at a Questionmark Perception importer

av Richard van Iwaarden -
Bilde av Particularly helpful Moodlers

Excellent Tim, this seems to work well. Do you feel up to another php challenge?

I think together with someone that knows PHP we will get a great Questionmark Perception importer out of this.

I can report problems accurately and can tell what goes wrong with several questions. The PHP programmer can try to fix it.

Next thing that goes wrong is this:

<QUESTION ID="3344896440979135" DESCRIPTION="TC-8501-00046 symbool veiligheidsbril" TOPIC="lokaal\Thema Tuincentrum\10 Algemene zaken\01 Arbeidsomstandigheden" STATUS="Normal">
  <CONTENT TYPE="text/html"><![CDATA[<h3>Symbolen</h3>]]></CONTENT>
  <CONTENT TYPE="text/html"><![CDATA[Waar staat dit teken voor?]]></CONTENT>

  <CONTENT TYPE="text/html"><![CDATA[<IMG height=104 hspace=10 src="%SERVER.GRAPHICS%topicresources/911682863/01oe15-veiligheidbril_01.jpg" width=104 align=left vspace=10 border=1>]]></CONTENT>

The problem with this PHP routine is that it will only read the last content tag.

        // process content tags
        $contents = $question['#']['CONTENT'];
        foreach ($contents as $content) {
            $type = trim($content['@']['TYPE']);
            $data = trim($content['#']);
           
            if ($type=="image/") {
                $qo->image = $data;
            }
            elseif ($type=="text/plain") {
                $qo->questiontext = addslashes($data);
                $qo->questiontextformat = 2; // plain_text
            }
            elseif ($type=="text/html") {
                $qo->questiontext = addslashes($data);
                $qo->questiontextformat = 1; // html
            }

            else {
                $this->error( "Unknown content type in question header ($type)" );
                $qo->questiontext = '';
            }
        }

The PHP routine only inserts the last CONTENT-tag as questiontext, but it should parse all CONTENT tags.

Any idea how to translate that to PHP?

Also, it would be great if this: %SERVER.GRAPHICS% would be removed.

Som svar til Richard van Iwaarden

Re: A very very rough first stab at a Questionmark Perception importer

av Tim Hunt -
Bilde av Core developers Bilde av Documentation writers Bilde av Particularly helpful Moodlers Bilde av Peer reviewers Bilde av Plugin developers
Sorry, I am a bit busy right now. However, I am not the only PHP programmer in these forums, so, with any luck, someone else may leap in.