Colorado State University Logo | Spring 21: CS 150 - Culture and Coding (AUCC 3B/GT-AH3) Colorado State University Logo | Spring 21: CS 150 - Culture and Coding (AUCC 3B/GT-AH3)
Spring 21: CS 150 - Culture and Coding (AUCC 3B/GT-AH3)
Computer Science

Practical Project > Fort Collins Weather Data

Weather in Fort Collins is great. Except for when it’s not. This dataset contains the temperature and wind speed for every hour between 2008 and 2015, and is provided by the Fort Collins Weather Station and Colorado State University.

Details

The Temperatures.csv dataset is split into the following four columns:

  • Date
    The date when the data was recorded. Formatted day-month-year (ex. “10-Jun-2010”)

  • Time
    The time when the data was recorded. Formatted in 24-hour time (ex. “16:21”)

  • Temperature
    The temperature in fahrenheit (ex. “69.9”)
    Note: Some temperatures are missing and are recorded simply as ***

  • Wind Speed
    The wind speed in mph (ex. “1.7”)

Required Methods To Implement (graded)

We will grade the following methods. Please note, that while there may be different ways to implement them, and you are free to even write helper methods (which we did ourselves) - we need the method names to match the following specification.

CSVReader

This file specifically is used to read the Comma Separated Value files using a Scanner Object. We also used it to help store the indices of the columns in constant variables for easy use in GenderStats.java.

public void initialize(String file)

This method will initialize a class level scanner object based on a File (new File(…)). The name of the file will be passed in. You can assume it is a correct name, but you should also try and catch the IOException that is required by calling new file. The following code can help you get started. You may also want to look at the Digital Humanities lab for an example.

Here is some example code that will help you.

try {
     fileScanner = new Scanner(new File(file));
 }catch (IOException io) {
     io.printStackTrace();
}

public boolean hasNext()

Returns if the scanner has more lines to read if the scanner has been initialized. If the scanner hasn’t been initialized, it will return false. Looking at how scanner checks to see if more lines need to be read will help with this method.

public String[] getNext()

If the scanner has more lines to read, it reads the line and returns a String array of all the values in the line - broken up by the comma (‘,’) delimiter! This is essentially how CSV files are stored.

Stats.java

This file is the main driver file of your program. Two things will happen in this file. The first is getting a time period from the user. They can choose a day, a month, or a year. They can also choose some combination of those three. You then must calculate the maximum, minimum, and average temperatures for that time period. How you do this is up to you, but you will want to use the CVSReader and its associated methods.

Output

Output for all three statistics is formatted in the following way

Average temperature for Aug-2012: 72.57 
Maximum temperature for Aug-2012: 94.40 
Minimum temperature for Aug-2012: 49.40

These are the outputs if the user entered “Aug-2012”, look at the example outputs to get a better of the format. Blank spaces and capitalization will not be graded.

Suggestions / Insights

If your getNext() method is working correctly you should be able to get a String array that looks something like this

[“17-Dec-2010”, “17:00”, “27.4”, “2.6”]

There are two methods which you will find useful when working with a line of data like this

  • String.contains()
    Can be used to check if the date element contains the time period you are analyzing

  • Double.parseDouble()
    Can convert the String representing the temperature into a double allowing you to do the necessary calculations

Remember that not all times have temperatures, missing temperatures are recorded as “***”. You should ignore any times with missing temperatures.

Some additional analytics you might perform using this dataset

  • Average wind speed for each hour
  • Correlation between Temperature shift and wind speed
  • Temperature trends over the years

Example Inputs-Outputs

Temperatures on a specific day

Input: 25-Dec-2008

Output:
Average temperature for 25-Dec-2008: 27.11 
Maximum temperature for 25-Dec-2008: 43.30 
Minimum temperature for 25-Dec-2008: 11.00

Temperatures across an entire month

Input: Jun-2010

Output:
Average temperature for Jun-2010: 67.81 
Maximum temperature for Jun-2010: 95.00 
Minimum temperature for Jun-2010: 43.70

Temperatures over a year

Input: 2015

Output:
Average temperature for 2015: 50.89 
Maximum temperature for 2015: 94.30 
Minimum temperature for 2015: -1.40

Temperatures on the best day of the year

Input: 24-Sep

Output:
Average temperature for 24-Sep: 61.92 
Maximum temperature for 24-Sep: 86.10 
Minimum temperature for 24-Sep: 38.30

Reference

Computer Science Department

279 Computer Science Building
1100 Centre Avenue
Fort Collins, CO 80523
Phone: (970) 491-5792
Fax: (970) 491-2466

Spring 21: CS 150 - Culture and Coding (AUCC 3B/GT-AH3)

Survey of computer science, formal logic, and computational thinking. Explores the historical, gender, and cultural perspectives on the role of technology in society. Includes learning a basic programming language. Students will be expected to write small programs, and construct written arguments on ways in which technology influences our modern culture. Previous computer science experience not necessary.