-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
84 lines (76 loc) · 3.01 KB
/
index.js
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
const program = require('commander');
require('console.table');
const config = require('./config');
const metadata = require('./metadata');
const matches = require('./matches');
const events = require('./events');
const carnage = require('./carnage');
const async = require('neo-async');
const mapsTable = require('./maps-table');
const usersTable = require('./users-table');
const strongholdsTable = require('./strongholds-table');
const ctfTable = require('./ctf-table');
const weaponsTable = require("./weapons-table");
const awardsTable = require("./awards-table");
program
.version('1.0.0')
.option('-s, --skip [skip]', 'The number of games halo-tracker should skip before it begins looking for a session', parseInt)
.option('-c --count [count]', 'The number of games halo-tracker should include in this batch of stats', parseInt)
.option('-c --allow-customs [allowCustoms]', 'The number of games halo-tracker should include in this batch of stats', parseInt)
.parse(process.argv);
program.args.forEach(gamertag => {
config.set('user', gamertag);
});
const fetchAllDataForMatch = (matchId, carnageReportUrl, friendlyTeamId, cb) => {
console.info(`Fetching carnage report and match events for ${matchId}`);
carnage.getCarnageReportData(carnageReportUrl, friendlyTeamId, (err, carnageData) => {
if (err) {
console.error(`Error fetching carnage report for match ${matchId}: ${err}`)
cb(err);
return;
}
// pass the carnageData in and update it with whatever we can tease out through the matchEvent api
events.getEventData(matchId, carnageData, (err, finalMatchData) => {
if (err) {
console.error(`Error fetching event data for match ${matchId}: ${err}`);
cb(err);
return;
}
return cb(null, finalMatchData);
});
});
};
metadata.getMetadata((err, { maps, medals, impulses, weapons, gameTypes }) => {
if (err) {
console.error(`Error fetching metadata: ${err}`);
process.exit(1);
return;
}
matches.getMatches({
gamertag: program.args[0],
skip: program.skip || 0,
count: program.count,
allowCustoms: program.allowCustoms || false
}, (err, matchesData) => {
if (err) {
console.error(`Error fetching matches: ${err}`);
process.exit(1);
return;
}
// for each match of our session, hit the carnage report api and the match events api, and put together some interesting stats
async.series(matchesData.map(match => fetchAllDataForMatch.bind(null, match.Id.MatchId, match.Links.StatsMatchDetails.Path, match.Players[0].TeamId)), (err, allMatchData) => {
if (err) {
console.error(`Error fetching carnage reports: ${err}`);
process.exit(1);
return;
}
console.table(mapsTable.getMapsTable(allMatchData));
const userData = usersTable.getUsersTable(allMatchData);
console.table(userData);
console.table(weaponsTable.getWeaponsTable(allMatchData));
console.table(strongholdsTable.getStrongholdsTable(allMatchData));
console.table(ctfTable.getCtfTable(allMatchData));
console.log(awardsTable.getAwardsTable(allMatchData, userData));
});
});
});