Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
IcarusServer
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
icarus
IcarusServer
Commits
60e8ca8a
Commit
60e8ca8a
authored
Jun 14, 2016
by
andreagerino
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding explorations endpoint
parent
5bae4b56
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
67 additions
and
112 deletions
+67
-112
invisiblepuzzle.js
routes/services/invisiblepuzzle/invisiblepuzzle.js
+67
-112
No files found.
routes/services/invisiblepuzzle/invisiblepuzzle.js
View file @
60e8ca8a
...
...
@@ -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) {
router
.
get
(
'/explorations/hp
'
,
function
(
req
,
res
,
next
)
{
var refresh = req.query.refresh;
if(refresh==1){
var
collection
=
icarusDb
.
collection
(
'resources'
);
rebuild_user_stats(req, res, next);
var
cursor
=
collection
.
aggregate
(
}else{
// Pipeline
[
// Stage 1
{
$match
:
{
"appdata.appname"
:
"Invisible Puzzle"
,
"userdata.event"
:
"exploration"
,
"debug"
:
false
}
},
res.sendStatus(500);
// 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.uu
id",
"
doc
s" : {
"_id"
:
"$
userdata.level.
id"
,
"
exploration
s"
:
{
"$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.send
Status(201,
result);
res
.
send
(
200
,
result
);
}
...
...
@@ -364,6 +319,6 @@ function rebuild_user_stats(req, res, next){
});
}
*/
}
module
.
exports
=
router
;
module
.
exports
=
router
;
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment