arthur-shaw / susoapi

R interface for Survey Solutions' APIs
https://arthur-shaw.github.io/susoapi/
Other
9 stars 5 forks source link

Write function to fetch user-specified info about interviews #23

Closed arthur-shaw closed 2 years ago

arthur-shaw commented 2 years ago

The get_interviews() function fetches all available data for an interview. There needs to be a function to fetch user-specified attributes about interviews. The GraphQL offers the following data. The user should be able to request particular attributes rather than fetch them all and select those that are relevant. This may be a new function or a change in the interface, where the full payload is the default but fewer attributes can be requested.

interviews (
    workspace: <glue::double_quote(workspace)>
    take: <take_n>
    skip: <skip_n>
) {
    nodes {
        id
        key
        assignmentId
        identifyingData {
            answerValue
            value
            valueBool
            valueDate
            valueLong
            valueDouble
            isEnabled
            entity {
                identifying
                label
                options {
                    parentValue
                    title
                    value
                }
                questionText
                scope
                type
                variable
            }
        }
        questionnaireId
        questionnaireVersion
        questionnaireVariable
        responsibleName
        responsibleId
        responsibleRole
        supervisorName
        status
        actionFlags
        wasCompleted
        notAnsweredCount
        errorsCount
        createdDate
        updateDateUtc
        receivedByInterviewerAtUtc
        interviewMode        
    }
    filteredCount
}
petbrueck commented 2 years ago

I second this enhancement. The current function is quite heavy I feel.

In addition to being able to return only a selection of nodes, it would also be very useful to make use of the where: InterviewsFilter, e.g. to only get interviews from questionnaire X. In fact, I'll need this for an upcoming project, so I'll try to fork next week and give it a try.

P.s. I also often stumble over the issue that the function returns the following

Error in get_interviews_by_chunk(workspace = workspace, take_n = chunk_size, : Object reference not set to an instance of an object.

which might be due to the server not being able to handle the IOPS (?) . I'll try to find the time to investigate further and maybe raise another issue =)

arthur-shaw commented 2 years ago

Thanks, @petbrueck.

I also often get the same error as you describe above. If you have time to investigate the issue, I'd love to understand better what's going on. For a current project, I end up having to rerun get_interviews() several times before it works. This is both frustrating and strange. Frustrating because I have to run the script repeatedly and outside of a script for things to work. Strange because the function should, in principle, either work or not work systematically--not work sometimes but not others, for the same scenario.

I have rewritten get_interviews_by_chunks() using GraphQL. I just need more testing before releasing. Perhaps I can do a pre-release as a branch. Stay tuned.