Story Details for articles

Golf Tracker - Ep. 11 - Application Evolution

Date Posted:
8/24/2011 7:52:14 PM
Date Updated:
8/24/2011 7:52:14 PM
0/0 votes
Programming Language:
golf, golf tracker, requirements, golf holes, par, tees
Demo site:
Home Page:

Golf Tracker - Application Evolution

This moment had to come.  New requirements have just come in from the client (me) on how the application needs to change in order for it to be better.

One of the primary changes that need to be made is how the player's handicap index is entered into the system.  Presently I have a page where the player enters in his name and handicap index.  If you know anything about golf you'll realize that this is not the best scenario.  This can promote, er, what's the word I'm looking for, oh, CHEATING!!!.

A player could enter an index that is higher than the skill level they play and end up winning every time against other players.  There needs to be a better way of handling this, and there is.

And as good developers, it's important for us to know as much about our clients business and how it works in order to better understand what is necessary to build their application.  So I'll go into some detail about what golf is and how it works, and how the new requirements will impact the development of this application.

New Requirements

The simplest way to solve this problem is to prevent the player from having to enter their own handicap index at all.  What will happen is that the player will simply post their score for a round of golf, and the MVC application will calculate their handicap index based on their scores.

So for this to happen, many things need to change within the existing application.  I'll first illustrate why these changes need to be made.  The image below is similar to what the client wants the application to look like and operate.

SCGA index list page

This is the Southern California Golf Association (SCGA) Handicap Index information page for a player.  In this case it's mine.  The client wants the application to have a resulting page look like this.  On the surface, this looks pretty simple, but when we analyze what's going on in the background to get this information, there are some significant changes we'll have to make to the application and the database.

There are a few things that are new such as:
  • Date - the date the round of golf was played
  • Score - the actual adjusted gross score for the round
  • Course Rating/Slope - values that help determine the golf course's difficulty
  • Differential - the result of the calculation of the score against the course rating and slope used to determine the golfers handicap index

What is Golf?

If you have never played golf, I'll go over how golf is played and scored. 

Golf is a stupid game that millions of people around the world pay good money for.  The basic premise is you have a little white ball and a bunch of clubs.  You use the clubs to hit the ball into a hole that is on a nice smooth grassy surface called a green, that can be more than 500 yards away.  You also are not allowed to touch the ball until it drops into the hole, so where ever you hit the ball, you have to hit it from there as it lies.

As you play each golf hole, you keep track of the number of times you hit the golf ball.  And unlike most sports like bowling, a low score is desirable.  There are also a boat-load of rules that can jump up and bite you in the ass if you aren't paying attention.

Below is an image of a typical golf hole on a golf course.  A standard golf course has 18 holes.  Every golf hole is different in it's yardage, layout and difficulty.  The Par for any particular hole generally is one of either Par-3, Par-4 or Par-5.

typical golf hole

  1. Tee boxes
  2. Water hazard
  3. Rough
  4. Out of bounds
  5. Sand trap
  6. Water hazard
  7. Fairway
  8. Green
  9. Pin
  10. Hole or Cup

The above image illustrates what a typical golf hole might look like.  You'll notice that it has three tee-boxes (1), each with a different color designation, Gold, Blue and White.  Also each tee-box has it's own yardage.  The further back the tee is from the green (8), the more difficult it is.

The primary things we should be aware of is the Tee (1), the Fairway (7) and the Green (8). 

Par is the value of a particular hole that follows these guidelines:
  • Every hole has a tee box and a green
  • Allow 2-putts on every green
This means that to score a 3 on a par-3 hole, you need to land the ball on the green on your first shot, then if you can get the ball into the hole in two putts, you'll make a par. By counting each shot, your first shot lands on the green, you miss your first attempt with the putt, but you make your second putt, score of 3.

par-3 hole

To make a par on a par-4 hole means you take two shots to reach the green and two putts on the green.

par-4 hole

On a par-5 hole, it should take you three shots to reach the green and two putts for a par.

par-5 hole

