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
485ee6f1
Commit
485ee6f1
authored
8 years ago
by
andreagerino
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding user detail endpoints
parent
376c1e3b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
209 additions
and
4 deletions
+209
-4
invisiblepuzzle.js
routes/services/invisiblepuzzle/invisiblepuzzle.js
+209
-4
No files found.
routes/services/invisiblepuzzle/invisiblepuzzle.js
View file @
485ee6f1
// PROTOCOL SPECIFICATION
// -----------------------
// /users/count - returns the number of users and how many of them are using VoiceOver
// /users/vib - returns objects representing who are using VoiceOver
// /users/sighted - returns objects representing who are not using VoiceOver
var
express
=
require
(
'express'
);
var
router
=
express
.
Router
();
...
...
@@ -8,7 +14,7 @@ var mongoClient = require('mongodb').MongoClient;
var
assert
=
assert
=
require
(
'assert'
);
// Connection URL
var
mongoUrl
=
'mongodb://
icarus:icarus
@localhost:27017/icarus'
;
var
mongoUrl
=
'mongodb://
readOnly:readOnly
@localhost:27017/icarus'
;
//Connect to the server and intialise the pool
var
icarusDb
;
...
...
@@ -28,11 +34,11 @@ router.get('/', function(req, res, next) {
});
router
.
get
(
'/users'
,
function
(
req
,
res
,
next
)
{
router
.
get
(
'/users
/count
'
,
function
(
req
,
res
,
next
)
{
var
collection
=
icarusDb
.
collection
(
'resources'
);
collection
.
aggregate
(
var
cursor
=
collection
.
aggregate
(
// Pipeline
[
...
...
@@ -88,7 +94,31 @@ router.get('/users', function(req, res, next) {
}
]
).
toArray
(
function
(
err
,
result
)
{
)
return_cursor
(
cursor
,
req
,
res
,
next
);
});
router
.
get
(
'/users/vib'
,
function
(
req
,
res
,
next
)
{
var
cursor
=
user_ids_cursor
(
true
);
cursor
.
map
(
function
(
d
)
{
return
d
[
'_id'
];
}
);
return_cursor
(
cursor
,
req
,
res
,
next
);
});
router
.
get
(
'/users/sighted'
,
function
(
req
,
res
,
next
)
{
var
cursor
=
user_ids_cursor
(
false
);
return_cursor
(
cursor
,
req
,
res
,
next
);
});
function
return_cursor
(
cursor
,
req
,
res
,
next
){
cursor
.
toArray
(
function
(
err
,
result
)
{
if
(
err
!=
null
){
...
...
@@ -111,7 +141,182 @@ router.get('/users', function(req, res, next) {
});
}
function
user_ids_cursor
(
vib
){
var
filter_condition
=
{
$eq
:
0
};
if
(
vib
==
true
){
filter_condition
=
{
$gt
:
0
}
}
var
collection
=
icarusDb
.
collection
(
'resources'
);
return
collection
.
aggregate
(
// Pipeline
[
// Stage 1
{
$match
:
{
"appdata.appname"
:
"Invisible Puzzle"
,
"debug"
:
false
}
},
// Stage 2
{
$group
:
{
"_id"
:
"$appdata.uuid"
,
"docs"
:
{
$sum
:
1
},
"voiceover"
:
{
$sum
:
{
$cond
:
[{
$eq
:[
"$appdata.voiceover"
,
true
]},
1
,
0
]}},
"levels"
:
{
"$addToSet"
:
"$userdata.level.id"
},
"sonifications"
:
{
"$addToSet"
:
"$userdata.sonification"
}
}
},
// Stage 3
{
$project
:
{
"docs"
:
1
,
"vo_ratio"
:
{
$divide
:[
"$voiceover"
,
"$docs"
]},
"levels"
:
1
,
"sonification"
:
1
}
},
// Stage 4
{
$match
:
{
"vo_ratio"
:
filter_condition
}
}
]
)
}
/*router.get('/users/', function(req, res, next) {
var refresh = req.query.refresh;
if(refresh==1){
rebuild_user_stats(req, res, next);
}else{
res.sendStatus(500);
}
});
function rebuild_user_stats(req, res, next){
var collection = icarusDb.collection('resources');
collection.aggregate(
// Pipeline
[
// Stage 1
{
$match: {
"appdata.appname" : "Invisible Puzzle",
"debug" : false
}
},
// Stage 2
{
$group: {
"_id" : "$appdata.uuid",
"docs" : {
"$sum" : 1
},
"voiceover" : {
"$sum" : {
"$cond" : [
{
"$eq" : [
"$appdata.voiceover",
true
]
},
1,
0
]
}
},
"levels" : {
"$addToSet" : "$userdata.level.id"
},
"sonifications" : {
"$addToSet" : "$userdata.sonification"
}
}
},
// Stage 3
{
$project: {
"docs" : 1,
"vo_ratio" : {
"$divide" : [
"$voiceover",
"$docs"
]
},
"levels" : 1,
"sonifications" : 1
}
},
// Stage 4
{
$out: "ip_user_stats"
}
]
).toArray(function(err, result) {
if(err!=null){
debug(err);
next(err);
}else{
if(result==undefined){
res.sendStatus(404);
}else{
res.sendStatus(201, result);
}
}
});
}*/
module
.
exports
=
router
;
This diff is collapsed.
Click to expand it.
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