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
|
#!/usr/bin/node
const R = require('ramda'),
moment = require('moment');
function paramsForHourSample(config) {
const requestArgsForRegionStartEnd = R.curry((region, start, end) => [
`/shards/${region}/matches`, {
'sort': '-createdAt',
'filter[patchVersion]': config.patchVersion,
'filter[gameMode]': R.join(',', config.modes),
'filter[createdAt-start]': start.toISOString(),
'filter[createdAt-end]': end.toISOString(),
'page[limit]': config.matchesPerRequest,
'page[offset]': '0',
}
]);
const intervalMinutes = moment.duration(config.interval, config.intervalUnit).as('minutes');
const requestsPerMinutePerRegion = Math.floor(config.requestsPerInterval / config.regions.length);
const splitDurationMinutes = Math.floor(intervalMinutes / requestsPerMinutePerRegion);
const splitMoments = (hour) => R.map(
(offsetIndex) => [
hour.clone().minutes(offsetIndex * splitDurationMinutes),
hour.clone().minutes((offsetIndex + 1) * splitDurationMinutes),
],
R.range(0, requestsPerMinutePerRegion),
);
return R.pipe(
splitMoments,
R.xprod(config.regions),
R.map(R.unnest),
R.map(R.apply(requestArgsForRegionStartEnd)),
);
}
module.exports = {
paramsForHourSample,
};
|