Show survey data total

More
1 month 3 days ago - 1 month 3 days ago #173940 by flasher44
flasher44 created the topic: Show survey data total
Hello, I need help.

I would like to display at the end of the survey for each person it's total of points from it's first entry.

For example :

Entry 1:

Question : how many frog seen ?
Answer : 2

Question : how many bird seen ?
Answer : 7


Displayed at the end of the survey :

Total frogs : 2
Total Bird : 7

Total animals : 9


Entry 2

Question : how many frog seen ?
Answer : 5

Question : how many bird seen ?
Answer : 12


Displayed at the end of the survey :

Total frogs : 7
Total Bird : 21

Total animals : 28


I already created the survey, but I dont know to use in the text element box, {FROGS.shown}, only display the number just entered not all number of FROGS from the begining.


Thanks for your help...
Last Edit: 1 month 3 days ago by flasher44.

Please Log in or Create an account to join the conversation.

More
1 month 3 days ago #173948 by jelo
jelo replied the topic: Show survey data total
That would mean you need access to the responses of all respondents at the end of each survey.
ExpressionManager (will become ExpressionScript) isn't having access to the responses of all respondents. The common approach is via an external script which accesses the database.

What version of LimeSurvey is used? Perhaps someone can provide you a workaround.

Are you a student conducting a survey? If yes, tell me why you use LimeSurvey?
www.limesurvey.org/forum/development/116...y-you-use-limesurvey

Please Log in or Create an account to join the conversation.

More
1 month 3 days ago #173963 by flasher44
flasher44 replied the topic: Show survey data total
I'm using V3.6.1-0073, could help me with this kind of script, I'm unable to do it myself ?

Please Log in or Create an account to join the conversation.

More
1 month 2 days ago #173989 by holch
holch replied the topic: Show survey data total
Is this one questionnaire with different sections (one response) or would this be respondents filling the questionnaire on different occasions (different responses):

In the first case, you can access all answers given in the same response via Expression Manager and add things up in an equation type question.

In the second case: Not possible, because you can't access the answers from other responses/filled questionnaires.

I'm not a LimeSurvey GmbH member. I answer at the LimeSurvey forum in my spare time. No support via private message.
Some helpful links: Manual (EN) | Question Types | Workarounds

Please Log in or Create an account to join the conversation.

More
1 month 2 days ago #174022 by flasher44
flasher44 replied the topic: Show survey data total
The respondents fill the questionnaire every day. So there is no solution ?

Please Log in or Create an account to join the conversation.

More
1 month 2 days ago #174026 by jelo
jelo replied the topic: Show survey data total
LimeSurvey isn't offering the functionality out of the box.
There might be a plugin or a workaround (which would involve coding with external scripts), but I'm not aware of one.

Are you a student conducting a survey? If yes, tell me why you use LimeSurvey?
www.limesurvey.org/forum/development/116...y-you-use-limesurvey

Please Log in or Create an account to join the conversation.

More
1 month 2 days ago #174028 by LouisGac
LouisGac replied the topic: Show survey data total
It should be possible to do via a custom survey theme, and by adding the dynamic survey model object inside the twig sand box (via internal.php).

Please Log in or Create an account to join the conversation.

More
1 month 2 days ago #174035 by LouisGac
LouisGac replied the topic: Show survey data total
ok I did it for you:
github.com/LimeSurvey/LimeSurvey/commit/...bda5204cdcc8750efe16

This feature has been requested a bunch of times in the forum, and it's very easy to add, so here we go. Also, it shows what can be done via twig and custom functions.

It will be available in next release, you can still implement the commit in your local version.

To use it: turn on quota, public statistics, then in submit.twig view add something like:
{% set aResponses = getAllTokenAnswers(aSurveyInfo.sid) %}
  {{ dump(aResponses) }}

You'll see that aResponses contains all the responses of the current token.
Just loop throught it to do what ever you want.
The following user(s) said Thank You: tpartner

Please Log in or Create an account to join the conversation.

More
1 month 2 days ago #174051 by flasher44
flasher44 replied the topic: Show survey data total
Thank you LOuis, but I would need a step by step explanation, I don't know what to do with your coding …

Sorry ;)

Please Log in or Create an account to join the conversation.

More
1 month 1 day ago - 1 month 1 day ago #174083 by tpartner
tpartner replied the topic: Show survey data total
Some assumptions for the example below:
  • You are using tokens for the survey.
  • Q1 has, for example, an SGQA identifier of "111111X22X33".
  • You have extended a theme .

In the theme editor, select the Completed screen, then edit the submit.twig part file, adding code something like below and save it to your local theme.


<div> 
    {% set aResponses = getAllTokenAnswers(aSurveyInfo.sid) %}
    {% set responseSum = 0 %}
    {% set responseCount = 0 %}
    {% set responseToken = '' %}
 
    {% for response in aResponses %}
        {% if (response['111111X22X33'] != '') %}
            {% set responseSum = responseSum + response['111111X22X33']|number_format %}
            {% set responseCount = responseCount + 1 %}
        {% endif %}
 
        {% if (loop.index == 1) %}
            {% set responseToken = response['token'] %}
        {% endif %}
    {% endfor %}
 
    {% if (responseCount > 0) %}
        There are {{ responseCount }} valid responses for Q1 with token value {{ responseToken }}.
        <br />
        The sum of all valid responses  is {{ responseSum }}.
        <br />
        The average of all valid responses is {{ (responseSum/responseCount) }}.
    {% endif %}
</div>

After several responses by a given token, you should see something like this in the completed screen.


Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
Last Edit: 1 month 1 day ago by tpartner. Reason: Fix bug in code

Please Log in or Create an account to join the conversation.

More
1 month 1 day ago #174084 by tpartner
tpartner replied the topic: Show survey data total
LouisGac, would it be possible to get all responses, regardless of token? If, for example, you wanted a total for a question answered by all respondents.

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in or Create an account to join the conversation.

More
1 month 1 day ago #174085 by jelo
jelo replied the topic: Show survey data total
Nice and no modifications to corefiles.

Are you a student conducting a survey? If yes, tell me why you use LimeSurvey?
www.limesurvey.org/forum/development/116...y-you-use-limesurvey

Please Log in or Create an account to join the conversation.

More
1 month 1 day ago #174086 by tpartner
tpartner replied the topic: Show survey data total
LouisGac, sorry, never mind, I found it

getAllAnswers(aSurveyInfo.sid)

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in or Create an account to join the conversation.

More
1 month 1 day ago - 1 month 1 day ago #174092 by flasher44
flasher44 replied the topic: Show survey data total
Thanks Tpartner,

I've an error "Unknown "getAllTokenAnswers" function."


So just to be sure, I remove all the code on the completed page and I paste yours, correct ?
Attachments:
Last Edit: 1 month 1 day ago by flasher44.

Please Log in or Create an account to join the conversation.

More
1 month 1 day ago #174094 by Joffm
Joffm replied the topic: Show survey data total
Hi,
really, now there is only this code snippet in "submit.twig"?
This is not correct.
As you see in the screenshot, this code adds a div below the line "print your answers".

So it has to be inserted there in the twig file.

In the twig file there are comments to explain each block of code, like:
"Assessments"
"Link to print answers preview"
"Link to public statistics"

And you also see that each of these blocks contains a <div> ... </div> surrounded by an if-statement.

This means you insert the provided snippet somewhere between or after these blocks.

Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!