forked from odota/core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprofiler.js
More file actions
70 lines (68 loc) · 2.03 KB
/
profiler.js
File metadata and controls
70 lines (68 loc) · 2.03 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
var queries = require('./queries');
var insertPlayer = queries.insertPlayer;
var utility = require('./utility');
var getData = utility.getData;
var async = require('async');
var db = require('./db');
var constants = require('./constants');
var max;
start();
function start()
{
getSummaries(function(err)
{
if (err)
{
throw err;
}
return setTimeout(start, 1000);
});
}
function getSummaries(cb)
{
db.raw(`select max(match_id) from matches`).asCallback(function(err, result)
{
if (err)
{
return cb(err);
}
max = Number(result.rows[0].max);
var min = max - 10000000;
db.raw(`
select distinct account_id
from player_matches
where match_id in (SELECT (?::bigint + random()*(?::bigint - ?::bigint))::bigint as rand
from generate_series(1,50))
and account_id < ? limit 100
`, [min, max, min, constants.anonymous_account_id]).asCallback(function(err, results)
{
if (err)
{
return cb(err);
}
if (results.rows.length === 0)
{
console.log('No Steamids to scan for...');
return cb();
}
console.log('players sampled: %s', results.rows.length);
var container = utility.generateJob("api_summaries",
{
players: results.rows
});
getData(container.url, function(err, body)
{
if (err)
{
//couldn't get data from api, non-retryable
return cb(JSON.stringify(err));
}
//player summaries response
async.each(body.response.players, function(player, cb)
{
insertPlayer(db, player, cb);
}, cb);
});
});
});
}