Created
August 30, 2015 11:57
-
-
Save npry/f96199e05b7234740d08 to your computer and use it in GitHub Desktop.
mmr guesser for DotA 2, based on /u/Erolon's original java implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| __author__ = 'mammothbane' | |
| import sys | |
| import requests | |
| from bs4 import BeautifulSoup | |
| import logging | |
| logging.basicConfig(level=logging.DEBUG, filename='guess.log') | |
| dotabuff_url = 'http://www.dotabuff.com/players/' | |
| for x in range(1, len(sys.argv)): | |
| y = int(sys.argv[x]) | |
| logging.info('checking dotabuff ' + str(y)) | |
| r = requests.get(dotabuff_url + str(y), headers = {'User-Agent': 'MMR-Guesser by mammothbane'}) | |
| if r.status_code >= 400: | |
| logging.error('error ' + str(r.status_code) + ' encountered fetching dotabuff profile ' + str(y)) | |
| continue | |
| soup = BeautifulSoup(r.text) | |
| mmr = 0 | |
| primary = soup.select('div.primary')[0].select('section') | |
| skill_check = primary[1].get_text() | |
| most_played = primary[0] | |
| if 'High Skill' in skill_check: | |
| if 'Very' in skill_check: | |
| mmr = 3800 | |
| else: | |
| mmr = 3000 | |
| elif 'Normal Skill' in skill_check: | |
| mmr = 1750 | |
| else: # no games rated by dotabuff, so assign a higher skill..? | |
| mmr = 2500 | |
| logging.debug('initial estimate: ' + str(mmr)) | |
| hero_mapping = {'Earth Spirit': 350, 'Juggernaut': 150, 'Troll Warlord': 150, 'Meepo': 500, 'Storm Spirit': 300} | |
| for f in hero_mapping.keys(): | |
| if f in most_played.get_text(): | |
| logging.debug('[+' + str(hero_mapping[f]) + '] ' + f) | |
| mmr += hero_mapping[f] | |
| most_played_hero = int(primary[0].select('.bar-default')[0].parent.get_text()) | |
| logging.debug('[+' + str(most_played_hero) + '] most played hero') | |
| mmr += most_played_hero | |
| stats_pane = soup.select('div.secondary')[0].select('section')[1] | |
| games_played = int(stats_pane.select('tr td')[1].get_text()) | |
| logging.debug('[+' + str(games_played//4) + '] ' + str(games_played) + ' games played') | |
| mmr += games_played//4 | |
| logging.info('dotabuff ' + str(y) + ': ' + str(mmr)) | |
| print('Estimated MMR: ' + str(mmr)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment