Skip to content

Commit

Permalink
feat(params): return percentage used
Browse files Browse the repository at this point in the history
  • Loading branch information
geekus committed Mar 2, 2017
1 parent 429518f commit 1dfd283
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports.getRequestParams = function getParams(req) {
// Custom dimension 2: Query params
cd2: req.originalUrl.split('?')[1],
// Custom metric 1: RateLimit usage in percent
cm1: (req.user.remaining / req.user.limit) * 100,
cm1: parseInt((100 - ((req.user.remaining / req.user.limit) * 100)), 10),
};

if (req.user.type === 'token') {
Expand Down
6 changes: 3 additions & 3 deletions test/unit/ga.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ describe('Params', () => {
key: 'abc123',
provider: 'DNT',
app: 'UT.no',
limit: 1000,
remaining: 999,
limit: 500,
remaining: 450,
reset: 1487940909,
penalty: 1,
},
Expand All @@ -26,7 +26,7 @@ describe('Params', () => {
cg1: 'turer',
cd1: 'turer',
cd2: 'limit=50',
cm1: 99.9,
cm1: 10,
uid: 'DNT',
an: 'UT.no',
aid: undefined,
Expand Down

0 comments on commit 1dfd283

Please sign in to comment.