How we built a bot to manage our studio pool games
This is what inspired us to get creative with our pool tables in the London and Bristol studios. In the beginning, the team mostly used games of pool to facilitate impromptu chats about complex bugs and other tech headaches.
Over time, a colleague and myself started recording pool victories against one another in a grid on an unofficially-reserved whiteboard in the studio.
Before long, that faint whiff of competition evolved into a thick stench, and it became clear we needed something else. The whiteboard, limited by its 2D existence, wouldn’t scale to our needs.
Victories and defeats against others still had to be mostly manually recorded. We like building solutions to “problems” like this, so that was how Poolbot was created.
Poolbot is now our resident cue-sports statistician manifested as a Slack bot. Channeling the likes of Hazel Irvine and Steve Davis, it knows all about what goes on on the baize.
The architecture of Poolbot is a simple client server setup, and uses a tech stack common to many Potato projects. The Slack bot client is written in pure Python and consumes messages returned by the Slack real time message API.
The server is hosted on Google App Engine and runs off a Djangae app. Data is stored in the Datastore, and consequently we denormalise a lot of things across the various models to improve performance and reduce latency.
We use trusty DRF to expose various RESTful API endpoints, to which the client (and other integrations including the NFC reader) can send HTTP requests.
To record a victory, you can just roll into Slack, type
"@poolbot record beat @user_handle" and watch the ELO points trickle in. Yes, we've implemented the ELO rating algorithm to keep some leaderboards – a global one and a seasonal one (we have a new season every 10 weeks) - the top positions of which are coveted by all.
That’s not all Poolbot knows. It comes with a small set of other commands:
"@poolbot form @user_handle": see how that user has performed recently
"@poolbot elo @user_handle": see how your ELO ratings would be affected by playing the other person
"@poolbot head-to-head @user_handle": see your recent form against the other person
"@poolbot stats @user_handle": see that user's lifetime & season stats
"@poolbot spree @user_handle": see that user's current killing spree (number of games won without a loss)
Poolbot’s career progression roadmap has been outlined too, with it expected to grow into such roles and responsibilities as:
- 9-ball mode
- Allowing users to mount challenges against another player
- Betting extra ELO points on a game
- Doubles matches
- Recording game results via a mobile app and NFC
- Plotting performance over time
- Recording extra stats per game
- Eventually sentience and refereeing capabilities (erm, probably)
Here are some of our up-to-date stats:
- Number of players on leaderboard: 78 (this is almost everyone in London and Bristol)
- Number of games recorded: 4,248 (this includes many games out of office hours…)
- First victory recorded on: 7 April 2016
- All-time ELO high: 1,384
- Current season ELO high: 1,157
One of the great things about Poolbot is that it has brought both studios together over a shared passion. Developing it also gave us an unexpected opportunity to explore text as UI, which helps to keep our skills sharp in our everyday work.
If you like the sound of Poolbot, you can use it too. All you need is a Slack team, somewhere to host the client (which can use WebSockets), and a Google App Engine account for the server. Let the games begin!
Originally published at p.ota.to on 31st January 2017