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
376c1e3b
Commit
376c1e3b
authored
May 08, 2016
by
andreagerino
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding user stats download to IP service
parent
47f4feea
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
106 additions
and
0 deletions
+106
-0
invisiblepuzzle.js
routes/services/invisiblepuzzle/invisiblepuzzle.js
+106
-0
No files found.
routes/services/invisiblepuzzle/invisiblepuzzle.js
View file @
376c1e3b
var
express
=
require
(
'express'
);
var
express
=
require
(
'express'
);
var
router
=
express
.
Router
();
var
router
=
express
.
Router
();
var
debug
=
require
(
'debug'
)(
'Icarus:server'
);
var
mongoClient
=
require
(
'mongodb'
).
MongoClient
;
var
assert
=
assert
=
require
(
'assert'
);
// Connection URL
var
mongoUrl
=
'mongodb://icarus:icarus@localhost:27017/icarus'
;
//Connect to the server and intialise the pool
var
icarusDb
;
mongoClient
.
connect
(
mongoUrl
,
function
(
err
,
db
)
{
assert
.
equal
(
null
,
err
,
err
);
debug
(
"Connected to MongoDB database: "
+
db
.
databaseName
);
icarusDb
=
db
;
});
/* GET root . */
/* GET root . */
router
.
get
(
'/'
,
function
(
req
,
res
,
next
)
{
router
.
get
(
'/'
,
function
(
req
,
res
,
next
)
{
...
@@ -8,4 +28,90 @@ router.get('/', function(req, res, next) {
...
@@ -8,4 +28,90 @@ router.get('/', function(req, res, next) {
});
});
router
.
get
(
'/users'
,
function
(
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
]}}
}
},
// Stage 3
{
$project
:
{
"docs"
:
1
,
"vo_ratio"
:
{
$divide
:[
"$voiceover"
,
"$docs"
]}
}
},
// Stage 4
{
$group
:
{
"_id"
:
1
,
"users"
:
{
$sum
:
1
},
"vib"
:
{
$sum
:
{
$cond
:
[{
$gt
:[
"$vo_ratio"
,
0
]},
1
,
0
]}}
}
},
// Stage 5
{
$project
:
{
"_id"
:
0
,
"users"
:
1
,
"vib"
:
1
}
}
]
).
toArray
(
function
(
err
,
result
)
{
if
(
err
!=
null
){
debug
(
err
);
next
(
err
);
}
else
{
if
(
result
==
undefined
){
res
.
sendStatus
(
404
);
}
else
{
res
.
send
(
200
,
result
);
}
}
});
});
module
.
exports
=
router
;
module
.
exports
=
router
;
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