Welcome to the LimeSurvey Community Forum

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

Limesurvey API download Group timings

More
3 weeks 4 days ago #271274 by BBSR-SR5
Please help us help you and fill where relevant:
Your LimeSurvey version:  LimeSurvey Cloud Version 6.15.5
Own server or LimeSurvey hosting: Cloud
Survey theme/template: Irrelevant
==================
Hello everyone, 
I'm trying to export group timings via the API function export_responses. I've seen this older thread , but unfortunately I don't quite understand how you move from the group ID (like "216") to a cryptic field name like "159677X490X12345time" in the expamle. I've been trying list_groups or even get_group_properties to see if it was hidden there somewhere, but didn't find anything.

I really need the group timings so I can see if a question was even accessed.

Thank you :)

Please Log in to join the conversation.

More
3 weeks 4 days ago #271276 by tpartner

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: BBSR-SR5

Please Log in to join the conversation.

More
3 weeks 4 days ago #271277 by BBSR-SR5
Thank you, that helps to explain it :)

I'm still a bit confused why this has a question number if I'm retrieving the group timings.

"159677X490X12345time"

Following the SGQA schema this should be survey "159677", group "490", question "12345" answer "time". Can I just take any question number from the group or does it need to be a specific one?

Please Log in to join the conversation.

More
3 weeks 4 days ago #271282 by holch
My bet is that there is no such thing as "group timing". The group timing is probably just the time of the last question in the group. But I am just guessing here. Let's wait and see what others have to say.

Help us to help you!
  • Provide your LS version and where it is installed (own server, uni/employer, SaaS hosting, etc.).
  • Always provide a LSS file (not LSQ or LSG).
Note: I answer at this forum in my spare time, I'm not a LimeSurvey GmbH employee.

Please Log in to join the conversation.

More
3 weeks 4 days ago #271284 by tpartner
Export the some data and see what you have as column names. Those should be the identifiers used in the API call.

Cheers,
Tony Partner

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

Please Log in to join the conversation.

More
3 weeks 1 day ago - 3 weeks 1 day ago #271330 by BBSR-SR5

Export the some data and see what you have as column names. Those should be the identifiers used in the API call.
Hm, I tried that but it doesn't seem to work. If I export without setting fields, I'm getting something like this as a json:
Code:
"id": 11, "submitdate": null, "lastpage": 42, "startlanguage": "de", "seed": "786809226", "token": "txxxxx", "startdate": "2024-04-30 13:32:52", "datestamp": "2024-04-30 13:43:00", "SH01[x]": "10",

If I try by actually defining the fields I only get null values for the answers and the timings (the other fields still work):
Code:
"id": 11, "submitdate": null, "lastpage": 42, "startlanguage": "de", "seed": "786809226", "token": "txxxxx", "startdate": "2024-04-30 13:32:52", "datestamp": "2024-04-30 13:43:00", "SH01[x]": null, "326961X209X1790time": null,
 Any idea why this doesn't seem to work?
Last edit: 3 weeks 1 day ago by BBSR-SR5.

Please Log in to join the conversation.

More
3 weeks 1 day ago #271331 by tpartner
Export the data to Excel via the GUI not via the API.

Cheers,
Tony Partner

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

Please Log in to join the conversation.

More
3 weeks 1 day ago - 3 weeks 1 day ago #271333 by Joffm
Hi,
how is your survey displayed ("group by group" or "question by question")?
If you display group wise there are no question timings and viceversa.

But as long as you only show some small snippets of your code, it's difficult to answer.

So, please, create a small prototype, send the lss export and your script to export this.

Joffm

BTW:
You mentioned this
[url] forums.limesurvey.org/forum/can-i-do-thi...with-json-rpc#225030 [/url]
Maybe you got confused.
The shown script is not the script that produces the output in the screenshot.

The first - and most important - statement is:
You have to define all fields you want to export.

and an explanation of the - as you said before - cryptic codes
These time fields with SGQ-syntax.

And at the screenshot there is written
(only timing of groups) 

Just to show that you can do both (depending on the mode of display)

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 3 weeks 1 day ago by Joffm.

Please Log in to join the conversation.

More
3 weeks 1 day ago #271335 by Joffm
Hi,
I did a small test - with a small survey.
Displayed "group bey group"
And with this script
Code:
$surveyResponses = $myJSONRPCClient->export_responses(
    $sessionKey,
    $survey_id,
    'json', // Document type : pdf,csv,xls,doc,json
    null, // Language code : null : default from survey
    'complete', // Stautus complete|incomplete|all
    NULL, // Heading : code|full|abbreviated : question text, default code
    NULL, // answer : short|long , default : long
    1,    // From Response ID
    30000,   // To Response ID
    ['id','973111X3474X42337','973111X3474X42338','973111X3475X42339','interviewtime','973111X3474time','973111X3475time','973111X3476time']
);

I got this result
 

So, everything is fine.
Here the Excel Export to compare
 
 

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: BBSR-SR5

Please Log in to join the conversation.

More
3 weeks 1 day ago - 3 weeks 1 day ago #271336 by BBSR-SR5
Empty post: Got forum errors when having too much code in my post.
Last edit: 3 weeks 1 day ago by BBSR-SR5. Reason: information

Please Log in to join the conversation.

More
3 weeks 1 day ago #271337 by BBSR-SR5

Export the data to Excel via the GUI not via the API.



 
That also results in fieldnames like SH01[x]. I've also tried the SPSS version (which would be SH01_x) but that also doesn't work.

how is your survey displayed ("group by group" ofr "question by question")?

Group by group. 

So, please, create a small prototype, send the lss export and your script to export this.


Okay I attached a small prototype .lss

I've put a small python script together. I haven't been trying to use any SGQA codes, just using the stuff from the gui excel export as tpartner suggested.

This results in only null values exported for the questions and timings:

For some reason the forum doesn't like my code and results so I put it in a zip...
 

Please Log in to join the conversation.

More
3 weeks 1 day ago #271338 by Joffm
Hi,
if you use SGQA syntax I do not see an issue.

I admit this is php (I have not the least knowledge of python), but I assume that your python code is correct.
Code:
$surveyResponses = $myJSONRPCClient->export_responses(
    $sessionKey,
    $survey_id,
    'json', // Document type : pdf,csv,xls,doc,json
    null, // Language code : null : default from survey
    'complete', // Stautus complete|incomplete|all
    NULL, // Heading : code|full|abbreviated : question text, default code
    NULL, // answer : short|long , default : long
    1,    // From Response ID
    30000,   // To Response ID   
['id', 'submitdate', 'lastpage', 'startlanguage', 'seed', 'startdate', 'datestamp', '758878X3477X42341', '758878X3477X42342SQ001', '758878X3477X42342SQ002', '758878X3477X42342SQ003', '758878X3478X42343', 'interviewtime', '758878X3477time', '758878X3478time']
);
Here the data of the last participant and everything displayed as table


Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: BBSR-SR5

Please Log in to join the conversation.

More
3 weeks 1 day ago #271340 by BBSR-SR5

Hi,
if you use SGQA syntax I do not see an issue.

I admit this is php (I have not the least knowledge of python), but I assume that your python code is correct.
Code:
$surveyResponses = $myJSONRPCClient->export_responses(
    $sessionKey,
    $survey_id,
    'json', // Document type : pdf,csv,xls,doc,json
    null, // Language code : null : default from survey
    'complete', // Stautus complete|incomplete|all
    NULL, // Heading : code|full|abbreviated : question text, default code
    NULL, // answer : short|long , default : long
    1,    // From Response ID
    30000,   // To Response ID   
['id', 'submitdate', 'lastpage', 'startlanguage', 'seed', 'startdate', 'datestamp', '758878X3477X42341', '758878X3477X42342SQ001', '758878X3477X42342SQ002', '758878X3477X42342SQ003', '758878X3478X42343', 'interviewtime', '758878X3477time', '758878X3478time']
);

Here the data of the last participant and everything displayed as table


Joffm

 
Thank you very much for your explanation! With this I managed to figure out my problem. This was three fold:
  1. I was trying to retrieve group timings on answer/child question level
  2. I didn't realise I also needed to retrieve answers with the SGQA code, I couldn't use the field name from the json or csv output.
  3. For retrieving answers for sub-questions (like in multiple choice or matrix questions) I couldn't use the qid from the sub-question, but needed to use the qid of the parent question and the "title" of the sub-question.
Thank you a lot. This resolved my issue!

So in my case to retrieve the timings for a group I needed the following parameters survey id and group id. I need to put them together in a code like this:
[sid]X[gid]time -> 758878X3478time

If I want to retrieve the answers i.E. a text answer or a single choice question (both are questions without child questions) I need the parameters survey id, group id, question id. I need to to put them together like this:
[sid]X[gid]X[qid] -> 758878X3477X42341

If I want to retrieve the answers for something like a multiple choice or matrix question (questions with child questions). I need the parameters survey id, group id, parent question id, child question title. I need to put them together like this:
[sid]X[gid]X[parent qid][child title] -> 758878X3477X42342SQ003

Again thanks a lot for your help, I was really blocked here.

Please Log in to join the conversation.

More
3 weeks 1 day ago #271343 by BBSR-SR5
In case someone is googling this in the future. You can get the IDs for all fields with the API method"get_fieldmap()":  api.limesurvey.org/classes/remotecontrol...#method_get_fieldmap

I'Ve pulled an example from the survey I'm working on.

If you exported via the GUI this would be the column/variable: "SA02[x]"
Code:
"326961X223X1637x": {
            "fieldname": "326961X223X1637x",
            "type": "F",
            "sid": 326961,
            "gid": 223,
            "qid": 1637,
            "aid": "x",
            "sqid": 1807,
            "title": "SA02",
            "question": "<p>Was \u00fcberwiegt: Herausforderungen oder Chancen?</p>\r\n",
            "subquestion": "",
            "group_name": "[VI-SA02] Aktuelle Stimmung und Ausblick",
            "mandatory": "N",
            "encrypted": "N",
            "hasconditions": "N",
            "usedinconditions": "N",
            "questionSeq": 48,
            "groupSeq": 37,
            "preg": null,
            "SQrelevance": "1",
            "relevance": "1",
            "grelevance": "",
            "other": "N",
            "help": ""
      },

"title" is the "Code" you know from the GUI when creating a new question. "aid" is the "Code" from subquestions:
 

I may be feeling like an idiot right now, because I build something like this fieldmap from exporting single questions and merging them together to get all the relevant data.

Anyway, maybe this will save some future API users a lot of time.

Please Log in to join the conversation.

More
3 weeks 1 day ago - 3 weeks 1 day ago #271344 by Joffm
Hi,
thanks for sharing.

But in my opinion there are more direct ways.
You can list the SGQ code of your question with such equations (with the properties "gid" and "qid")
[url] www.limesurvey.org/manual/ExpressionScri...#Access_to_variables [/url]
 
E.g. in a text display


But these values you also see directly here
 

Joffm
 

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 3 weeks 1 day ago by Joffm.

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose