marcusgreen / moodle-qtype_wordselect

langHighlight words by clicking e.g. select all nouns in this sentence

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Word Select question when attempted, the Response history displays the submitted words in random order and without delimiters

AnupamaSarjoshi opened this issue · comments

Hi Marcus,

We have seen the following issue. Could you please have a look? Thanks.

Describe the bug
When the WordSelect question is attempted as Admin, the Response history shows the submitted words in Random order and also there is no delimiter around the words to separate each one of them. This seems to be confusing when the submitted words have punctuation marks in them.

To Reproduce
Steps to reproduce the behaviour:

  1. Login as Admin. Go to 'Question bank' and create a new Wordselect question
  2. Preview and set the 'Response history' to Shown.
  3. Attempt the question and select some words and click on 'Submit and finish'
  4. Notice that in the Response history, the submitted words are displayed in Random order and also there is no delimiter around the words to separate each one of them.

Expected behaviour
In the Response history the submitted words should be in order to the question text and also the words should be displayed within braces { } to clearly separate out the words selected.

Screenshots
image

Desktop (please complete the following information):

  • OS: [e.g. iOS] Windows
  • Browser Chrome
  • Wordselect Version: 2.48 on Moodle 3.11

Just to be certain, can you confirm that this issue only shows up for someone with site admin role?

Am about to attempt to reproduce it locally

Thanks Marcus. Though I haven't tried, I don't think it is specific to site admin role. Anyone with the capability to access Response history probably will see the same

@AnupamaSarjoshi I would like to try to reproduce your problem, but...
You forgot to mention a) the instructions given to the student ("click such and such words")
b) if your question uses the Multiword mode
c) you forgot to mention the "How questions behave" options you are using
Could you please export and attach your question to your reply? Thanks!

I think the question is taken directly from the included examples. I will add instructions in the next release... Good catch on the question behaviour, though I don't think it will be a decider (could be wrong). It seems a strange one. Hope to look further this evening.

Just tested this locally on my Moodle 4.0.1. Works as expected, The submitted words are in the same order as in the text. Agree with @AnupamaSarjoshi however that some kind of separator between those submitted words (or groups of words) would be useful

I wonder if however the core ddwtos question does it might be an inspiration...

My first attempt
image

I need confirmation of what question behaviour is being used, I suspect from the word submit at the start that it is Deferred feedback. I can see the code that generates the output in the summarise_response method of question.php

public function summarise_response(array $response) {

Braces could be added like this

        $summary .= "{ " . $allwords[substr($index, 1)]->get_without_delim() . "} ";

With reference to word order, I cannot reproduce what you are seeing. The order is probably determined from how the words are returned from

    $allwords = $this->get_words();

But at the moment I cannot figure out how it would be returned in an order other than how it appears in the original text.

I can't work this out either, but I can confirm we are seeing this.

I don't believe the behaviour matters. I just reproduced the issue by previewing Anu's question on our system, and only afterwards notice that was using Interactive with multiple tries.

In case it helps, here is the question: (Github does not like XML files, so I had to rename to add .txt.)
questions-U101-20B-WordSelect Reading Comprehension-20220622-1654.xml.txt

There were bugs like this in the past in some core qtypes. Baiscally, when a DB server is new, then in theory, the order of results from any query will be random unless you specify an order-by. However, when DBs are new then typically rows are returned in id order at first, and then with time start getting more random. So, that might possibly explain this hard-to-reproduce bug ... except I just quickly looked at the code, and from what I can see, all the queries have an order-by id. (Example old bugs: MDL-27394 or commit f07d1d319716a0b381ece29435c72999a798f778 - so old, it came before the tracker.)

More debugging needed, but I am out of time for today.

Thanks for the feedback Tim. The behaviour thing was partly to ensure I was seeing exactly the same text before it showed the words, but as you suggest, that is probably not relevant. I was wondering about the order of stuff returned from the db, but I couldn't see how that would happen in this case. I will look further.

I think the the order of the words returned is determined somewhere after here

if (strpos($questiontextnodelim, $l . $l) !== false) {

Possibly on the line that reads
$matches = preg_split($fieldregex, $questiontextnodelim, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);

But the order of things returned from preg_split is always the order they were in the original string, so it is not clear how this could lead to the problem. It really is a mystery.

That was my assumption. I would be happier if I could reproduce it. I now want to set one up with exactly the same version of PHP and Postgress, which of course should/could not make any difference whatsoever but you never know (even when you feel you do know)

I am closing this as I don't have the time to work towards a fix. If anyone comes up with a code fix I will be happy to review it.