Odd ordering of responses

Odd ordering of responses

by Jenny Gray -
Number of replies: 16
I've noticed something odd when viewing the responses for my questionnaires. I have 3 questions, and for all of them the user picks from radio buttons labelled "Very", "Fairly", "Not very" and "Not at all".

When we look at the results in the responses pane, the options are not listed in the same order across all 3 questions - take a look particularly at question 3. http://openlearn.open.ac.uk/mod/questionnaire/report.php?instance=1367&sid=1364&action=vall

This makes it much harder to compare the responses. We realise that the ones that no user have chosen aren't displayed at all, that's fine. I wonder if this is a postgres issue? Postgres doesn't automatically return rows from the database in ID order.

I haven't had a look at the code because I'm not entirely sure where to dig into for this little piece of functionality, but if some-one could point me in the right direction, I'm happy to investigate further.

Jenny

Average of ratings: -
In reply to Jenny Gray

Re: Odd ordering of responses

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Hi Jenny,

1- I am surprised that you are not using the obvious Rate/Scale question type for your questionnaire. Why are you using radio buttons instead?

2- Anyway, when I reproduce your 3 radio button questions on my moodle-questionnaire version 1.9 (latest available) I am not getting the same as you are (see attached screenshot).

I hope all your "possible answers" are arranged in this logical order:

  • Not at all
  • Not very
  • Fairly
  • Very

Joseph

Attachment image00.jpg
In reply to Joseph Rézeau

Re: Odd ordering of responses

by Jenny Gray -
1 - I don't remember any more! We've had the questionnaire for a couple of years. I guess I must have had my reasons at the time.

2 - OK that's odd because yes they are arranged in that order. I'll have to dig a bit deeper. Can you point me at the right bit of code for where it gets them out of the database and where the display is called?
In reply to Jenny Gray

Re: Odd ordering of responses

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
> Can you point me at the right bit of code etc.

Sorry, that would take me quite some time which I can't spare right now. How about upgrading to the latest 1.9 version? that should solve the problem.

Joseph

In reply to Joseph Rézeau

Re: Odd ordering of responses

by Jenny Gray -
OK, if you don't know the right area off the top of your head, I'll just dig in and look for it.

I'll take a look at the latest code too and see if that will help - thanks.
In reply to Jenny Gray

Re: Odd ordering of responses

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Jenny, one thing to look out for is is that seemingly MySQL almost always returns records in the order they were inserted into the database, while Postgres is much more likely to return them in an arbitrary order. (Must be a difference in their inner workings.) I remember in the quiz we found some bugs where SQL queries were missing ORDER BY clauses, but people had been running for years on MySQL without being bit by the bug. We were sad
In reply to Tim Hunt

Re: Odd ordering of responses

by Jenny Gray -
Hi Tim, nice to hear from you!

I think you're probably right about the ORDER BY being missing. Now I just need to find the time to hunt out the right part of the code.
In reply to Jenny Gray

Re: Odd ordering of responses

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
By the way, Jenny, are you actually using Postgres rather than mySql?
Tim, how can a plugin developer track bugs which are linked to the use of one database rather than the other if that developer does not have access to both mySql and postgres (plus a couple of other databases, I expect)?mixed
In reply to Joseph Rézeau

Re: Odd ordering of responses

by Jenny Gray -
Yes, here at the OU we are currently running on Postgres.

As Tim mentioned we've found places in the past where things hadn't been tested under Postgres and worked perfectly well under MySQL.

Postgres is open-source and not a difficult install, so you could just set up another database to connect to for occasional testing. But otherwise, like many developers, its about the community helping out with Postgres testing (or if we offer new stuff, with the MySQL testing!).
In reply to Jenny Gray

Re: Odd ordering of responses

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Joseph, I know you asked me, but I don't have anything to add to Jenny's reply.
In reply to Jenny Gray

Re: Odd ordering of responses

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Jenny > Postgres is open-source and not a difficult install...

Well, I am finding Postgres not all that easy to install.sad

On the Moodle site there is no easy to use "package" for Windows including postgres, only mysql...

I finally managed to install Postgres (8.3.5), Apache 2 which goes with it and phpPgAdmin on my Windows XP (local) machine. Unfortunately I am now stumped by 2 (maybe linked problems).

a) In phpPgAdmin I cannot log in to PostgreSQL; it wants a username and password which I do not know how to provide; I would prefer to log in without a password (since this is only on my local machine); I have looked at the documentation, I have put the necessary "trust" lines in pg_hba.conf but to no avail...

