Join Simon Allardice for an in-depth discussion in this video Exploring Lake Pend Oreille, part of Code Clinic: Swift (2015).
(robotic music) - Welcome to Problem number one in Code Clinic for Swift. I'm Simon Allardice. Code Clinic is a course where each month a different programming problem is given to a collection of lynda.com developer authors and we solve that problem using our programming language of choice. It gives us the opportunity to explore several things, different approaches to solving a problem, the pro's and con's of languages and technologies, a chance to talk about software architecture, and some tips and tricks to incorporate into your own coding practices.
This first problem is all about data. It's working with statistics and, to some extent, getting started handling big data, to manipulate and summarize large collections of information, to get insights you couldn't get from staring at thousands of data points. In this problem, I've been asked to use weather data collected by the US Navy from Lake Pend Oreille in northern Idaho. This is the fifth deepest freshwater lake in the United States. It's deep enough that the US Navy tests submarines there. And as part of that testing, the Navy compiles an exhaustive list of weather statistics, wind speed, air temperature, barometric pressure.
All of these measured every few minutes of every day sustained over years. You can view this data by pointing your web browser at lpo.dt.navy.mil. You'll find several weather summaries, a webcam, and the raw data they collect saved as text files. Now for anyone living or working on the lake, weather statistics are an important part of every day life. The average wind speed could be very different than the maximum or even the median wind speed especially if you're on a small boat in the middle of the lake. So, in this Code Clinic, the different authors have been asked to use their favorite language to calculate the mean and median of the wind speed, air temperature, and barometric pressure for a given range of dates.
But this isn't just about making a few calculations. It's also how do we get that data? It might be viewable on this website but how do we get it into our applications? And once we have it, how should we show it? Before we begin, for those of you who haven't worried about such things for awhile, we should review mean and median. These are both statistics and we need a set of numbers. How about 14 readings for wind gust at the Lake's Deep Moore weather station on January the first 2014. 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. So our first statistic, the mean, is also known as the average. To calculate the mean of a collection of values, we simply add all the values together and then divide by the number of values. In this example, we 14 plus 14 plus 11 plus 11 plus 11 plus 11 plus 3 plus 7 plus 7 plus 7 plus 7 plus 4 plus 8. Then we divide the sum by 14, the count of numbers in the set. In this case, the mean is equal to 9. But the median is different.
The median is the value you find right in the middle of a sorted range of values. Think of the median as in the median strip of the road. It always marks the center of the road. To calculate the median, we don't do any adding up. We first sort all the values from lowest to highest. If there is an odd number of values, then we just take the exact middle number in that sequence. If there is an even number of values, we don't have an exact middle, so we take the middle two numbers and split the difference, calculating the mean average of those middle two numbers.
In this case, there is an even number of values here. So we sort, then mean average the middle two values 8 and 11. So, the median is 9.5. Sometimes you'll find the mean and the median are the same. But here, as is common, they are slightly different. So, this is our first challenge. Calculate some statistics from weather data available online. Perhaps you want to pause and create a solution of your own. How would you solve the problem with just with you know now? In the next few videos, I'll show you how I approached it.
Simon introduces challenges and then provides an overview of his solutions in Swift. Challenges include topics such as statistical analysis, searching directories for images, and accessing peripheral devices.
Skill Level Intermediate
Q: I am unable to access the Lake Pend Oreille data from outside the U.S.
A: A static copy of this data is provided here for lynda.com members outside of the U.S