The staff at the startup I was in around 2013 conformed to stereotype by playing a lot of Foosball, and quite competitively at that. To revel in this, I decided to write an app that would a) allow us to track games and b) provide a ranking of players!
For tracking games, a very basic Flask app with a form for submission and list of games would suffice.
For ranking I chose to implement an ELO scoring system. This was modified to account for having two players on each team by assuming the combined ability is the sum of the two players. The system actually tracked three scores: one that ignored position, one that only made a change when the player was in the front and one that only made a change when the player was in the back.
I chose to store the progression of a players ELO score over time, allowing fun graphs of your progress:
As well as calculating your current ranking, I also stored the ranking over time. This allows a fun “bumps style” graph showing the change in rankings over time:
The code is on github at https://github.com/davidn/foosball
To allow adding games out of order, I chose not to persist the ELO scores and rankings in the database; they were instead calculated from scratch on demand and cached. The memory this took required large App Engine instances than I would have liked. This also made viewing scores and rankings randomly slow, as when a game was added or the cache was empty recalculation would happen during a page view.
A better design would have been to persist scores in the database – even if this is somewhat denormal – and do the recalculation when adding a game. It would be relatively simple to have made adding games in the past possible anyway, by calculating scores forward from there.
This project is still live at elo-foosball.appspot.com, although a game hasn’t been added in nearly 10 years!