Skip to content

Instantly share code, notes, and snippets.

@hntd187
Last active October 9, 2017 19:15
Show Gist options
  • Save hntd187/5589e018f012f91acaa996f635312e9c to your computer and use it in GitHub Desktop.
Save hntd187/5589e018f012f91acaa996f635312e9c to your computer and use it in GitHub Desktop.
Faceit dota2 stats
#!/bin/bash
# Usage: ./gen.sh [report] -u -l <league>
# Types of reports: pct (order by win percent), wins (order by number of wins) matches (order by number of games)
# -u boolean, whether or not to update the counts
# -l <league> the faceit league id to pull matches from
assume(){
/usr/bin/python <(cat <&5) | column -t -s','
}
export CHOICE="wins"
league="90617f53-615f-479a-991f-ba74a163fa39"
update=0
if [[ $# > 0 ]]; then
for opt in "$@"
do
case "$opt" in
matches|pct|games)
export CHOICE=$1
shift;;
-l)
league=$2
update=1
shift 2;;
-u)
update=1
shift;;
*)
shift;;
esac
done
fi
echo "For League: $league"
echo "Report: $CHOICE"
echo -e "Update? $update\n"
if [[ ! -e "results.json" || $update == 1 ]]; then
curl -s "https://api.faceit.com/match-history/v4/matches/competition?id=$league&page=0&size=2000&type=hub" | \
jq -r .payload[].matchId 2>/dev/null | \
xargs -I{} curl -s 'https://api.faceit.com/stats/v1/stats/matches/{}' | \
jq '{matchid: .[0].matchId, players: [.[0].teams[].players[] | {hero: .i6, result: .i5}]}' 2>/dev/null | jq -s '' > results.json
fi
assume 5<< "EOS"
#!/usr/bin/python
import json
heroes = open('heromap.json')
results = open('results.json')
jsonheroes = json.loads(heroes.read())
jsonresults = json.loads(results.read())
hmap = {}
for h in jsonheroes:
hmap[h['key']] = h['value']
agg = {}
for match in jsonresults:
for player in match['players']:
if player['hero'] in agg:
agg[player['hero']]['matches'] += 1.0
agg[player['hero']]['wins'] += int(player['result'])
else:
agg[player['hero']] = {
'matches': 1.0,
'wins': int(player['result'])
}
import os
c = os.environ['CHOICE']
print "Hero,Games,Wins,Pct"
if c == 'matches':
for i, stats in sorted(agg.iteritems(), key=lambda (k,v): (v['matches'], k), reverse=True):
print "%s,%s,%s,%0.2f%%" % (hmap[i], int(stats['matches']), stats['wins'], (stats['wins']/stats['matches'] * 100))
elif c == 'pct':
agg = filter(lambda (k, v): v['matches'] >= 5, agg.iteritems())
for i, stats in sorted(agg, key=lambda (k,v): ((v['wins']/v['matches']), k), reverse=True):
print "%s,%s,%s,%0.2f%%" % (hmap[i], int(stats['matches']), stats['wins'], (stats['wins']/stats['matches'] * 100))
elif c == 'wins':
for i, stats in sorted(agg.iteritems(), key=lambda (k,v): (v['wins'], k), reverse=True):
print "%s,%s,%s,%0.2f%%" % (hmap[i], int(stats['matches']), stats['wins'], (stats['wins']/stats['matches'] * 100))
EOS
[
{
"key": "1",
"value": "Anti-Mage"
},
{
"key": "2",
"value": "Axe"
},
{
"key": "3",
"value": "Bane"
},
{
"key": "4",
"value": "Bloodseeker"
},
{
"key": "5",
"value": "Crystal Maiden"
},
{
"key": "6",
"value": "Drow Ranger"
},
{
"key": "7",
"value": "Earthshaker"
},
{
"key": "8",
"value": "Juggernaut"
},
{
"key": "9",
"value": "Mirana"
},
{
"key": "10",
"value": "Morphling"
},
{
"key": "11",
"value": "Shadow Fiend"
},
{
"key": "12",
"value": "Phantom Lancer"
},
{
"key": "13",
"value": "Puck"
},
{
"key": "14",
"value": "Pudge"
},
{
"key": "15",
"value": "Razor"
},
{
"key": "16",
"value": "Sand King"
},
{
"key": "17",
"value": "Storm Spirit"
},
{
"key": "18",
"value": "Sven"
},
{
"key": "19",
"value": "Tiny"
},
{
"key": "20",
"value": "Vengeful Spirit"
},
{
"key": "21",
"value": "Windranger"
},
{
"key": "22",
"value": "Zeus"
},
{
"key": "23",
"value": "Kunkka"
},
{
"key": "25",
"value": "Lina"
},
{
"key": "26",
"value": "Lion"
},
{
"key": "27",
"value": "Shadow Shaman"
},
{
"key": "28",
"value": "Slardar"
},
{
"key": "29",
"value": "Tidehunter"
},
{
"key": "30",
"value": "Witch Doctor"
},
{
"key": "31",
"value": "Lich"
},
{
"key": "32",
"value": "Riki"
},
{
"key": "33",
"value": "Enigma"
},
{
"key": "34",
"value": "Tinker"
},
{
"key": "35",
"value": "Sniper"
},
{
"key": "36",
"value": "Necrophos"
},
{
"key": "37",
"value": "Warlock"
},
{
"key": "38",
"value": "Beastmaster"
},
{
"key": "39",
"value": "Queen of Pain"
},
{
"key": "40",
"value": "Venomancer"
},
{
"key": "41",
"value": "Faceless Void"
},
{
"key": "42",
"value": "Skeleton King"
},
{
"key": "43",
"value": "Death Prophet"
},
{
"key": "44",
"value": "Phantom Assassin"
},
{
"key": "45",
"value": "Pugna"
},
{
"key": "46",
"value": "Templar Assassin"
},
{
"key": "47",
"value": "Viper"
},
{
"key": "48",
"value": "Luna"
},
{
"key": "49",
"value": "Dragon Knight"
},
{
"key": "50",
"value": "Dazzle"
},
{
"key": "51",
"value": "Clockwerk"
},
{
"key": "52",
"value": "Leshrac"
},
{
"key": "53",
"value": "Nature's Prophet"
},
{
"key": "54",
"value": "Lifestealer"
},
{
"key": "55",
"value": "Dark Seer"
},
{
"key": "56",
"value": "Clinkz"
},
{
"key": "57",
"value": "Omniknight"
},
{
"key": "58",
"value": "Enchantress"
},
{
"key": "59",
"value": "Huskar"
},
{
"key": "60",
"value": "Night Stalker"
},
{
"key": "61",
"value": "Broodmother"
},
{
"key": "62",
"value": "Bounty Hunter"
},
{
"key": "63",
"value": "Weaver"
},
{
"key": "64",
"value": "Jakiro"
},
{
"key": "65",
"value": "Batrider"
},
{
"key": "66",
"value": "Chen"
},
{
"key": "67",
"value": "Spectre"
},
{
"key": "68",
"value": "Ancient Apparition"
},
{
"key": "69",
"value": "Doom"
},
{
"key": "70",
"value": "Ursa"
},
{
"key": "71",
"value": "Spirit Breaker"
},
{
"key": "72",
"value": "Gyrocopter"
},
{
"key": "73",
"value": "Alchemist"
},
{
"key": "74",
"value": "Invoker"
},
{
"key": "75",
"value": "Silencer"
},
{
"key": "76",
"value": "Outworld Devourer"
},
{
"key": "77",
"value": "Lycanthrope"
},
{
"key": "78",
"value": "Brewmaster"
},
{
"key": "79",
"value": "Shadow Demon"
},
{
"key": "80",
"value": "Lone Druid"
},
{
"key": "81",
"value": "Chaos Knight"
},
{
"key": "82",
"value": "Meepo"
},
{
"key": "83",
"value": "Treant Protector"
},
{
"key": "84",
"value": "Ogre Magi"
},
{
"key": "85",
"value": "Undying"
},
{
"key": "86",
"value": "Rubick"
},
{
"key": "87",
"value": "Disruptor"
},
{
"key": "88",
"value": "Nyx Assassin"
},
{
"key": "89",
"value": "Naga Siren"
},
{
"key": "90",
"value": "Keeper of the Light"
},
{
"key": "91",
"value": "Wisp"
},
{
"key": "92",
"value": "Visage"
},
{
"key": "93",
"value": "Slark"
},
{
"key": "94",
"value": "Medusa"
},
{
"key": "95",
"value": "Troll Warlord"
},
{
"key": "96",
"value": "Centaur Warrunner"
},
{
"key": "97",
"value": "Magnus"
},
{
"key": "98",
"value": "Timbersaw"
},
{
"key": "99",
"value": "Bristleback"
},
{
"key": "100",
"value": "Tusk"
},
{
"key": "101",
"value": "Skywrath Mage"
},
{
"key": "102",
"value": "Abaddon"
},
{
"key": "103",
"value": "Elder Titan"
},
{
"key": "104",
"value": "Legion Commander"
},
{
"key": "105",
"value": "Techies"
},
{
"key": "106",
"value": "Ember Spirit"
},
{
"key": "107",
"value": "Earth Spirit"
},
{
"key": "108",
"value": "Abyssal Underlord"
},
{
"key": "109",
"value": "Terrorblade"
},
{
"key": "110",
"value": "Phoenix"
},
{
"key": "111",
"value": "Oracle"
},
{
"key": "112",
"value": "Winter Wyvern"
},
{
"key": "113",
"value": "Arc Warden"
},
{
"key": "114",
"value": "Monkey King"
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment