Insights

Building a real-time golf leaderboard

By and
Tuesday, 1 September 2020

Insights

Building a real-time golf leaderboard

By and
Tuesday, 1 September 2020

As more and more people are enjoying opened golf courses right now, we want to share some learnings from the Twitter Data Partner Cup that we hosted last fall. The format was a 'shotgun scramble' golf tournament in Los Angeles, CA meant to celebrate a few of Twitter’s Data partners and their customers for a day of fun on the links. If you are unfamiliar with the scramble format, each member of a four-person team tees off and the team repeatedly picks the best shot until the hole is completed. With a 'shotgun' start, there are 18 teams that begin play simultaneously – each starting on a different hole. For example, team 8 starts on hole 8.

With most non-professional golf tournaments, the team scores are typically not known until the very end when the scorecards are turned in. How cool would it be to get real-time score updates during the game? We saw this as an opportunity to create a tool that would allow for a live scoring system. This system could enable teams to submit their scores from the course as holes are completed, and the compiled scores could be shared via a live leaderboard, helping to fuel the competition.

This post is unavailable
This post is unavailable.

As members of the Twitter Developer Relations team, we felt up for the challenge to build such a scoring system with the Twitter platform. We began prototyping a solution during a company hackweek. We first sketched out a technical design for a system where:

  • Team scores are submitted via Direct Messages.
  • When a score arrives, the score is stored, a new leaderboard is generated, and that leaderboard is immediately sent back to the scorer via a Direct Message.
  • When a score arrives that’s under par, a congratulatory Tweet is posted.
  • Event "marshals" are enabled to post leaderboard Tweets as the event unfolded.

It became clear that we'd be building a Twitter chatbot, where private messages (Direct Messages) provide the main communication channel, while also having the ability to communicate with public Tweets.

Design and Twitter building blocks

When we thought about the features we'd want for such an app, these surfaced as the main features:

  • Scores are submitted via Direct Messages using a simple format that encodes the team number, the number of the hole just completed, along with the score. Each team has a score keeper, and this player is taught how to submit scores.
  • When a player submits a score, they should receive an updated leaderboard via Direct Message. This serves as confirmation that the score was received and accepted.
  • The system needed the ability to support updating an incorrect score. Mistakes will happen.
  • If the score is below par, a Tweet is automatically posted to publicly congratulate the team. #BirdieAlert
  • The app should support a set of admin-level commands that only event marshals have access to. For example, these marshals decide when to publicly Tweet the leaderboard, typically every 20-30 minutes. We did not want to Tweet a leaderboard every time a score is submitted since a total of 324 scores are expected.
  • The leaderboard should look good and be easy to understand. Building a leaderboard graphic took considerably more effort than expected. See below for the final output.
This post is unavailable
This post is unavailable.
This post is unavailable.

With these design goals in mind, we began to build with the following Twitter API endpoints, which provide the foundation for any Twitter chatbot:  

  • Account Activity API - We knew we were building a 'listening' application, and we needed to listen for incoming Direct Messages with scores. The webhook-based Account Activity API (AAA) provides these real-time listening skills. The AAA provides the bridge between your web app and Twitter. We created the @HackerScorer account to host the chatbot and subscribed that account to the AAA service.
  • Direct Message API - When a score was received, the chatbot was designed to immediately respond to the scorer with an updated leaderboard in a Direct Messages. So, we knew the Direct Messages API would provide the fundamental 'submit score' communication channel.
  • POST statuses/update - The @HackerScorer account needed to Tweet when the event marshals triggered a leaderboard update. The system was also designed to send a congratulatory Tweet automatically when a score arrived that was under par.

Learnings and next steps

Even though we were testing and debugging up until the night before the event (like any hackweek project), we are happy to report the leaderboard app worked nearly flawlessly. The ability to see how other teams were scoring added to the excitement as the event progressed. Seeing notifications of other team's subpar holes added to the "what's happening now?" experience.

The main day-of-show challenge was spotty cell coverage out on the course. It's definitely recommended to test coverage at the event location beforehand. Also, in some cases, there clearly was not enough training on how to submit scores correctly the first time (we will not name names). Finally, we built the app to Tweet only when teams scored a Birdie (one under par). While Eagles (two under par) were not expected, they happened several times and were not Tweeted about. More sadly, there was a hole-in-one that went completely unacknowledged in real-time. Next time, we’ll be sure to account for these rare events and notify the audience!

This post is unavailable
This post is unavailable.

Not into golf? That's OK. Keep in mind that the framework used here to support a live golf scoring system is general enough for other use cases. This design could be used for a variety of other scenarios like scavenger hunts and other sports tournaments, such as soccer and bowling. Beyond shared sporting events, these patterns can support private polls by receiving private votes and rankings and publicly sharing compiled results at their completion.

The next time you’re planning a tournament or friendly game, think of Twitter.

Want to learn more about building Twitter chatbots?

The @HackerScorer chatbot was developed in Python using Flask. See the project's GitHub repository for more details.

If you want to learn more about how this live scoring app was developed and deployed, see our code-driven blog post about this prototype. This blog post is split into four parts, focusing on getting started with Twitter chatbots, designing the chatbot experience, developing the database-driven scoring system, and generating leaderboard graphics in real-time.

This post is unavailable
This post is unavailable.