-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.mjs
executable file
·99 lines (83 loc) · 2.89 KB
/
index.mjs
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env node
import fs from 'fs';
import path from 'path';
import fetch from 'node-fetch';
import _debug from 'debug';
import logSymbols from 'log-symbols';
const debug = _debug('hstracker-hsreplay-stats');
const CARD_TIER_FILENAME = 'cardtier.json';
async function getData(url) {
const resp = await fetch(url);
const json = await resp.json();
return JSON.parse(JSON.stringify(json, null, 2));
}
async function main() {
const allCards = await getData('https://api.hearthstonejson.com/v1/latest/enUS/cards.json', 'cards.json');
const cardIdMap = new Map();
allCards.forEach(({ name, id, dbfId }) => {
cardIdMap.set(dbfId, { id, name, dbfId });
});
const arenaRankingData = await getArenaDataForClass();
const heros = [
// Order is specific one used by HSTracker
'WARRIOR',
'SHAMAN',
'ROGUE',
'PALADIN',
'HUNTER',
'DRUID',
'WARLOCK',
'MAGE',
'PRIEST',
'DEMONHUNTER',
];
let logData = [];
const statsByHeroAndDbfId = new Map();
const allIds = new Set();
Object.entries(arenaRankingData).forEach(([hero, heroData]) => {
for (const card of heroData) {
allIds.add(card.dbf_id);
const key = JSON.stringify([hero, card.dbf_id]);
statsByHeroAndDbfId.set(key, card.included_winrate);
}
});
debug({ statsByHeroAndDbfId });
allIds.forEach((dbfId) => {
const cardData = cardIdMap.get(dbfId);
if (!cardData) {
// A card may not be in the data set at all
return;
}
const { id, name } = cardData;
const allValue = statsByHeroAndDbfId.get(JSON.stringify(['ALL', dbfId]));
const value = heros.map((h) => {
const key = JSON.stringify([h, dbfId]);
// Multiply by 10 because HSTracker can only display 3 digit numbers
// So percentages like 62.1% will display as 621, or -1 if missing
return `${Math.round(statsByHeroAndDbfId.get(key) * 10 || -1)}`;
});
logData.push({
id,
name,
value,
});
});
fs.writeFileSync(CARD_TIER_FILENAME, JSON.stringify(logData, null, 2));
return logData;
}
async function getArenaDataForClass() {
const arenaData = await getData(
'https://hsreplay.net/analytics/query/card_list_free/?GameType=ARENA&TimeRange=CURRENT_PATCH',
'arena_data.json'
);
return arenaData.series.data;
}
const data = await main();
debug(data);
console.log(logSymbols.success, `Downloaded scores for ${data.length} cards to ${CARD_TIER_FILENAME}`);
console.log(logSymbols.info, 'Run (only necessary once):')
console.log(
logSymbols.info,
` ln -sf "$PWD/${CARD_TIER_FILENAME}" "/Users/$USER/Library/Application Support/HSTracker/arena"`
);
console.log(logSymbols.warning, 'Don’t forget to restart HSTracker!');