I like to think of personal projects as a way of improving my coding and learning new areas of programming. Having only done theoretical astrophysics in my research before summer 2018, I hadn’t actually worked with big data – in the sense of oodles and oodles of independent records. Working with simulations means you’re looking at huge files that take hours upon hours to create and run calculations over, so it’s a different ballgame.
At the same time, I wanted to learn about APIs and get some practice working with one. It turns out that Riot Games, the company behind the popular massively multiplayer game League of Legends (LoL), maintains a public developer API for working with user information and match data. Having played LoL for around two years, I figured a great way to get my hands dirty and pick up new skills would be to build a project using in-game stats across many users and matches. Others have attempted to correlate match outcomes with player stats using ML with varying success, but I was more interested in non-trivial metrics that you could quote and use to actually analyze your gameplay. Metrics that weren’t necessarily pre-packaged for you in the API but could be calculated with enough match data.
Python is my language of choice, so I framed the project as a package called
predictlol. I named it this because the first thing I did was learn how to ping the API with the
requests module, and wrote a command-line Python script which, given a match, nicely printed out the username, rank, winrates, and games played for each of the 10 players in the game (5 on each team). Riot has an endpoint for current game stats, so the script can also print out these stats for a game that is in progress. It was already pretty fun to run the script right after I started a new game to size up my teammates and opponents – just the fact that it worked. None of these stats in themselves are necessarily great indicators of whether a player will succeed or fail in-game, but sometimes they tell a good story in what to look for as you’re playing! So really I wasn’t predicting outcomes per se, but instead I sought to inform likely outcomes based on past performance.
Now, due to the rate limiting on API requests with a developer key, this was about the most I could do real time. The next step was to mine enough data that I could generate more advanced stats than the ones the game calculates and stores at the end of every game. I decided somewhat arbitrarily that to search for match data I would: (a) take my last 100 ranked games, (b) take the 10 players in each game, (c) save the match data of each player’s last 100 or fewer ranked games, and (d) . After experimenting a bit, I bumped it to searching my last 120 ranked games for players, since some players didn’t have data anymore, or had too little, etc.
I came across a few small issues with this. Pulling data from on order 100 * 10 * 100 = 100,000 games with a rate limit of 100 requests per 2 minutes meant approximately 2000 min = 33 hr 20 min of scraping time. And that’s the ideal – in practice, I had to set a delay per request a little higher than the rate limit, in case it averaged out to be a little faster than the rate limit. I was running all this on my laptop, so I needed a continuous connection to actually get data. And even if I was getting data, sometimes the data was incomplete or flat out didn’t exist on the actual Riot server. So I built some safeguards for all of these problem areas (including using Python’s
smtplib to email myself if the code broke for some reason, which actually ended up being useful) and eventually cranked out all the data mining. Finally!
I’m still playing around with different custom stats, trying to find metrics that I would find helpful to see when I get into game or in comparing my performance with others post-game. The fact is still that 100 games per player is not that much, especially since some players haven’t actually reached the 100 game mark in the first place. Nevertheless, this project was already really neat as a playground for learning things I’d never touched before! I hope to eventually have
predictlol in a good enough place to “release” as a clean, well-documented package with which other LoL developers can experiment!
The project is located at github.com/lol-playground/predictlol.