Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Randomly select 2 out of 8 groups,then select 2 out of the rest 6 (V3.23.3)

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 5 months ago #208107 by Joffm
Hi, here is a prototype with a slightly different approach.

I used the property .gseq

Qcode.gseq the sequential number of the group, starting from 0 {gender.gseq}


gseq counts the number of a group starting with "0".
In your survey you start with 8 fixed groups (sequential number 0-7)
followed by 2 random groups (sequential number 8 and 9),
another fixed group (sequential number 10)
Now you want to display two more random groups which will have the sequential numbers 11 and 12.
So your relevance equation is QCode.gseq<13 And as QCode I used the code of the first question of the group.

Then I used a question of type text display to show the videos instead of showing them in the group description.
That's a personal attitude. I don't like to misuse this description. In my opinion it should be used for intenal use in teams to describe what this group is used for.

File Attachment:

File Name: limesurvey...1914.lss
File Size:45 KB


Some general things:
Of course you have to validate some questions. At the moment I am able to enter a year of birth like 1234.

And here is a script to force the input of a correct postcode (format: "1234 AB".
Code:
<script src="https://cdnjs.cloudflare.com/ajax/libs/inputmask/4.0.9/jquery.inputmask.bundle.min.js"></script> 
 
<script type="text/javascript" charset="utf-8">
  $(document).on('ready pjax:scriptcomplete',function(){ 
    $('#question{QID} input[type="text"]').inputmask({
      'mask': '9999 AA',
      'placeholder': '_',
      'removeMaskOnSubmit': false,
      'rightAlign': false,
    });
  });
</script>

All the best
Joffm


P.S.
Regarding your question about the thumbnails:
In my opinion you can do this by a real different solution.

In a question of type "short text" create four random numbers out of 8 (by javascript)
Result: "7246", meaning
1st group displays video 7.
2nd group displays video 2.
3rd group displays video 4.
4th group displays video 6.
So you will have only 4 fixed groups that show different videos.
Advantage: You know that video 7 and video 2 were displayed and are able to show these thumbnails in the comparison question.
Disadvantage: In the database and your exported results in the columns of group1 you will find the results of all videos. You have to restructure the data (e.g. by an EXCEL macro) according to the created random string.

But maybe somebodey else has an idea using the randomization by "randomization group name"

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 5 months ago #208112 by Joffm
And here your entire survey.
Remove the names of the video groups.

File Attachment:

File Name: limesurvey...3491.lss
File Size:458 KB


Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • CoraZHAO
  • CoraZHAO's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 5 months ago #208128 by CoraZHAO
Hi Joffm,
Good afternoon.
I've read your reply and I appriciate very much your help.
I'm flattered that you also checked for other problems in my survey.


Regarding the thumbnail issue, you mentioned that

Advantage: You know that video 7 and video 2 were displayed and are able to show these thumbnails in the comparison question.

Could you please explain more about how to achieve this or maybe there is a tutorial online? I searched the manual but maybe with inaccurate keywords, thus I didn't find any solution yet.I'm sorry I have very limited knowledge about the lime system.

At this moment I have no access to importing .lss file and I asked my administrator to enable the function. Hopefully she will react next monday.

Thank you again for your help.

Have a nice weekend!

Best,
ZHAO
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 5 months ago #208130 by Joffm
Hi,
I will create a sample survey to show this.

It is really easy to do, but a bit difficult to explain.
Better you see it.



Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 5 months ago #208158 by Joffm
Hi,
there is a fundamental mistake in your survey design.
Maybe because a lack of information. I did not realize that the fixed question after the first random ones refer to these.
But with this approach ("randomization group name") you have no information at all which video was displayed first which was second, and so on.

But in your case this is a crucial thing.

So, what to do?
You have to define the four displayed videos and their order, that this information is stored in your database.
To do this we use a question of type "short text" (I called it "Q0" and put it into your first group) with this javascript snippet
Code:
<script type="text/javascript" charset="utf-8">
 
function shuffle(array) {
  var currentIndex = array.length, temporaryValue, randomIndex;
 
  // While there remain elements to shuffle...
  while (0 !== currentIndex) {
 
    // Pick a remaining element...
    randomIndex = Math.floor(Math.random() * currentIndex);
    currentIndex -= 1;
 
    // And swap it with the current element.
    temporaryValue = array[currentIndex];
    array[currentIndex] = array[randomIndex];
    array[randomIndex] = temporaryValue;
  }
 
  return array;
}
 
 
  $(document).on('ready pjax:scriptcomplete',function(){
// Fill the array
      var arr = [1,2,3,4,5,6,7,8];
      arr = shuffle(arr);
      anumbers = arr.slice(0,4).join('');
      $('#question{QID} input[type="text"]').val(anumbers);
      $('#question{QID}').hide();
   });
</script>

To explain:
1. We create an array and fill it with the numbers 1-8
2. We shuffle this array
3. We take the first four elements and join them to a string
4. This string is piped into the question answer text.
5. We hide this question
You may show this question while testing by commenting this line
// $('#question{QID}').hide();

You will get something like "4275".

Now we have to define which videos are displayed.
Therefore I put 4 (hidden) questions of type "equation" into the second group. (I called them "Scene1", "Scene2",...)
Knowing that the video call only depends on the embed code I used this equation
{if(substr(Q0,0,1)==1,"Qw9iYRvGgws",if(substr(Q0,0,1)==2,"ldw3Kf7il9Y",if(substr(Q0,0,1)==3,"HhXjOJyCAuw",if(substr(Q0,0,1)==4,"99fnWaaiY2w",if(substr(Q0,0,1)==5,"i2UwJZ-B_J8",if(substr(Q0,0,1)==6,"CDoLmesCKfo",if(substr(Q0,0,1)==7,"Tm1Fwm3qKkg","bxFgnXDHF3w")))))))}

Meaning: If the first character of the string (you remember "4275") substr(Q0,0,1) is equal 1 the code is "Qw9iYRvGgws", else if the first character is equal 2 the code is "ldw3Kf7il9Y",...
Because the first character is 4 the code will be "99fnWaaiY2w".

The same for the second character - the second video, the third ,...
About the IF-statement and nested IFs please refer to the manual.

Now your questions.
You want to display these four videos. So you only need four groups.
G1 and G2, the first two.
Then the comparison question.
G3 and G4, the last two.
And again a comparison question.

Because you saved the embed code into the variables "Scene1", "Scene2", ...
the embed code of your first video is this:
Code:
src="https://www.youtube.com/embed/{Scene1}?rel=0"
You see that the embedcode is entered by the variable {Scene1}

Now you repeat this for the other video questions.

And in the comparison question you would like to display thumbnails of the two videos displayed before.
The best is to name your thumbnails
"thumb1.jpg", "thumb2.jpg", "thumb3.jpg", ...

And what do you display in the first comparison question?
Yes, the thumbnails that match the first two characters of the string.
In our example you want to display "thumb4.jpg" and "thumb2.jpg"
This you can do by
Code:
<div style="float:left"><img src="http://www.myServer.de/myPath/thumb{substr(Q0,0,1)}.jpg" /></div>
 
<div style="float:right"><img src="http://www.myServer.de/myPath/thumb{substr(Q0,1,1)}.jpg" /></div>
Again we use our string - the first character substr(Q0,0,1) and the second substr(Q0,1,1)

Remember: the function "substr" starts with the index "0".

In this example the images are called "Hamburg-Ballett_1.jpg", "Hamburg-Ballett_2.jpg", "Hamburg-Ballett_3.jpg", ...
That's all.
Now you know exactly which video was displayed when.
Because each video may be displayed at each of the four places you will have to restructure this to calculate means or so of the statement questions of each video.
By the way: You used codes like "EA1", "EA2", "EA3",... How do you think you will be able to calculate a mean?
The mean of "EA1" and "EA4" is NOT "EA2,5", believe me.
So you should use numerical codes.

Here your restructured survey.

File Attachment:

File Name: Greening_new.lss
File Size:378 KB


I additionally changed the following:
1. D1 -> changed to an array ( I don't know why you use a 5-point scale and have to explain the answer options before)
2. The first video question -> removed the explanationj of the scale and put it into the array header

But there are many, many things to improve
Mainly restructure the survey.
26 questions on one page ("Personal information") is a horrible thing, especially because you hop from one topic to the other and back.
Usually we say "one question per page".

Please, read this

This browser does not support PDFs. Please download the PDF to view it: Download PDF



Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: CoraZHAO
The topic has been locked.
  • CoraZHAO
  • CoraZHAO's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 5 months ago #208188 by CoraZHAO
Hi Joffm,
I appreciate it ! You are excellent! You’ve pointed out the vital problem in my survey.
I feel myself such a poor survey designer...
Your explanation is very detailed, I've read it carefully. I think the whole logic is clear for me, though I have little knowledge of java.

My administrator just imported the last two .lss files you shared last week.
And I'm still waiting for her to import this one. Then I can check the survey and follow your instruction step by step. Such as testing the random groups, add images and revise the question code…

I will get to you as soon as I've tried the approach by myself. It is very likely I will have some questions about javascript. I will try my best to handle it.



Best,
Yuwen.
The topic has been locked.
  • CoraZHAO
  • CoraZHAO's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 5 months ago #208226 by CoraZHAO
Dear Joffm,

I've tried the solution and it works perfectly.
Your instruction is also very detailed , I followed it and found you've already done all the changes even some minor revision.
I appreciate it very much.

I uploaded my thumbnails and changed the link in script.
Looks nice!



One small thing I'd like to ask,
I found once we go back to the 'Declaration of consent' page which include the "Q0" for define the four displayed video, the 4 numbers will be recalculated thus the videos change.
Although the chance are very little that respondents go back to the very front after watching videos. I was still wondering if there is a way to disable the backward navigation only for the first group?
I saw in settings--->Presentation & navigation settings--->Allow backward navigation which can affect the whole survey. But for other groups it's better to enable backward.


Thank you again, I learnt a lot from your suggestions!

Best,
Yuwen
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 5 months ago - 3 years 5 months ago #208227 by Joffm
Hi, Yuwen,

I found once we go back to the 'Declaration of consent' page which include the "Q0" for define the four displayed video, the 4 numbers will be recalculated thus the videos change.


Yes, this is true.
Do this:

1. Rename question "Q0" to "Q00".

2. At the start of the second group create a question of type "eqation" which you call "Q0". (Now we use this to define the videos, and fill it once with the content of Q00).
Of course you hide this question "Always hide... ON".
In the question text enter {if(is_empty(Q0),Q00,Q0)}
Meaning: If this question - Q0 - is still empty, fill it with the content of Q00, else let the old value.

Now Q0 will not change anymore.

Joffm

By the way:
You copied your question text from Word or another text processing program, didn't you?
Have a look at the source code of these texts - rather terrible. You copy all the HTML garbage.
Code:
<p class="MsoCommentText" style="margin-top: 0in; margin-right: 0in; margin-bottom: 8pt;"><strong><span style="font-size:20px;">​​​​​​</span><span style="font-size:20px;"><span style="font-family:Times New Roman,Times,serif;">And this is the question text</span></span></strong></p>
<br /> 
Don't do this. To get a certain styling of the question text, use the theme.

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 3 years 5 months ago by Joffm.
The following user(s) said Thank You: CoraZHAO
The topic has been locked.
  • CoraZHAO
  • CoraZHAO's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 3 months ago #210147 by CoraZHAO
Dear Joffm,
Thanks to your help, our first survey went quite smoothly!

Now I'm working on the second survey with the same structure.

However when I tried to add Q00 and edit the Dutch version.
I found a very werid and headache issue. That is, once I opened the questions (in English version)which have iframe videos, even if I didn't change anything and just click 'save'. All codes inserted before changed and can't work porperly.


e.g. the correct code for randomly show video No.2
Code:
<iframe allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen="" frameborder="0" height="600" src="https://www.youtube.com/embed/{Scene2}?rel=0&amp;amp;autoplay=1" width="1100"></iframe>

Changed into
Code:
{Scene2}?rel=0&amp;autoplay=1" width="1100">
after I click 'save'.

So I tried to import these questions again and it works well, as long as I did't edit and save them.

But the Dutch version still need to be add so I must edit these questions.

To figure out what's going on. I also tried the 'insert youtube video' button in my editor and add a new video. Once I clicked save. The same issue appeard ( all codes changed).


Even worse,
Sourcecode in Question'Q0' for generating random numbers also crashed. The original code is,
Code:
<script type="text/javascript" charset="utf-8">
 
function shuffle(array) {
  var currentIndex = array.length, temporaryValue, randomIndex;
 
  // While there remain elements to shuffle...
  while (0 !== currentIndex) {
 
    // Pick a remaining element...
    randomIndex = Math.floor(Math.random() * currentIndex);
    currentIndex -= 1;
 
    // And swap it with the current element.
    temporaryValue = array[currentIndex];
    array[currentIndex] = array[randomIndex];
    array[randomIndex] = temporaryValue;
  }
 
  return array;
}
 
 
  $(document).on('ready pjax:scriptcomplete',function(){
// Fill the array
      var arr = [1,2,3,4,5,6,7,8];
      arr = shuffle(arr);
      anumbers = arr.slice(0,4).join('');
      $('#question{QID} input[type="text"]').val(anumbers);
      $('#question{QID}').hide();
   });
</script>

Now it looks like,
Code:
QID input[type="text"]').val(anumbers); $('#questionQID').hide(); });

I tried to fix it by inserting the correct code again many times. But once I clicked 'save'. it will change into the short and wrong code....


Another survey with exactly the same code works just fine 3 weeks ago. (V3.23.3)
Same PC, same browser, but a higher version of Limesurvey.( V3.25.4.)

I think it is something to do with the Lime editor or iframe update since it never happened before.

I'll be very appriciated if you have any suggetions!

Best,
Yuwen.
The topic has been locked.
  • CoraZHAO
  • CoraZHAO's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 3 months ago #210149 by CoraZHAO
Since it could be an editor issue other people may also run into,
I also reported it here
forums.limesurvey.org/forum/design-issue...icking-save-v-3-25-4

Hope we can figure it out together! T.T


Best regards,
Yuwen
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 3 months ago #210151 by tpartner
Do not double-post.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • CoraZHAO
  • CoraZHAO's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 3 months ago #210242 by CoraZHAO
I apologize. It was because of XSS. Problem solved
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose