Skip to content

Instantly share code, notes, and snippets.

@cuuupid
Last active December 15, 2020 21:01
Show Gist options
  • Save cuuupid/297eaf14d92df4cfb6fa4df1cb1832b3 to your computer and use it in GitHub Desktop.
Save cuuupid/297eaf14d92df4cfb6fa4df1cb1832b3 to your computer and use it in GitHub Desktop.
Get statistics of all League of Legends champions by running this in the console of u.gg's tier list after scrolling all the way down
(() => {
const champions = {}
const key = {
champion: 1,
win: 3,
pick: 4,
ban: 5
}
const pct = str =>
eval(str.split('%')[0])
const parse = datastring => {
parts = datastring.split('\n')
const champ = parts[key.champion]
if (!champions[champ]) {
champions[champ] = {
win: [], pick: [], ban: [],
winrate: null,
pickrate: null,
banrate: null,
name: champ
}
}
const winrate = pct(parts[key.win])
const pickrate = pct(parts[key.pick])
const banrate = pct(parts[key.ban])
champions[champ].win.push(winrate)
champions[champ].pick.push(pickrate)
champions[champ].ban.push(banrate)
}
const parseAll = (() =>
[...(
document.getElementsByClassName(
'rt-tr-group'
)
)].map(el => el.innerText).map(parse)
)
const sum = arr =>
arr.reduce((sum, x) => sum + x)
const average = arr =>
sum(arr) / arr.length;
const compute = champ => {
const {
win,
pick,
ban
} = champions[champ]
const winrate = average(win)
const pickrate = sum(pick)
const banrate = sum(ban)
champions[champ].winrate = winrate
champions[champ].pickrate = pickrate
champions[champ].banrate = banrate
}
const computeAll = () =>
[...(
Object.keys(champions)
)].map(compute)
const stat = (cmp, l=20) => k => d => {
//! deep copy
d = JSON.parse(JSON.stringify(d))
const statOne = data => {
const champs = [
...Object.keys(data)
]
//? no reduce here, KISS
let s = data[champs[0]]
champs.map(champ => {
const a = s[k]
const b = data[champ][k]
if (cmp(b,a)) s = data[champ]
})
return {
champion: s.name,
value: s[k]
}
}
const results = []
while (
results.length < l &&
Object.keys(d).length > 0
) {
const result = statOne(d)
results.push(result)
delete d[result.champion]
}
return results
}
const statFuncs = () => {
const lt = (a,b) => a < b;
const gt = (a,b) => a > b;
const min = stat(lt)
const max = stat(gt)
const funcs = { min, max }
const genFuncs = field => {
const fs = {}
const fns = Object.keys(funcs)
fns.map(fn => {
fs[fn] = funcs[fn](field)
})
return fs
}
return {
pickrate: genFuncs("pickrate"),
winrate: genFuncs("winrate"),
banrate: genFuncs("banrate")
}
}
const stats = () => {
const data = champions
const funcs = statFuncs()
const fields = Object.keys(funcs)
const s = {}
fields.map(field => {
const fns = Object.keys(
funcs[field]
)
const d = {}
fns.map(fn => {
d[fn] = funcs[field][fn](data)
})
s[field] = d
})
return s
}
parseAll()
computeAll()
const statistics = stats()
const names = Object.keys(champions)
return { champions, statistics, names }
})()
@cuuupid
Copy link
Author

cuuupid commented Dec 15, 2020

Expected values for pick/ban are ~6% (1 / 147). Percents above are returned as whole numbers so an expected pickrate would be 6 in the returned statistics.

You can generate expected values depending on the patch as the # of champions changes by simply doing:

const { champions, statistics, names } = ... // paste in the code above
1 / names.length // expected value

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment