# Practice Problems for Module 10

# Part 1 - Warm up questions

# Complete the function uppercase that consumes two strings, file_in and file_out, 
# and reads in the contents of the file called file_in, and write the same contents
# into the file called file_out, except that all alphabetical letters in file_in
# appear in uppercase in file_out. 
#
# For example, if "in.txt" contains
#Hello
#students of
#  CS116!
# Then calling uppercase("in.txt", "out.txt") will write the following into
# the file called "out.txt":
#HELLO
#STUDENTS OF
#  CS116!

def uppercase(file_in, file_out):
    pass

# Part 2 - Extra Practice

# Problem 1:
# Write a function that consumes the name of a filename and returns the 
# the number of words in the file.

# Problem 2
# Write a function that consumes a name of an input file and an output file
# and reads in all the text from the input file, and writes it to the output
# file, but with the contents of each individual line reversed.

# Problem 3 --
# The UW Weather station has a huge archive of interesting, um, weather
# data. See http://weather.uwaterloo.ca/data.html. You can download csv (comma 
# separated data) from there. These can be saved as plain text files or in 
# spreadsheet format. For these examples, download csv data for one of
# the available years. 
#
# We need a daily weather class
class daily_data:
    'fields: date, low, high, precip'
    
    def __init__(self, d,L,H,p):
        self.date = d
        self.low = L
        self.high = H
        self.precip = p
    def __repr__(self):
        return "{0} {1}/{2} {3}p".format(self.date, self.high, self.low, self.precip)
    def __eq__(self, other):
        return type(self)==type(other) and self.date==other.date and \
               abs(self.high-other.high)<=0.00001 and\
               abs(self.low-other.low)<=0.00001 and\
               abs(self.precip-other.precip)<=0.00001
        
# date is a string of the form 'd-mon-year'
# low is the lowest temp of the day (in C)
# high is the highest temp of the day (in C)
# precip is the amount (in mm) of precipation (snow or rain)


# Construct some sample data for testing
str_day1 = '1-Jan-10,-4.0,2.0,4.0\n'
day1 = daily_data('1-Jan-10', -4.0, 2.0, 4.0)
str_day2 = '29-Feb-09,5.0,9.0,0.0\n'
day2 = daily_data('29-Feb-09', 5.0, 9.0, 0)

# Write functions to do the following:
# a)
# string_to_daily(s): 
# convert a string to a daily_date object
# b)
# format_daily_data(a_day):
#   return a formatted string for a daily_date object
# c)
# create_weather_dictionary(data): 
# return a dictionary with dates as the keys and daily_data objects 
#      as the values
# d)
# Weather_Analysis(data_file): 
#
# Now, use the returned dictionary to answer the following questions: 
# e)
# what is total precipitation for the year?
# f)
# what was hottest day? month?
# g)
# what was coldest day? month?
# h)
# how much precipation in a given month?
# i)
# what day had the greatest difference between low and high temps?
#
#

# If instead of using a dictionary, we had created a list directly from the 
# data (which is in increasing order of date), it would be easier to answer the
# following questions (as compared to the dictionary storage) -
# - what was the maximum number of days in a row with no precipitation?
# - what was the largest difference in low (or high) temperatures for two consecutive days?
#
# Problem 4:
# ElectionsCanada (http://www.elections.ca/content.aspx?section=ele&document=index&lang=e) 
# has lots of data available 
# regarding previous elections. Look at the results of the most recent 
# general election and look at the "raw data version (for researchers)":
# Some of the data is in csv format (comma separated value). Look at the 
# data and write a program to input the data. You'll need to declare
# some classes. Think of some information you'd like to retrieve.
#
#
