Skip to content

Instantly share code, notes, and snippets.

@blaskovicz
Last active July 1, 2018 02:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blaskovicz/5e07facddf889c3ffcf4f2ea4e19b325 to your computer and use it in GitHub Desktop.
Save blaskovicz/5e07facddf889c3ffcf4f2ea4e19b325 to your computer and use it in GitHub Desktop.
Sum Survey Monkey Responses
/**
usage: copy/paste code into your console to view all numeric responses, summed, printed per question.
example output:
[1] 6180176821 => 2
...
[23] 6167268127 => 2
Total 62 for 23 items (2.6956521739130435 / item)
*/
/**
usage: copy/paste code into your console to view all numeric responses, summed, printed per question.
Q1 id=106609657: Can you contribute any money to this event?
Total 1405 for 20 items (70.25 / item)
Q3 id=106637701: How many people will you bring (including yourself and children)?
Total 62 for 23 items (2.6956521739130435 / item)
*/
$(function() {
// start async fetches of response info
let responseViewLinks = $(".ta-toggle-link[data-response-count]");
let waitGroupCount = responseViewLinks.length;
responseViewLinks.click();
$(document).on("ajaxComplete", function() {
// or maybe just wait for ajaxStop?
//console.log(`complete, ${waitGroupCount}`)
waitGroupCount--;
if (waitGroupCount !== 1) return; // wait until complete
// get questions
$("[sm-question-id]").each(function(_, elem) {
let cell = $(elem);
let questionID = +cell.attr("sm-question-id");
let q = cell
.find(".sm-question-number")
.html()
.trim();
let title = cell
.find(".sm-questiontitle")
.html()
.trim();
let responses = $("[data-response-id]");
if (responses.length === 0) return;
// get responses for question
let index = 0;
let total = 0;
responses.each(function(_, elem) {
let cell = $(elem);
let responseId = cell.data("responseId");
if (responseId.indexOf(questionID) !== 0) {
return;
} else {
let rParts = responseId.split("-");
responseId = rParts[rParts.length - 1];
}
let response = cell
.find(".ta-response-item-content:first")
.html()
.trim();
if (response === "" || response != +response) return;
response = +response;
if (response === 0) response = 1; // normalize survey monkey slider bug / config issue
total += response;
index++;
//console.log(`[${index}] ${responseId} => ${response}`);
});
if (index !== 0) {
console.log(`${q} id=${questionID}: ${title}`);
console.log(
`Total ${total} for ${index} items (${total / index} / item)`
);
}
});
});
});
@blaskovicz
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment