forked from odota/core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmarkMatch.js
More file actions
50 lines (50 loc) · 1.67 KB
/
benchmarkMatch.js
File metadata and controls
50 lines (50 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
var moment = require('moment');
var utility = require('./utility');
var config = require('./config');
var benchmarks = require('./benchmarks');
var async = require('async');
/**
* Computes benchmarks for players in a match
**/
function benchmarkMatch(redis, m, cb)
{
async.map(m.players, function(p, cb)
{
p.benchmarks = {};
async.eachSeries(Object.keys(benchmarks), function(metric, cb)
{
//in development use live data (for speed), in production use full data from last day (for consistency)
var key = ['benchmarks', utility.getStartOfBlockHours(config.BENCHMARK_RETENTION_HOURS, config.NODE_ENV === "development" ? 0 : -1), metric, p.hero_id].join(':');
var raw = benchmarks[metric](m, p);
p.benchmarks[metric] = {
raw: raw
};
redis.zcard(key, function(err, card)
{
if (err)
{
return cb(err);
}
if (raw !== undefined && raw !== null && !Number.isNaN(raw))
{
redis.zcount(key, '0', raw, function(err, count)
{
if (err)
{
return cb(err);
}
var pct = count / card;
p.benchmarks[metric].pct = pct;
return cb(err);
});
}
else
{
p.benchmarks[metric] = {};
cb();
}
});
}, cb);
}, cb);
}
module.exports = benchmarkMatch;