Introducing Lake Pend Oreille

show more Introducing Lake Pend Oreille provides you with in-depth training on Developer. Taught by David Powers as part of the Code Clinic: PHP show less
please wait ...

Introducing Lake Pend Oreille

Hello, and welcome to Code Clinic. My name is David Powers. Code Clinic is a monthly course where unique a problem is introduced to a collection of authors. In response, each author creates a solution, using the programming language of their choice. In my case, I'll be using PHP. You can learn several things from Code Clinic. Different approaches to solving the problem, the pros and cons of different languages, and some tips and tricks to incorporate into your own coding practices.

This month, we'll work on a problem in statistical analysis and to some extent, handling big data. It's common to use a computer to manipulate and summarize large amounts of information, providing important insights into how to improve or handle a situation. In this problem, we'll use weather data collected by the US Navy from Lake Pend Oreille in northern Idaho. Lake Pend Oreille is the fifth deepest fresh water lake in the United States. So deep in fact, that the US Navy uses it to test submarines.

As part of that testing, the US Navy compiles an exhaustive list of weather statistics, including wind speed, air temperature and barometric pressure. You can browse this data by pointing your browser at You'll find several weather summaries, a web cam, and the raw data they collect every five or six minutes archived as standard text files.

For anyone living or working on Lake Pend Oreille, weather statistics are an important part of every day life. Especially if you're on a small boat in the middle of the lake. There can be a significant difference between average wind speed and median wind speed.In this challenge I'll be using PHP to calculate the mean and median of the wind speed, air temperature and barometric pressure recorded into the Deep Moor station for a given range of dates. The other authors will each use their own favorite language to solve the same problem.

First, let's briefly review mean and median. These are both statistics, to explain how they're calculated, we need a set of numbers. How about 14 readings for Wind Gusts at Deep Moor weather station on January 1, 2014. You can see the data of this website. The first column, is the day the wind gust was recorded. The second column, is the time it was recorded. And the third column, is the wind gust in miles per hour. The mean, is also known as the average.

So calculate the mean of a range of numbers, simply add the values in the set and then divide by the number of values. In this example, we add all of these numbers together and then divide the sum by 14 the amount of numbers in the set. In this case, the mean is equal to nine. The median is the middle value in a set of data sorted in ascending order. Think of the median as the median strip of the road, it always marks the center.

To calculate the median first, sort the numbers from lowest to highest. If there's an odd number of values, then just take the middle number. If there's an even number of values, then calculate the average of the central two numbers. In this case, there's an even number of values. So we sort, then take the average of the middle two values, eight and eleven, so the median is 9.5. In addition, some offices including myself have chosen to implement a web service to provide access to the new weather statistics created by the author's program.

This is typically done by creating a RESTful API, which when called, returns information in a format known as JSON. For a detailed description of JSON and its uses please, refer to JavaScript and JSON by Ray Villalobos. If you make this http call to my website of, you would expect to receive the mean and median for wind speed, air temperature, and barometric pressure for the range of dates starting from March 19, 2011, and running until midnight of the following day.

The JSON data returned looks like this. So that is our first challenge. Pull statistics from a data set available online. Perhaps, you want to pause and create a solution of your own. How would you solve the problem? In the next videos, I'll show you how I solve the challenge

Introducing Lake Pend Oreille
Video duration: 5m 4s 4h 44m Intermediate Updated Dec 16, 2014


Introducing Lake Pend Oreille provides you with in-depth training on Developer. Taught by David Powers as part of the Code Clinic: PHP

please wait ...