""" CSC120 Lab 7 """

from typing import List, Dict, TextIO

# Months constant
MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 'July',
          'August', 'September', 'October', 'November', 'December']

# Precondition for all functions in this module: each line of the temperature
# file contains the average monthly temperatures for a year (separated
# by spaces) starting with January.  The file must also have 3 header lines.

# Write the body of open_temperature_file first.
# You will use this function to open the temperature file and feed it into
# all of the other functions that require it.
def open_temperature_file(filename: str) -> TextIO:
    """Open the file named filename, read past the three-line header, and 
    return the open file.
    
    In the example below, notice that the next line to read gives us the fourth
    line - this function should have fully read the first three lines.
    
    >>> f = open_temperature_file('temps_small.txt')
    >>> f.readline()
    '-1.0    -0.5    1.0    10.0    10.0    20.0 
    >>> f.close()
    """
    
    # Add your code here
    

# Use 'temps_small.txt' for testing, and then ensure it works on the larger
# data set 'temps.txt'.
def average_temp_march(temp_file: TextIO) -> float:
    """Return the average temperature for the month of March
    over all years in open file temp_file.
    
    You can use the sum(L) function to get the sum of all numeric
    elements in a list.
    
    Remember that the str.split() will split a string into a list
    by spaces.
    
    >>> f = open_temperature_file('temps_small.txt')
    >>> average_temp_march(f)
    1.5
    >>> f.close()
    """
    
    # Add your code here  


def average_temp_month(temp_file: TextIO, mo: int) -> float:
    """Return the average temperature for month mo over all
    years in f. mo is an integer between 0 and 11, representing
    January to December, respectively.
    
    You can use the sum(L) function to get the sum of all numeric
    elements in a list.
    
    >>> f = open_temperature_file('temps_small.txt')
    >>> average_temp_month(f, 4)
    12.5
    >>> f.close()
    """
    # Add your code here  
    
    
def higher_avg_temp(filename: str, month1: int, month2: int) -> int:
    """Return either month1 or month2 (integers representing months in the
    range 0 to 11), whichever has the higher average temperature over
    all years in the file at filename.  If the months have the 
    same average temperature, then return -1.
    
    Note that the given parameter is a filename string, not an open file.
    You will have to open and close it twice.
    
    Hint: Use your average_temp function.  Don't forget to close files that
    you open.
    
    >>> higher_avg_temp('temps_small.txt', 3, 5)
    5
    """
    # Add your code here
    
    
def below_freezing(temp_file: TextIO) -> List[float]:
    """Return, in ascending order, all temperatures below freezing 
    (0 degrees Celcius), for all temperature data in temp_file. 
    Include any duplicates that occur.
    
    >>> f = open_temperature_file('temps_small.txt')
    >>> below_freezing(f)
    [-3.0, -2.0, -1.0, -0.5]
    >>> f.close()
    """
    # Add your code here  
    
    
## Dictionary functions below.
# You may use functions you've written above if they might help.
# Start each function by creating an empty dictionary.

def month_to_average(filename: str) -> Dict[str, float]:
    """Return a dictionary where the keys are the months and the values are 
    the average temperatures for each month over all years in temp_file.
    
    Use the MONTHS constant at the top of this file for the month names.
    
    Hint: use functions you've written above.  Don't forget to close any files
    you open.
    
    >>> month_to_average('temps_small.txt')
    {'January': -1.5, 'February': -1.75, 'March': 1.5, 'April': 10.0, \
    'May': 12.5, 'June': 20.0, 'July': 20.0, 'August': 20.0, 'September': 20.0,\
    'October': 10.0, 'November': 0.0, 'December': 1.0}
    """
    
    # Add your code here
    
    
def range_lists(temp_file: TextIO) -> Dict[str, List[float]]:
    """Return a dictionary where the keys and values are the following:
    
    Key: 'temp < 0', Values: All temperatures in temp_file that are less than 0.
    Key: '0 <= temp < 10', Values: All temperatures at least 0 and less than 10.
    Key: 'temp >= 10', Values: All temperatures more than or equal to 10.
    
    If no temperature matches a certain criteria, the value for that key should
    be an empty list.
    
    >>> f = open_temperature_file('temps_small.txt')
    >>> range_lists(f)
    {'temp < 0': [-1.0, -0.5, -2.0, -3.0], \
    '0 <= temp < 10': [1.0, 0.0, 1.0, 2.0, 0.0, 1.0], \
    'temp >= 10': [10.0, 10.0, 20.0, 20.0, 20.0, 20.0, 10.0, 10.0, \
    15.0, 20.0, 20.0, 20.0, 20.0, 10.0]}
    >>> f.close()
    """
    # Add your code here
    
    
def year_to_average(temp_file: TextIO) -> Dict[int, float]:
    """Return a dictionary where the keys are the years (starting from 2006),
    and the values are the average temperateures for each year in temp_file.
    
    Hint: First make a list of the averages for each year from the lines of the 
    files, then assign them to the dictionary keys. (you can use two separate 
    for loops to do these two tasks).
    
    >>> f = open_temperature_file('temps_small.txt')
    >>> year_to_average(f)
    {2006: 9.208333333333334, 2007: 9.416666666666666}
    """
    # Add your code here
    
    