This isn't to say you can't make par other ways.  One way would be to reach a par-4 green in three shots and then make one putt, or even miss the green on your third shot and chip it in.  The point is, that the guidelines that stipulate how to figure out par on a hole is based on the perfect way to play the hole.  Your score is simply how many strokes you take to play each hole and then you add them up to get your total score for the round of golf.

Now back to the Course Rating and Slope and yardage, and stuff.  To get a better understanding of what these values are, I'll explain using a typical score card for a golf course.

typical score card

This score card just shows the front nine but that will do for this explanation.

As I mentioned, every hole has at least one tee box.  Most have more.  For this golf course there are three tees that are color designated, Black, Blue and White.  Each tee also has it's own Course Rating and Slope.  The Course Rating is the decimal value and the Slope is the three-digit whole number.  The reason each tee has it's own set of Course Ratings and Slopes is due to it's difficulty. 

The tees farther back will generally be hardest, the middle tees will be medium difficulty, and the front tees will be the easiest.  This is to allow players of different skills levels to play the same golf course and be able to choose their level of difficulty that they want to play.  Also at the very bottom of the card is the Red tees which are for the Women.

The Course Rating is what could be considered an average score for a scratch golfer (a player that always shoots around par) for 10 rounds from those tees.

The Slope is a convoluted number the USGA folks came up with to make calculations harder.  No just kidding, it's also a rating of difficulty for the golf course and that set of tees.  Slopes go from a low of around 67 to as high as 152.  Of course the higher the slope for a golf course, the tougher the golf course is.

Then you'll notice that each hole has a different yardage for each tee.  When a player decides on the first tee which set of tee boxes he will play, he must play those tees for the entire round for the score to be valid.  In other words, if you start on the White tees, you must play ALL white tees for the entire round.

So how does this affect players?

Let's take for example two good friends want to play a round of golf together but each of them are of a different skill level.  The score card below illustrates this.

score card with scores

I have removed the score for the back nine in this example, but this is good enough for this demonstration.

Let's assume Joe and Frank are good friends and they both know how each other plays.  And let's assume that these scores that they shot today are indicative of their skill level.  This would mean that, by looking at the gross scores, Joe is the better player since he shot 73 and Frank shot 80.

As a reminder, in golf a low score is better.

But they both like to play a friendly game with a couple bucks on the line.  If they were playing even, meaning they were playing without handicaps, then Frank wouldn't be the sharpest tool in the shed if he agrees to play Joe even.  Since Joe is the better player, he would win almost 10 times out of 10.

By being able to use handicaps, they can play against each other on a more level playing field.  This is shown by their net scores (the total of their gross score minus their handicap), which are 71 and 69 respectively.  In this case we can see that Frank has won this round, but not by much.  They both played better than their handicaps since their net scores are both under par, but Frank played just a little better.

So now what?

Now there are still some questions that need to be answered before I can begin making these changes.
  • Where does the Handicap come from?
  • Is the HandicapIndex and Handicap the same?
  • If the Handicap is calcluated, how do we calculate it?
  • To calculcate it, we need a Course Rating and Slope
Let's take a look at how the SCGA web site allows players to post the golf scores.

Step 1

The golfer enters his handicap number and last name

enter handicap number to post a score

Step 2

Then the player is shown the page to enter their round of golf information.

post a score blank page
This is similar to what the client wants created for this Golf Tracker application.  He wants players to simply enter their scores into the system and have the system calculate their handicap indexes.  This way there won't be any cheating by the players.

But for the sake of this application which is NOT going to be a robust golf handicapping application, I won't be including three items from this form:
  • Type - this tells the system whether the round of golf is a casual round, a Tournament round, etc.  This type is important to determining how to calculate the handicap index.
  • Holes - we will assume for this application that all rounds posted will be 18 hole rounds.  9 hole rounds will not be available.
  • Rating/Slope Entry - this selection just gives the player the opportunity to enter the Course Rating and Slope for a golf course that may not be in the system.
After the player has selected the date of the round, he can select what State the golf course is in, and then the first letter of the name of the golf course. This next image shows that the Course drop down is populated with all the courses in the selected state that begin with the selected letter.

select a golf course to post a score

Once the golf course is selected, the Tee drop down is populated with the list of tees for that course.

list of tees to post a score
The player would select the set of tees they played from and you'll notice that each tee is associated with a Course Rating and Slope.  This is what helps drive the calculation.  Once the tee is selected, the player can enter their adjusted score.

enter the adjusted score
The ESC Score is the Equitable Stroke Control score.  This stipulates that a player is limited to a score for any particular hole.

ESC score explanation
The way this reads is that if your handicap for this course is 9 or less, then the highest score you are allowed to take on any particular hole is a double-bogey.  This means you need to go over your scores and make sure you make the adjustment before posting your score.

As an example, let's say that Joe who is a 2-handicap golfer had a 6 on a par-3.  That's a triple bogey and it's not allowed to be posted.  So he would need to adjust his posted score for that hole to no more than a double-bogey 5, which reduces his gross score by 1-shot.  So if he shot a gross 73, then his adjusted score that he would be required to post would be 72.

Let's take another look at the player score list.

list of scores
So once I build a proper score posting form I'll know how the scores get into the system, but what is this differential?

More calculations

In order to calculate the Handicap Index we need to get the differentials for each round of golf.

differential slide

Looking at this slide we can see the USGA formula for calculating the differential for a round of golf.

((gross score - CR) * 113) / slope = differential

First we subtract the Course Rating from the gross score, then we multiply it by 113.  113 is the average slope for all courses.  Then we divide that result by the slope to get the differential for a round of golf.  And then it is rounded to one decimal place.

Then finally the Handicap Index is derived by taking the best 10 differentials from the last 20, and calculating the average.  And in the case of the image above it results in 1.1 as the Handicap Index.

What's the difference between the Handicap Index and the Handicap?

The difference between these two are:
  • Handicap Index - the decimal value which is an average of indexes calculated from many scores.
  • Handicap - the whole number value which is used to calculate the net score for a single round of golf.
So how does a player figure out what their handicap is? 

When a golfer is ready to play a round of golf with his buddies, he needs to have a handicap for the course they will be playing.  The Handicap Index has nothing to do with golf courses.  The Handicap does.  To get the handicap, the golfer needs to consult a sheet that is generally posted inside the golf shop of the golf course to figure this out.  The image below shows such a chart that designates handicaps for the slope of a particular golf course.

slope ratings charts

Let's say these golfers are going to play a course with a slope of 131, and golfer #1 is a 9.9 Handicap Index.  If he looks at the chart he'll see that on this golf course, on this set of tees, he'll be playing at an 11-handicap.

But just to illustrate more how the slope affects your handicap, if they were playing a golf course with a slope of 132, golfer #1 would be a 12-handicap. 

Whew - now what?

Now it's time to figure out what's necessary to refactor this application to allow for this new requirements.  The first thing that I can see is that the database schema needs to change.  This is what we have right now.

present database schema

You can see there is no place to store Course Rating, Slope, Differentials, tee assignments, etc.  What it seems like I need is a table for Tees.  This is what I came up with.

desired database schema

Now I have a way of collecting and storing data about the various tees for each golf course and using that to calculate the players handicap indexes.

Plan of Attack

The plan of attack I've come up with is the following:
  • Refactor the database
  • Refactor the DataObjects
  • Refactor the BusinessObjects
  • Create a GolfTrackerAPI to handle calculations
  • Update the Server Layer to communicate with the new API
  • Modify the controllers and views for the new requirements
The interesting point here is that I've decided to create a GolfTrackerAPI to handle all the calculations.  This includes handling all the data that will generate the player scores list like the USGA page I've shown.  Since there's a lot of calculations that need to execute, I want to have a single API handle it all so it's easier to manage in the future.

The controllers will still only communicate with the services, but for these new calls, the services will be communicating with the new API instead of directly with the data repositories.  Here's a diagram of what I have in mind.

Golf tracker api structure


Now that all this is on the table, I'm going to have to build the damn thing.  :^)  That's will I'll do in the next episode.

Stay tuned.


    No comments yet.


User Name: