We take things very seriously here at Segment. But nothing is taken more seriously than our ping pong, which explains why we play on a non-Olympic regulation sized table (that sits snuggly above our junior-sized pool table), in addition to our sole use of one star balls. In fact, the Ping Pong culture at Segment is so strong, we even have a dedicated Slack channel for it.
But what fun is it to play Ping Pong with your co-worker without keeping track of everyone's skill level, especially in a low-friction, asynchronous way? Being the resident Derp Engineer, I knew it was mostly on me to solve this in a manner most obtrusive and obnoxious—by writing an app.
Elo rating system
The Elo rating system is a method for calculating the relative skill levels of players in head-to-head games such as chess. Currently, it has been adapted for use in many multiplayer video games and team sports, including football, basketball, baseball, competitive programming.
The basic principle is that the difference between two players ratings will serve as a predictor of the outcome of the match (two players with the same rating will be seen by the Elo system as having equal chances of winning). The winner of the match will take a proportional number of points with regards to the predicted outcome from the loser, i.e. if the player with the higher Elo rating going into the match wins, then she will take fewer points from the loser; if the player with the lower Elo rating wins, then that player will take more points.
I did a quick search on NPM (using the awesome `npm` Alfred workflow command) and came across this module, elo-rank, that takes two players starting ratings, the outcome of the match, and returns the new ratings (example below).
var elo = require('elo-rank'); var playerA = 1200; var playerB = 1400; //Gets expected score for first parameter var expectedScoreA = elo.getExpected(playerA, playerB); var expectedScoreB = elo.getExpected(playerB, playerA); //update score, 1 if won 0 if lost playerA = elo.updateRating(expectedScoreA, 1, playerA); playerB = elo.updateRating(expectedScoreB, 0, playerB);
With this library, I decided to put together a very simple app to maintain the ratings of our Ping Pong players at Segment.
Ladder: NodeJS, MongoDB, Koa, Deku
The front-end is just built with these components.
And here is the finished product:
Being a Slack-forward organization, I decided to add some notifications to our beloved #pingpong channel with PongBot:
I setup PongBot with [Heroku Scheduler](https://addons.heroku.com/scheduler), to send the top five in the ladder to Slack every morning at 9am. I updated the `Makefile` to include the command with which Heroku Scheduler can kick off the request:
# Push to slack-ranking. slack-ranking: node_modules @node --harmony server/slack/ranking
The `server/slack/ranking` file will grab the top five in the Mongo database, format it, and then `POST` it to the #pingpong Slack endpoint.
For the real-time updates, I also added logic to grab and format the relevant information and then to `POST` to the endpoint whenever a new game outcome is submitted through the app.
*Note that PongBot is currently closed source, because I am lazy and have our Slack token in the repository. Maybe I'll open source it for other teams if there is interest!*
You can deploy your own very easily by following the instructions/using the `Deploy on Heroku` button on the GitHub page (link below).
Other Ping Pong hacks, apps, projects
It is no secret that any area with a high concentration of nerds, there will organically emerge some kick ass DIY projects around Ping Pong. And the Bay Area is no exception.
We really respect the team over at Campaign Monitor, not only for just being rad people, but also for taking their ping pong culture so seriously that they actually spun out their in-house ping pong pet project into its own commercial product, Ping Pong Ninja.
Sure, tech-minded folks have been chastised for spending resources on solving problems for the 0.01% (you read correctly, the one percent of the one percent), such as world famine and privilege distribution. I suspect its only because the public has overlooked the tremendous contributions of Si Digital to the Ping Pong world, using RFID tags in the players' bats to track them, tapping buttons under the table to indicate a point, and having giant display screens in the room to keep score.
We plan to hold 5-on-5 Ping Pong tournaments between companies! We just played Sift Science a month ago (we lost 3-2, unfortunately) and it was a ton of fun!
Want to challenge the Segment team to a match? Contact me and we'll get it setup!