Difference between revisions of "CSC111 Homework 11 2015"

From dftwiki3
Jump to: navigation, search
Line 16: Line 16:
 
* Your assignment is to write a program that reads weather data from a text file, then processes the data, and finally outputs the answers to several questions.
 
* Your assignment is to write a program that reads weather data from a text file, then processes the data, and finally outputs the answers to several questions.
  
* Call your program '''hw11.py'''
+
* Call your program '''hw11_1.py'''
  
==The Text File==
+
==The Text Files and Their Format==
The Web site http://www.metoffice.gov.uk/climate/uk/stationdata/ keeps records of temperatures for '''37''' towns/cities of the UK for the past few years, going back in some cases to 1853.
+
<br />
 
+
* The British government has been keeping track of temperatures in several cities of the U.K.  The official Web site where the data is available is http://www.metoffice.gov.uk/climate/uk/stationdata/.  The records of temperatures for '''37''' towns/cities of the UK for the past few years, going back in some cases to 1853, are kept on this site.
Your assignment deals with data taken from this site.  The different lists of temperatures have been stored on a local server at Smith College, and several are given to you to test your program on.
+
<br />
 
+
* The data recorded consists of these quantities
==Background Information==
+
:* Mean daily maximum temperature (tmax)
 
+
:* Mean daily minimum temperature (tmin)
* The main address for the data is that of the Met-Office site:  http://www.metoffice.gov.uk/climate/uk/stationdata/ 
+
:* Days of air frost (af)
 
+
:* Total rainfall (rain)
* The data has been replicated at http://cs.smith.edu/~dthiebaut/UKTemperatures/, and you can use this Smith-based Url instead. The data files are the same at both places.
+
:* Total sunshine duration (sun)
 
+
:(More information can be found [[media:www_metoffice_gov_uk.pdf| here]].)
* A file name is associated with each city or town.  For example, the city of '''Aberporth''' is associated with '''aberporthdata.txt''', and the record of the weather data for '''Aberporth''' is stored at URL http://cs.smith.edu/~dthiebaut/UKTemperatures/aberporthdata.txt
+
<br />
 
+
* The format for the data is CSV.
* The name of the file is simply the name of the town, all lowercase, followed by "data.txt."
+
* The data from the UK Web site have been mirrored on a Smith server: [http://cs.smith.edu/~dthiebaut/UKTemperatures/  http://cs.smith.edu/~dthiebaut/UKTemperatures/].  You will need to download a few files from that site to develop and test your program.
 +
* The name of a file is simply the name of the U.K. town, all lowercase, suffixed by "data.txt."
  
 
<br />
 
<br />
 
===Format of the data===
 
===Format of the data===
 
<br />
 
<br />
* The format of the data is explained at http://www.metoffice.gov.uk/climate/uk/stationdata/, a copy of which is available [[media:www_metoffice_gov_uk.pdf| here]].
+
* Download one of the files from  [http://cs.smith.edu/~dthiebaut/UKTemperatures/ http://cs.smith.edu/~dthiebaut/UKTemperatures/], say '''armaghdata.txt''', and take a look at it. Use '''Notepad''', '''TextEdit''' or your favorite text editor.
 
+
* You will notice that when measurements are missing, they are replaced by "---".  Your program should not skip measurements that are missing.
* Your program should accept ''estimated'' data as well as ''real data''. In other words, data followed by an asterisk should not be dropped or skipped by your program.
+
* Sometimes, especially at the end of the file, measurements are suffixed with an asterisk (*).    Your program should discard the asterisk, and treat the data as valid.
 +
* Some lines have the word "Provisional" at the end.  Your program should treat these lines the same as regular line, and should '''not''' skip them.
 
<br />
 
<br />
 
===Input===
 
===Input===
 
<br />
 
<br />
Your program should prompt the user for a file name.  The user will supply the name of one of the text files that will have been previously downloaded from the Smith Web site listed above.  In other words, your program simply needs to read a text file and does not need to access the Web.
+
* Your program should prompt the user for a file name.  The user will supply the name of one of the text files that will have been previously downloaded from the Smith Web site listed above.  In other words, your program simply needs to read a text file and does not need to access the Web.
 +
* If the user provides an invalid file name, your program will keep on prompting the user for a new name.  Your program will only exit once it has been given a valid file name, and processed its data and output the answers.
 +
 
 
<br />
 
<br />
 
===Processing===
 
===Processing===
Line 52: Line 56:
 
<br />
 
<br />
 
;Question 1
 
;Question 1
:  In what year or years was the coldest temperature recorded?  If the coldest temperature appears several times, list all the years and month in which it will have been reported.  
+
:  In what year or years was the coldest temperature recorded?  If the coldest temperature appears several times, list all the years and month in which it will have been reported.  The format of the output is illustrated in a later section.
 
<br />
 
<br />
 
;Question 2
 
;Question 2
  
:  In what year or years was the warmest temperature recorded?  If the warmest temperature appears several times, list all the years and month in which it will have been reported.  
+
:  In what year or years was the warmest temperature recorded?  If the warmest temperature appears several times, list all the years and month in which it will have been reported.  The format of the output is illustrated in a later section.
  
 
;Question 3
 
;Question 3
: What are the 5 sunniest months and years for the given city?
+
: What are the 5 sunniest months and years for the given city?   The format of the output is illustrated below.
 
<br />
 
<br />
 
==Output Format==
 
==Output Format==
Line 69: Line 73:
 
  Invalid file name, please re-enter
 
  Invalid file name, please re-enter
 
  > armaghdata.txt
 
  > armaghdata.txt
  1, -4.2, 1878 12, 1895, 2  
+
  1, -4.2, 1878, 12, 1895, 2
  2, 23.8, 1995, 8, 1989, 7  
+
  2, 23.8, 1995, 8, 1989, 7
  3, 256.0, 1940, 6, 252.9, 1949 6, 251.6, 1935, 5, 244.1, 1957, 6, 243.8, 1989, 7  
+
  3, 256.0, 1940, 6, 252.9, 1949, 6, 251.6, 1935, 5, 244.1, 1957, 6, 243.8, 1989, 7
 
   
 
   
 
<br />
 
<br />
Line 77: Line 81:
 
   
 
   
 
  > ballypatrickdata.txt
 
  > ballypatrickdata.txt
  1, -1.8, 1979, 1  
+
  1, -1.8, 1979, 1
  2, 20.0, 1995, 8  
+
  2, 20.0, 1995, 8
  3, 279.3, 1975, 5, 272.6, 1976, 8, 253.7, 1977, 5, 247.2, 1984, 5, 245.6, 1974, 4  
+
  3, 279.3, 1975, 5, 272.6, 1976, 8, 253.7, 1977, 5, 247.2, 1984, 5, 245.6, 1974, 4
 
   
 
   
 
:Note that each line is prefixed with a number, identifying the question for which the line is the answer.
 
:Note that each line is prefixed with a number, identifying the question for which the line is the answer.
 +
:Note, also, that the output is in CSV form.  A coma separates all the values.  No extra spaces should appear in front of comas.
 
   
 
   
 
==Moodle Submission==
 
==Moodle Submission==

Revision as of 17:02, 12 April 2015

--D. Thiebaut (talk) 17:20, 12 April 2015 (EDT)


<showafterdate after="20150415 12:00" before="20150601 00:00">


This Homework is due on 4/21/15 at 11:55 p.m.


Problem #1: Temperatures in the UK

HistoricStationDataUKWeather.png


Assignment

  • Your assignment is to write a program that reads weather data from a text file, then processes the data, and finally outputs the answers to several questions.
  • Call your program hw11_1.py

The Text Files and Their Format


  • The British government has been keeping track of temperatures in several cities of the U.K. The official Web site where the data is available is http://www.metoffice.gov.uk/climate/uk/stationdata/. The records of temperatures for 37 towns/cities of the UK for the past few years, going back in some cases to 1853, are kept on this site.


  • The data recorded consists of these quantities
  • Mean daily maximum temperature (tmax)
  • Mean daily minimum temperature (tmin)
  • Days of air frost (af)
  • Total rainfall (rain)
  • Total sunshine duration (sun)
(More information can be found here.)


  • The format for the data is CSV.
  • The data from the UK Web site have been mirrored on a Smith server: http://cs.smith.edu/~dthiebaut/UKTemperatures/. You will need to download a few files from that site to develop and test your program.
  • The name of a file is simply the name of the U.K. town, all lowercase, suffixed by "data.txt."


Format of the data


  • Download one of the files from http://cs.smith.edu/~dthiebaut/UKTemperatures/, say armaghdata.txt, and take a look at it. Use Notepad, TextEdit or your favorite text editor.
  • You will notice that when measurements are missing, they are replaced by "---". Your program should not skip measurements that are missing.
  • Sometimes, especially at the end of the file, measurements are suffixed with an asterisk (*). Your program should discard the asterisk, and treat the data as valid.
  • Some lines have the word "Provisional" at the end. Your program should treat these lines the same as regular line, and should not skip them.


Input


  • Your program should prompt the user for a file name. The user will supply the name of one of the text files that will have been previously downloaded from the Smith Web site listed above. In other words, your program simply needs to read a text file and does not need to access the Web.
  • If the user provides an invalid file name, your program will keep on prompting the user for a new name. Your program will only exit once it has been given a valid file name, and processed its data and output the answers.


Processing


  • You must use the method illustrated in the first 2 problems of Lab 11 to process the data.
  • All temperatures should be reported in degrees Celsius which is the system used in the U.K.


Questions


Question 1
In what year or years was the coldest temperature recorded? If the coldest temperature appears several times, list all the years and month in which it will have been reported. The format of the output is illustrated in a later section.


Question 2
In what year or years was the warmest temperature recorded? If the warmest temperature appears several times, list all the years and month in which it will have been reported. The format of the output is illustrated in a later section.
Question 3
What are the 5 sunniest months and years for the given city? The format of the output is illustrated below.


Output Format


  • Here is the expected output for armaghdata.txt:


> armagh.txt
Invalid file name, please re-enter
> armaghdata.txt
1, -4.2, 1878, 12, 1895, 2
2, 23.8, 1995, 8, 1989, 7
3, 256.0, 1940, 6, 252.9, 1949, 6, 251.6, 1935, 5, 244.1, 1957, 6, 243.8, 1989, 7


and here is the expected output for ballpatrickdata.txt:
> ballypatrickdata.txt
1, -1.8, 1979, 1
2, 20.0, 1995, 8
3, 279.3, 1975, 5, 272.6, 1976, 8, 253.7, 1977, 5, 247.2, 1984, 5, 245.6, 1974, 4

Note that each line is prefixed with a number, identifying the question for which the line is the answer.
Note, also, that the output is in CSV form. A coma separates all the values. No extra spaces should appear in front of comas.

Moodle Submission

  • Submit your program in the Moodle HW11 PB1 section.


</showafterdate>