Commit 60e8ca8a authored by andreagerino's avatar andreagerino

Adding explorations endpoint

parent 5bae4b56
......@@ -114,82 +114,6 @@ 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) {
if(err!=null){
debug(err);
next(err);
}else{
if(result==undefined){
res.sendStatus(404);
}else{
res.send(200,result);
}
}
});
}
function user_ids_cursor(vib){
var filter_condition = {$eq: 0};
......@@ -257,28 +181,60 @@ function user_ids_cursor(vib){
}
/*router.get('/users/', function(req, res, next) {
var refresh = req.query.refresh;
if(refresh==1){
router.get('/explorations/hp', function(req, res, next) {
rebuild_user_stats(req, res, next);
var collection = icarusDb.collection('resources');
}else{
var cursor = collection.aggregate(
res.sendStatus(500);
// 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 rebuild_user_stats(req, res, next){
router.get('/explorations/hpbylevel', function(req, res, next) {
var collection = icarusDb.collection('resources');
collection.aggregate(
var cursor = collection.aggregate(
// Pipeline
[
......@@ -286,6 +242,7 @@ function rebuild_user_stats(req, res, next){
{
$match: {
"appdata.appname" : "Invisible Puzzle",
"userdata.event" : "exploration",
"debug" : false
}
},
......@@ -293,16 +250,16 @@ function rebuild_user_stats(req, res, next){
// Stage 2
{
$group: {
"_id" : "$appdata.uuid",
"docs" : {
"_id" : "$userdata.level.id",
"explorations" : {
"$sum" : 1
},
"voiceover" : {
"with_hp" : {
"$sum" : {
"$cond" : [
{
"$eq" : [
"$appdata.voiceover",
"$userdata.headphones",
true
]
},
......@@ -310,38 +267,36 @@ function rebuild_user_stats(req, res, next){
0
]
}
},
"levels" : {
"$addToSet" : "$userdata.level.id"
},
"sonifications" : {
"$addToSet" : "$userdata.sonification"
}
}
},
// Stage 3
{
$project: {
"docs" : 1,
"vo_ratio" : {
"$divide" : [
"$voiceover",
"$docs"
]
},
"levels" : 1,
"sonifications" : 1
}
"_id": 1,
"explorations": 1,
"hp_ratio": {$divide:["$with_hp","$explorations"]}
},
// Stage 4
{
$out: "ip_user_stats"
$sort: {
"_id": 1
}
}
]
).toArray(function(err, result) {
);
return_cursor(cursor, req, res, next);
});
function return_cursor(cursor, req, res, next){
cursor.toArray(function(err, result) {
if(err!=null){
......@@ -356,7 +311,7 @@ function rebuild_user_stats(req, res, next){
}else{
res.sendStatus(201, result);
res.send(200,result);
}
......@@ -364,6 +319,6 @@ function rebuild_user_stats(req, res, next){
});
}*/
}
module.exports = router;
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment