codecombat/scripts/analytics/mongodb/queries/teacherSurveyCounts.js

29 lines
890 B
JavaScript
Raw Normal View History

2015-08-05 14:40:57 -04:00
// Print out teacher survey counts by day
// Usage:
// mongo <address>:<port>/<database> <script file> -u <username> -p <password>
var surveyDayMap = {};
2015-12-08 19:16:37 -05:00
var cursor = db['trial.requests'].find();
2015-08-05 14:40:57 -04:00
while (cursor.hasNext()) {
var doc = cursor.next();
var date = doc._id.getTimestamp();
2015-12-08 19:16:37 -05:00
if (doc.created) {
date = doc.created;
}
2015-08-05 14:40:57 -04:00
var day = date.toISOString().substring(0, 10);
if (!surveyDayMap[day]) surveyDayMap[day] = 0;
surveyDayMap[day]++;
}
var surveysSorted = [];
for (var day in surveyDayMap) {
surveysSorted.push({day: day, count: surveyDayMap[day]});
}
2015-12-08 19:16:37 -05:00
surveysSorted.sort(function(a, b) {return a.day.localeCompare(b.day);});
2015-08-05 14:40:57 -04:00
print("Number of teacher surveys per day:")
for (var i = 0; i < surveysSorted.length; i++) {
var stars = new Array(surveysSorted[i].count + 1).join('*');
print(surveysSorted[i].day + "\t" + surveysSorted[i].count + "\t" + stars);
}