New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PL: support multi-select when viewing JotForm survey results #28441
PL: support multi-select when viewing JotForm survey results #28441
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow! Thanks for the great explanation of this change, and excellent find! Is there any place we could add a test case for this, even just over the one line you changed? (If not, maybe we can sprout a method from that line and test it in isolation.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Niiiice! I can imagine how long this took to unravel based on my previous forays into this code jungle. I agree that some testing would be nice but I feel good about this change!
I wonder if the percentage calculations should work differently for multi-select questions. I would normally expect these to sum to over 100% for multi-select and represent the % of users who chose that as an answer. So if there are 2 people responding to the "Within the last 3 years..." question, the "I completed an online course/webinar" should read as 100%. I don't understand the use case well enough to say for sure right now |
I've updated this PR with a second commit that fixes the percentages for multi-select questions. The description has also been updated to describe this. The most complex logic has also been extracted into its own function and is now unit-tested. |
This adds support for multi-select answers when viewing workshop per-day JotForm survey results. After a long day of diving into this code, I'm surprised at how small the fix is, and am also not yet sure whether it's the right or complete fix.
But here's why the simple addition of a
.flatten
seems to have worked. Almost everything came down to this line in the controller:For these examples, we'll take
surveys_for_session[response_section]
to be this, which represents two surveys, each with the same four questions answered:For a single-select, the transformation worked like this:
For a multi-select, the same transformation worked like this:
which was not what we wanted, and didn't group answers properly on the client.
But with the addition of the
.flatten
, we see this:This looks closer to what we're after.
Taking a look at the view for this data at
/pd/workshop_dashboard/daily_survey_results/ID
, with only a small change made to renderSingleChoiceResponses
formultiSelect
answers as well, things amazingly seem to work with no further changes:Except the eagle-eyed will notice that the percentages aren't right here, because the logic for
singleSelect
questions looked at the number of answers supplied by one respondent divided by the number of answers supplied by all respondents. In the case ofmultiSelect
, we want to divide by the number of respondents to that question, rather than the number of answers. A second commit handles this: