From 5bae4b56653f4f5a418a02d9a01468dd887b00f9 Mon Sep 17 00:00:00 2001 From: andreagerino Date: Tue, 14 Jun 2016 10:22:48 +0200 Subject: [PATCH] Adding explorations endpoint --- .../invisiblepuzzle/invisiblepuzzle.js | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/routes/services/invisiblepuzzle/invisiblepuzzle.js b/routes/services/invisiblepuzzle/invisiblepuzzle.js index 2f20088..493c623 100644 --- a/routes/services/invisiblepuzzle/invisiblepuzzle.js +++ b/routes/services/invisiblepuzzle/invisiblepuzzle.js @@ -114,6 +114,55 @@ router.get('/users/sighted', function(req, res, next) { }); +router.get('/explorations/headphones', function(req, res, next) { + + var collection = icarusDb.collection('resources'); + + var cursor = collection.aggregate( + + // Pipeline + [ + // Stage 1 + { + $match: { + "appdata.appname" : "Invisible Puzzle", + "userdata.event" : "exploration", + "debug" : false + } + }, + + // Stage 2 + { + $group: { + "_id" : 1, + "explorations" : { + "$sum" : 1 + }, + "with_hp" : { + "$sum" : { + "$cond" : [ + { + "$eq" : [ + "$userdata.headphones", + true + ] + }, + 1, + 0 + ] + } + } + } + } + + ] + + ); + + return_cursor(cursor, req, res, next); + +}); + function return_cursor(cursor, req, res, next){ cursor.toArray(function(err, result) { -- 2.18.1