b) When I try to install moodle (1.9), I can see the initial install screen, I fill in the address of the moodledata folder, click on Next and after some time, get only a blank page.

Jenny (and Tim) do you know of the existence of step-by-step instructions for installing moodle with postgres on Windows?

Joseph

In reply to Joseph Rézeau

Re: Odd ordering of responses

by Jenny Gray -
a) try using username and password both as "postgres"

b) there must be some kind of fatal error that's not being output. Can you override the debugging level (which is off by default for install) to see what's going on.

I do have postgres running on windows on my laptop, but we usually use linux for our real servers here. I don't remember following any specific instructions for the install though, sorry.
In reply to Jenny Gray

Re: Odd ordering of responses

by James Brisland -
Hi Everyone,

I believe I have found a fix for this issue.

In the get_response_single_results() method of the questionnaire_question class in /mod/questionnaire/questiontypes/questiontypes.class.php I have added an order by id.


-- BEFORE --
// JR added qc.id to preserve original choices ordering
$sql = 'SELECT qc.id, qc.content, COUNT(rt.response_id) AS num '.
'FROM '.$CFG->prefix.'questionnaire_quest_choice qc, '.
$CFG->prefix.'questionnaire_'.$this->response_table.' rt '.
'WHERE qc.question_id='.$this->id.' AND qc.content NOT LIKE \'!other%\' AND '.
'rt.question_id=qc.question_id AND rt.choice_id=qc.id'.$ridstr.' '.
'GROUP BY qc.id,qc.content';

$rows = get_records_sql($sql);

// handle 'other...'
$sql = 'SELECT rt.response, qc.content , COUNT( rt.response_id ) AS num '.
'FROM '.$CFG->prefix.'questionnaire_response_other rt, '.
$CFG->prefix.'questionnaire_quest_choice qc '.
'WHERE rt.question_id='.$this->id.' AND rt.choice_id=qc.id'.$ridstr.' '.
' GROUP BY rt.response,qc.content';
------------

-- AFTER --
// JR added qc.id to preserve original choices ordering
$sql = 'SELECT qc.id, qc.content, COUNT(rt.response_id) AS num '.
'FROM '.$CFG->prefix.'questionnaire_quest_choice qc, '.
$CFG->prefix.'questionnaire_'.$this->response_table.' rt '.
'WHERE qc.question_id='.$this->id.' AND qc.content NOT LIKE \'!other%\' AND '.
'rt.question_id=qc.question_id AND rt.choice_id=qc.id'.$ridstr.' '.
'GROUP BY qc.id,qc.content ORDER BY qc.id';

$rows = get_records_sql($sql);

// handle 'other...'
$sql = 'SELECT rt.response, qc.content , COUNT( rt.response_id ) AS num '.
'FROM '.$CFG->prefix.'questionnaire_response_other rt, '.
$CFG->prefix.'questionnaire_quest_choice qc '.
'WHERE rt.question_id='.$this->id.' AND rt.choice_id=qc.id'.$ridstr.' '.
' GROUP BY rt.response,qc.content,qc.id ORDER BY qc.id';
-----------

The only thing I'm not sure about is if this fix will need to be done in other areas for different question types. I don't know the questionnaire module well at all!

If you want to compare the fix to the old one go to the following URL's

OLD: http://openlearn.open.ac.uk/mod/questionnaire/report.php?instance=1367&sid=1364&action=vall

NEW: http://openlearnacct.open.ac.uk/mod/questionnaire/report.php?instance=1367&sid=1364&action=vall

Also I don't have commit access to the contrib CVS area, do you want this committing back? If so I will pass it onto Jenny.
In reply to James Brisland

Re: Odd ordering of responses

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Hi James,
Would you please re-post full details of this bug and your fix to the moodle bug tracker so that either Mike or myself can check it and commit the necessary changes to contrib as soon as possible?
If possible attach your fix as a PATCH to your bug report.
Thanks in advance,
Joseph
bug tracker page for the Questionnaire module

In reply to Joseph Rézeau

Re: Odd ordering of responses

by James Brisland -
Hi Joseph,

Bug re-created @ http://tracker.moodle.org/browse/CONTRIB-877

Patch is attached to the bug.

Hopefully that will be everything you need to get the fix in.

If there is anything else you need just shout.