-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreporterUtils.js
More file actions
48 lines (39 loc) · 1.37 KB
/
reporterUtils.js
File metadata and controls
48 lines (39 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Return the responses from a reporter object.
// A reporterObject is a JavaScript object parsed from a reporter app, JSON export.
function getResponses(reporterObject) {
var snapshotResponses = [];
var snapshots = reporterObject.snapshots;
// For each snapshot from the export
for (var i = 0; i < snapshots.length; i++) {
snapshotResponses.push(snapshots[i].responses);
snapshotResponses[i].date = snapshots[i].date;
};
return snapshotResponses;
}
// Returns all answers to the userQuestionPrompt from the selected day
function getQuestionData(userQuestionPrompt) {
var results = [];
var currentResponses = responses[dataIndex];
// For each response from the snapchats
for (var iResponse = 0; iResponse < currentResponses.length; iResponse++) {
var response = currentResponses[iResponse];
// For each question answered during the report
for (var iQuestion = 0; iQuestion < response.length; iQuestion++) {
var question = response[iQuestion];
// If the question matches the user's query
if (question.questionPrompt == userQuestionPrompt) {
var result = {};
// Find the answer
for (var property in question) {
if (property != "questionPrompt") {
result['value'] = question[property];
}
}
// Attach the time to the answer
result.date = response.date;
results.push(result);
}
}
};
return results;
}