Using Quiz Overview Reports for stats on quizzes outside of Moodle (2.0)

Using Quiz Overview Reports for stats on quizzes outside of Moodle (2.0)

by Joe Cape -
Number of replies: 19
Picture of Plugin developers
I'm trying something quite unusual and am interested to hear if anyone has done anything similar.

 

I have a web app that existed prior to my Moodle site and takes students through lessons and quizzes. Its functioning and look need to be conserved so it doesn't make sense to rewrite this as a Moodle module, but I want to have reporting of the results of students taking the lessons/quizzes available to the teachers on their Moodle course.

 

My solution for the moment has been to use a custom-made web service function with triggers at appropriate points in the web app (e.g. at the end of a quiz) that is accessed through an iframe using the URL resource.

 

The internal workings of the web service function do roughly the following:

 

CREATE A QUIZ:

 

insert record to mdl_quiz (name according to a convention based on the structure of web app),
Insert record to mdl_course_modules (using module 13 and the id of quiz just created; visible=0),
update record in mdl_course_sections (sort the contents of sequence field and insert the course-module id in the appropriate place),
insert record to mdl_quiz_question_instance (uses any question to allow moodle to see that the quiz has a question)

 

CREATE A QUIZ ATTEMPT

 

insert record to mdl_quiz_attempt (using the user id of the user accessing the web app; unique id as the highest current unique id + 1),
insert record to mdl_quiz_grade (using the same grade as inserted above)

 

This then works to provide teachers with stats about these hidden 'modules' that correspond to each URL resource.

 

One less important glitch is that the quiz modules so created won't appear until an existing quiz is updated (just by clicking 'edit settings' and 'update' on any quiz without making changes) or a new one created but once this is done the teachers will be able to see the table and graph of student success, which is what was wanted.

 

A more important glitch is that bona fide quizzes can't now be attempted, as I get the following error:

 

bug info: Duplicate entry '4' for key 'mdl_quizatte_uni_uix'
INSERT INTO mdl_quiz_attempts (quiz,userid,preview,layout,attempt,sumgrades,timestart,timefinish,timemodified,uniqueid) VALUES(?,?,?,?,?,?,?,?,?,?)
[array (
0 => '49',
1 => '2',
2 => 1,
3 => '2,0,4,0,3,0',
4 => 1,
5 => 0,
6 => 1307548257,
7 => 0,
8 => 1307548257,
9 => 4,
)]
Stack trace:
  • line 394 of /lib/dml/moodle_database.php: dml_write_exception thrown
  • line 874 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->query_end()
  • line 916 of /lib/dml/mysqli_native_moodle_database.php: call to mysqli_native_moodle_database->insert_record_raw()
  • line 101 of /mod/quiz/startattempt.php: call to mysqli_native_moodle_database->insert_record()

 

I am guessing this is a problem with the unique_id field of the quiz_attempt and that this causes a conflict.

Is there a way to solve this by finding a different way to create this unique id and can I persist with this method to get what I need or should I expect other instabilities to result from this?

What would my prospects be of using the gradebook API to write a new gradebook report using a table and lib/graphlib to get this done? One motive for using quizzes was that all of the permission issues are taken care of so that teachers will only see grades of their own students. Would this be harder to implement in a gradebook report?

Average of ratings: -
In reply to Joe Cape

Re: Using Quiz Overview Reports for stats on quizzes outside of Moodle (2.0)

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I don't think you should try to use the quiz for this.

All you want to do is to get the grade into the gradebook. And possibly you want to easily provide students with a link to the activity in the other system. Therefore, it is much cleaner to make a separate module for this.

At the OU we have made a custom module like this. unzip the attached into the mod folder, then go to the admin page to insall. You then need to go to Admin -> Plugins -> Externalquiz to set up the remote systems.

This probably does not do exactly what you want. It was made for our use, with no intention of sharing the code. I am only dumping it here because it may help you. There is no documentation I can share with you either.

Anyway, the key point is that when you add an externalquiz to a course, the student gets a link to attemp the activity. Also, there is then some cron code that that fetches the grades from the other system once per day, and imports it into the gradebook. It does that using the standard XML grade import, so you would need to get your other system to output the grades in that format, which should not be too hard. It is a really simple XML format.

When I say we made it, we have a Moodle 1.9 version created by various people. The Moodle 2.0 version was done by Colin Chambers, so he gets most of the credit for the attached.

In reply to Tim Hunt

Re: Using Quiz Overview Reports for stats on quizzes outside of Moodle (2.0)

by Joe Cape -
Picture of Plugin developers

Hi Tim,

Thanks for this advice and the included module.

"All you want to do is to get the grade into the gradebook."

Yes, once it is in gradebook, then the permissions to view the reports are in line with Moodle's capabilities, which is what is wanted.

It would be nice to show aggregate results of students for each quiz in bar-charts and have a breakdown of performance for each question as per the quiz overview/ attempt result reviews, but I'm guessing that once the results are in gradebook, it will be possible to use the lib/graphlib functions to create graphs and other visual representations of performance.

I have tried installing the externalquiz module and an error (copied below) complaining that table 'externalquiz_systems' doesn't exist, and indeed it is not defined in the db/install.xml file (just 'externalquiz_system' and 'externalquiz'). So I will have a play with it and see if I get anywhere.

I'll keep you posted on how I get on with it ; it seems like a very useful addition to moodle for anyone with existing online resources which won't be easily converted into activity modules.

Thanks for sharing!

Debug info: Table 'moodle_testing.mdl_externalquiz_systems' doesn't exist
SELECT * FROM mdl_externalquiz_systems ORDER BY name ASC
[array (
)]
Stack trace:
  • line 391 of /lib/dml/moodle_database.php: dml_read_exception thrown
  • line 790 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->query_end()
  • line 1097 of /lib/dml/moodle_database.php: call to mysqli_native_moodle_database->get_records_sql()
  • line 1046 of /lib/dml/moodle_database.php: call to moodle_database->get_records_select()
  • line 54 of /mod/externalquiz/mod_form.php: call to moodle_database->get_records()
  • line 152 of /lib/formslib.php: call to mod_externalquiz_mod_form->definition()
  • line 71 of /course/moodleform_mod.php: call to moodleform->moodleform()
  • line 219 of /course/modedit.php: call to moodleform_mod->moodleform_mod()
In reply to Joe Cape

Re: Using Quiz Overview Reports for stats on quizzes outside of Moodle (2.0)

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Oops. That looks like a bug. The table name should be consistent everywhere (and to follow the coding guidelines it should be externalquiz_systems). Thansk for spotting this. I'll get it investigated.

In reply to Tim Hunt

Re: Using Quiz Overview Reports for stats on quizzes outside of Moodle (2.0)

by Colin Chambers -

Sorry guys. My bad. We brought the table and field definitions inline with standard moodle but I obviously missed the install file. Oops.

A fixed module zip is attached.

In reply to Colin Chambers

Re: Using Quiz Overview Reports for stats on quizzes outside of Moodle (2.0)

by Joe Cape -
Picture of Plugin developers

This may be an idle thought, Moodle's naming convention for using plural or singular forms of names for tables seems slightly odd.

It seems like mdl_quiz follows the standard practice of using 'quiz' in the singular for storing many quizzes, because each record in the quiz table stores information about just one quiz; whereas other tables (mdl_quiz_attempts, mdl_quiz_grades, etc.) use the plural even though each record only relates to one attempt, grade, etc. Mostly, the main components of the Moodle system are given singular names but any entities that are used by these are pluralised, as above, but then mdl_modules is also plural (is this just inconsistent?). Ideally, I think its better to use singular except where a single record holds data about > 1 of what is being named (as in 'settings' ) and in this way it is best for each name to work as a metonym ('quiz' stands for all quizzes). If you go along with this, 'externalquiz_system' would also be preferable since no record ever relates to more than one system.

Given that you have a naming convention, its best to stick to it.

Like I said, just an idle thought.

The original module (included by Tim) was working after doing a find/replace to 'externalquiz_system' and Colin's new updated external quiz module also works.

When I say its working, I mean it sends people to the external web app from the activity module page, but I haven't tried syncing the grades with gradebook. I have tried creating some new quizzes, taking them as a student, and exporting the grades as XML to see what format it expects but this just gives:

<results batch="xml_export_1307698279"></results>

It is exporting correctly to excel.

Anyway, I've not tried the grade xml export feature before so I'm sure I'm just missing something.

So finally, just to clarify the idea behind using this module, I have some questions. 

How is the identity of the user passed from Moodle to the external quiz? Using the URL resource, the user id was simply passed in as an additional parameter, but I can't see what does that job using external_quiz.

Should the external web app update a specific xml file every time a student receives a grade for an activity, and will the document then be a list of all grades that students have ever been awarded? If not, how will there be a trigger for entries to be deleted if the external site cannot see when they have been moved across to Moodle ?

Thanks again for providing this module, and to Colin for updating it to Moodle 2.

In reply to Joe Cape

Re: Using Quiz Overview Reports for stats on quizzes outside of Moodle (2.0)

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

