-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
123 lines (116 loc) · 3.52 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
var rp = require("request-promise"),
Promise = require("bluebird"),
jsdom = require("jsdom"),
debug = require("debug")("ggxrd-stats"),
fs = require("fs");
const game = process.argv.indexOf("--rev") !== -1 ? "pg2" : "pg";
const metagame = process.argv.indexOf("--metagame") !== -1;
const baseUrl = "http://www.ggxrd.com/" + game + "/diagram_view.php?grade=dan";
const filename = "matchups_" + game + ".csv";
debug("game: %s", game);
debug("metagame: %s", metagame);
debug("baseUrl: %o", baseUrl);
const japNames = {
"Sol": "ソル",
"Ky": "カイ",
"May": "メイ",
"Millia": "ミリア",
"Zato": "ザトー",
"Potemkin": "ポチ",
"Chipp": "チッ",
"Faust": "ファウ",
"Axl": "アク",
"Venom": "ヴェノ",
"Slayer": "スレ",
"I-No": "イノ",
"Bedman": "ベッドマン",
"Ramlethal": "ラムレザル",
"Sin": "シン",
"Elphelt": "エルフェルト",
"Leo": "レオ",
"Jam": "蔵土縁紗夢",
"Johnny": "ジョニー",
"Jack-O": "ジャック・オー",
"Haehyun": "琴 慧弦",
"Raven": "レイヴン",
"Dizzy": "ディズィー"
};
function getCharacter(text) {
for(var key in japNames) {
if (text.indexOf(japNames[key]) !== -1)
return key;
}
debug("UNKNOWN %s", text);
return "UNKNOWN";
}
function makeCsv(matchups) {
const chars = Object.keys(matchups);
const header = metagame ? "" : ", " + chars.join(", ") + "\n" ;
const lines = chars.map(c => {
return c + ", " + chars.map(c2 => {
if(metagame) {
return ( matchups[c][c2] / 10 );
}
return matchups[c][c2];
}).join(", ");
}).join("\n");
return header + lines;
}
function buildMatchupTable(windows) {
const matchups = {};
windows.forEach(window => {
const $ = window.jQuery;
const charTitle = $(".rankBox > p").text();
const me = getCharacter(charTitle);
matchups[me] = {};
matchups[me][me] = 5; //seems reasonable
debug("gettings stats for %s", me);
$.makeArray($("div.rankBox ul li")).forEach(el => {
const $el = $(el);
const opponent = getCharacter($el.text());
const rank = $el.find(".rankBoxNum").text();
matchups[me][opponent] = rank;
});
});
return matchups;
}
var env = Promise.promisify(jsdom.env);
env(baseUrl, ["http://code.jquery.com/jquery.js"])
.then(function (window) {
debug("Parsed index page");
const $ = window.jQuery;
return $.makeArray($("option"))
.map(i => $(i).attr("value"))
.filter(s => s != "all");
})
.then(function (chars) {
debug("Got characters %o", chars)
return Promise.all(chars.map(c => {
return rp({
method: "POST",
uri: baseUrl,
form: {
mode: "character",
character: c
}
});
}));
})
.then(function (results) {
debug("All pages downloaded, parsing")
return Promise.all(results.map(r => {
return env(r, ["http://code.jquery.com/jquery.js"]);
}));
})
.then(function (windows) {
debug("All pages parsed");
return buildMatchupTable(windows);
})
.then(makeCsv)
.then(fs.writeFileSync.bind(fs, filename))
.then(function() {
console.log(filename, "written")
})
.catch(function (err) {
console.log(err);
});