MONTH_NUM = {'Jan': 1, 'Feb': 2, 'Mar': 3, 'Apr': 4, 'May': 5, 'Jun': 6,
             'Jul': 7, 'Aug': 8, 'Sep': 9, 'Oct': 10, 'Nov': 11, 'Dec': 12}

def format_kwh(kwh_array):
    """
    Given an array of electricity usage data, which is a list of list of strings,
    where each inner list has the form
    [year, month, kwh]

    Output a dictionary mapping (year (int), month (int)) to the
    average temperature values (as floats) for that month.

    For example:
    format_kwh([['2007', 'Aug', '1471.95'],
                ['2007', 'Jan', '554.01'],
                ['2007', 'Oct', '655.50']])
     -> {(2007, 8): 1471.95, (2007, 1): 554.01, (2007, 10): 655.50}

    Hint: use MONTH_NUM
    """
    pass # your code here


def format_temps(temp_array):
    """
    Given an array of temperature data, which is a list of list of strings,
    where each inner list has the form
    [year, month, day, high_temp, lo_temp, avg_temp]

    Output a dictionary mapping (year (int), month (int)) to a list of all the
    average temperature values (as floats) for that month.

    For example:
    format_temps([
    ['2007', '1', '1', '48.0', '33.1', '40.5'],
    ['2007', '1', '7', '51.1', '43.0', '47.0'],
    ['2007', '3', '14', '68.0', '45.0', '56.5'],
    ['2008', '7', '21', '84.0', '68.0', '76.0'],
    ]) -> {(2007, 1): [40.5, 47.0], (2007, 3): [56.5], (2008, 7): [76.0]}
    """
    # your code here




def join_arrays(temp_array, kwh_array):
    """
    Given the raw temperature and kwh data described above,
    make and return a dictionary that maps
    (year (int), month (int)) -> (kwh (float or None), temp_avg (float or None))

    If the data is missing, indicate so using None.
    """
    pass # your code here



if __name__ == "__main__":
    tiny_kwh = [['2007', 'Aug', '1471.95'],
                ['2007', 'Jan', '554.01'],
                ['2007', 'Oct', '655.50'],
                ['2007', 'Apr', '526.59'],
                ['2007', 'May', '760.00'],
                ['2007', 'Jul', '1348.45'],
                ['2007', 'Mar', '658.42'],
                ['2007', 'Sep', '1518.79'],
                ['2007', 'Jun', '1110.79'],
                ['2007', 'Nov', '574.19'],
                ['2007', 'Dec', '648.72'],
                ['2007', 'Feb', '606.33'], ]
    exp_kwh = {(2007, 8): 1471.95,
               (2007, 1): 554.01,
               (2007, 10): 655.5,
               (2007, 4): 526.59,
               (2007, 5): 760.0,
               (2007, 7): 1348.45,
               (2007, 3): 658.42,
               (2007, 9): 1518.79,
               (2007, 6): 1110.79,
               (2007, 11): 574.19,
               (2007, 12): 648.72,
               (2007, 2): 606.33}
    result_kwh = format_kwh(tiny_kwh)
    print(f'Did format_kwh get expected result? {exp_kwh == result_kwh = }')
    if type(result_kwh) == dict:
        for key in exp_kwh:
            if key not in result_kwh or result_kwh[key] != exp_kwh[key]:
                print(f"Expected {key=} to have value {exp_kwh[key]} but got {result_kwh.get(key, 'KEY MISSING')}")
    else:
        print(f"Expected result to be a dictionary, but got {result_kwh=}")


    tiny_temps = [
    ['2007', '1', '1', '48.0', '33.1', '40.5'],
    ['2007', '1', '7', '51.1', '43.0', '47.0'],
    ['2007', '3', '14', '68.0', '45.0', '56.5'],
    ['2008', '7', '21', '84.0', '68.0', '76.0'],
    ]
    result_temp = format_temps(tiny_temps)
    exp_temp =  {(2007, 1): [40.5, 47.0],
                 (2007, 3): [56.5],
                 (2008, 7): [76.0]}
    print(f'----------\nGot {result_temp = }')
    print(f'       Expected = {exp_temp}\n--------')


    join_result = join_arrays(tiny_temps, tiny_kwh)
    exp_join = {(2007, 1): [554.01, 43.75],
                (2007, 2): [606.33, None],
                (2007, 3): [658.42, 56.5],
                (2007, 4): [526.59, None],
                (2007, 5): [760.0, None],
                (2007, 6): [1110.79, None],
                (2007, 7): [1348.45, None],
                (2007, 8): [1471.95, None],
                (2007, 9): [1518.79, None],
                (2007, 10): [655.5, None],
                (2007, 11): [574.19, None],
                (2007, 12): [648.72, None],
                (2008, 7): [None, 76.0]}


    print(f'Did join_arrays get expected result? {join_result == exp_join =}')
    if type(join_result) == dict:
        for key in exp_join:
            if key not in join_result or join_result[key] != exp_join[key]:
                print(f"Expected {key=} to have value {exp_join[key]} but got {join_result.get(key, 'KEY MISSING')}")
    else:
        print(f"Expected result to be a dictionary, but got {join_result=}")