The think you need to know about the XML export is that it will only export students and gradebook columns that have an 'idnumber' set.

 

The Moodle table naming is sort-of logical. The rule is:

  • One-word table names are singular (user, course, quiz);
  • multi-word table names have the last word plural, the rest singular (course_modules, quiz_question_response_stats, quiz_attempts)

Except

  • Very old tables that have existed since before the rule was made (e.g. modules)
  • Places where the rule was intentionally broken for a good reason (e.g. files - file is a reserved word in some databases)
  • Places where people screwed up (e.g. quiz_report - I fixed that in Moodle 2.1)
In reply to Tim Hunt

Re: Using Quiz Overview Reports for stats on quizzes outside of Moodle (2.0)

by Joe Cape -
Picture of Plugin developers

Hi Tim,

Yes, I thought I only had to set idnumber for the activity, not the students as well. With that corrected, I get:

<results batch="xml_export_1307952802">

<result>

<assignment>2</assignment>

<student>2</student>

<score>-</score>

</result>

<result>

<assignment>2</assignment>

<student>3</student>

<score>6.67</score>

</result>

</results>

There is a glitch here, however, in that the grade for the first student is shown in gradebook, but not exported.

Also, I will need the detailed reporting on questions within the quiz so do you know if this is facilitated by the xml import/export and could be possible using the externalquiz module?

At least I feel happier about the table names now!

In reply to Joe Cape

Re: Using Quiz Overview Reports for stats on quizzes outside of Moodle (2.0)

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

If you want the individual question grades, you will need to add extra columns to the gradebook for them, each with their own idnumber. Import and export should then be able to process them.

Externalquiz does not currently support that, but you could probably extend the code.

In reply to Tim Hunt

Re: Using Quiz Overview Reports for stats on quizzes outside of Moodle (2.0)

by Joe Cape -
Picture of Plugin developers

Hi Tim,

I am trying to test this using the following setup.

I have created an xml file with the following content:

 

<results batch="xml_import_1308045559">

<result>

<state>"new"</state>

<assignment>1</assignment>

<student>4</student>

<score>7</score>

</result>

<result>

<state>"new"</state>

<assignment>1</assignment>

<student>5</student>

<score>8</score>

</result>

</results>

 

This has been placed in myexternalquiz/install.xml, corresponding to the Grade import URL defined in the Edit External Quiz settings.

I have not created a parameter check xml document.

I have set 'cron interval' to 1.

The above details in the import.xml file use the idnumbers that have been given to students and assignments (i.e. the ext. quiz).

In the module settings, 'Import grades automatically' is checked.

In Plugins/Activity modules/External quiz, I have set 'Cron email address' to my email address.

'Cron window start time' has been set to a time shortly in the future, for testing.

'Cron window end time' has been set to 5 minutes after 'Cron window start time'.

After waiting for the system time to reach 'Cron window start time' and then giving it a few minutes more, I have checked to see whether student with idnumber 4 & 5 had had grades imported for the quiz with idnumber 1 (an instance of the externalquiz module). This hadn't happened and I hadn't received any e-mail from the cron task.

Is there anything obvious that I'm missing?

Thanks.

Update: I have tried importing the XML from the same file using the grade administrator and that works as expected. It seems like the problem is that the cron job is not running at all.

In reply to Joe Cape

Re: Using Quiz Overview Reports for stats on quizzes outside of Moodle (2.0)

by Joe Cape -
Picture of Plugin developers

You can ignore the above.

I realized I had to run admin/cron.php,

After doing this, I get the message:

<b>Warning</b>:  file_get_contents(http://myexternalsite/import.xml1) [<a href='function.file-get-contents'>function.file-get-contents</a>]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in <b>/var/www/testing/moodle/mod/externalquiz/externalquiz_remote_data.php</b> on line <b>78</b><br />

So the first line 'file_get_contents(http://myexternalsite/import.xml1)' tells me that the idnumber of the externalquiz activity is being tacked on to the URL of the import data.

Does this mean that (i) I should be referencing a php file which contains xml data that is generated based on the ID number (ii) I should set 'Grade import URL' to a directory path, like 'myexternalquiz/import_xml/' rather than the xml file and then change my xml file from '/import.xml' to '/import_xml/1.xml'. ?

Thanks for any tips you can give!

In reply to Joe Cape

Re: Using Quiz Overview Reports for stats on quizzes outside of Moodle (2.0)

by Joe Cape -
Picture of Plugin developers

The cron script is working to update gradebook from the XML document when I change a line in externalquiz_remote_data.php (line 57):

$this->urlused = $this->extimporturl ; //. $this->testid

Since the test id is intended to be tacked on to the URL , I'm wondering how this was meant to work.

Should it (the Grade Import URL) be a php document with a dynamic variable (like 'import.php?testid=') which then generates XML content) ?

I'm going to keep working it out, so I know I'm piling post upon post here but very grateful if you can give some more hints about exactly what the intended set-up is so that I can start thinking about how to create the XML documents within my quiz and how to extend it to work for individual questions .

In reply to Joe Cape

Re: Using Quiz Overview Reports for stats on quizzes outside of Moodle (2.0)

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

The point is that externalquiz is designed to connect to an external quizzing system That is, a system that provides many different tests for many different courses.

So, when we request results from the other system, it assume that you need to pass the testid (idnumber), so that the other system knows which test to send back data for.

So yes, it needs to be a dynamic URL at the other end that can send back results for any test according to testid.

In reply to Tim Hunt

Re: Using Quiz Overview Reports for stats on quizzes outside of Moodle (2.0)

by Joe Cape -
Picture of Plugin developers

Could that URL just point to a PHP script that dynamically echoes the same contents as I have currently in the XML document?

In reply to Joe Cape

Re: Using Quiz Overview Reports for stats on quizzes outside of Moodle (2.0)

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I think that with Apache (and possibly other servers) if it is processing a URL of a static file like example.com/some/url.xml, then it will just ignore any query string. That is, example.com/some/url.xml?testid=whatever will serve exactly the same file.

In reply to Tim Hunt

Re: Using Quiz Overview Reports for stats on quizzes outside of Moodle (2.0)

by Joe Cape -
Picture of Plugin developers

The other queries I had were:

  1. What is the purpose of the parameters xml document and is this needed for the proper running of the module? ,
  2. How is the user identified once they are within the external system? ( I would assume that this is passed in as the id so that this can be used to generate the student field of the XML import doc; I can edit the link that is generated in the module view file to make sure this is passed in but I just wanted to check that this was also how it was intended to be used) and
  3. Where might I start looking for how to get a question-by-question report of performance in a quiz into gradebook?

Thanks again for the advice so far, it has been really useful.

Edit: I recently purchased the book "Moodle 1.9 Extension Development" by Jonathan Moore & Michael Churchward which features a chapter on creating gradebook reports. Do you know how much this should differ from doing the same for Moodle 2.0?

In reply to Joe Cape

Re: Using Quiz Overview Reports for stats on quizzes outside of Moodle (2.0)

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

1. The parameters XML bit is to do with some ou-specific stuff that checks certian settings against the 'correct' values in other databases. You should probably ignore it.

2. The OU has a good single-sign-on system. Therefore, in our case, when they get to the other system, they are logged in, and the system konws who they are.

3. Sorry, no time to answer this part right now. I don't have any great ideas. You just need to start learning about the Moodle gradebook.

Gradebook has not changed much in 2.0.

The other thing you could look at is the IMS LTI specification. This gives a reasonable overview: http://www.vimeo.com/8073453/

In reply to Tim Hunt

Re: Using Quiz Overview Reports for stats on quizzes outside of Moodle (2.0)

by Joe Cape -
Picture of Plugin developers

I've got a script that outputs XML as needed and the cron job gets the grades in this way so its working well. Thanks again for OU activity module.

In reply to Joe Cape

Re: Using Quiz Overview Reports for stats on quizzes outside of Moodle (2.0)

by John Fitzpatrick -

This ExternalQuiz is exatly what I need, and answers all my prayers.I've been reading these posts closely, but I cant figure how to get this working. If I seen an example I could probably worlk it out.

Would someone be able to give me sample settings for 'Grade import URL', 'Parameter check URL' under Configure external quiz systems, and how these relate to 'External quiz ID' in the activity?

Thanks

John

In reply to John Fitzpatrick

Re: Using Quiz Overview Reports for stats on quizzes outside of Moodle (2.0)

by John Fitzpatrick -

Hi Guys

I've now create a dynamic PHP page, where I pass the test ids and it gets the results from the mysql database & returns them in XML. However, I cant get it to work with the ExternalQuiz plugin. Does this look right:-

Moodle ExternalQuiz Config

 

Also, when I browse to 'http://labs.mysite.com/admin/cron.php' the import fails, and if I try browse to it again I get the message

Processing module function externalquiz_cron ...Starting External Quiz gradebook imports ...
External quiz already run today don't process again.

Will this only run once per day, and not at one minute intervals as config'd in the screenshot?

Thanks

John