Viewers: in countries Watching now:
Many successful programmers know more than just a computer language. They also know how to think about solving problems. They use "computational thinking": breaking a problem down into segments that lend themselves to technical solutions. Code Clinic is a series of six courses where lynda.com authors solve the same problems using different programming languages. Here, David Powers works with PHP.
David introduces challenges and provides an overview of his solutions in PHP. Challenges include topics such as statistical analysis, searching directories for images, and accessing peripheral devices.
Visit other courses in the series to see how to solve the exact same challenges in languages like C#, C++, Java, Python, and Ruby.
If you think this task simply involves calculating mean and median averages, think again. Calculating the averages requires only a few lines of code and you're done. Now this task goes much deeper. Maybe not as deep as Lake Pend Oreille, but deep enough. Let's take a look at the way the Pend Oreille raw data is organized by going to the website. Then clicking the raw data link on the main page and it's deep more weather data that we want. And the environmental data for 2001 through to 2010 is stored in these large text files.
They range in size from about one and half megabytes. To this one for 2008, which is nearly seven megabytes. But if we look at the date for 2010, we can see that it comes to an end in late May. Thereafter, each measurement is in a separate file that contains just one day's data. So if we open this 2014 folder, we can see inside the series of other folders one for each day. And if we just open one at random we can see there are 11 files in there one for each different type of measurement.
We're interested in only three, air temperature, barometric pressure and wind speed. Getting and processing the data for one or two days can be done very quickly. But let's say someone requests a longer range. Even at several pages a second, the response is going to be too slow for a web service. And anyway the historical weather data is never going to change so it makes sense for a web service to cache it. So the approach that I took was to download the environmental data files for 2001 to 2010.
So let's go back to my editing program. And I've got them all stored here in the raw data folder. And I created a script to process them, to batch process them. Extracting the information that I wanted at inserting this into a database. Because the data is stored in a predictable format, PHP's file and string manipulation functions make it easy to crunch thousands of lines of data. But there's a nasty surprise. The data from 2007 is stored in a different format from proceeding years.
So this script needs to take account of that. The next task was to handle one day at a time. So I created a class which does exactly that. And then, ran it in a loop to get one year's data at a time. And this same class now updates the database automatically, once every 24 hours. The final part of the task was to create the web service. The great news is the PHP provides all the necessary tools. We can use PHP file manipulation functions to get the data from the Pend Oreille website.
With the help of string manipulation functions and loops, we can extract all the information we need and inserted directly into our database. Array functions and simple arithmetic calculate the mean and median averages. And building the web service uses a number of PHP features. Including grabbing variables from a query string, communicating with a database, and encoding adjacent output. There is a lot of coding involved, so let’s get on with it.
Find answers to the most frequently asked questions about Code Clinic: PHP .
Here are the FAQs that matched your search "" :
A: The Lake Pend Orielle site is not accessible in some geographical areas. We have contacted the owner of the server to try to resolve this issue.
Sorry, there are no matches for your search "" —to search again, type in another word or phrase and click search.
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.