city = 'BALTIMORE'

biweek = 3

"""
Explanation: Solution of  Dalziel et al. 2015
Write a function that takes as arguments the name of a city and the index of a biweek (from 1 to 26). The function should return the number of cases of measles for that city and biweekly period, for all the available years.
First, we are going to build the pieces that go into the function. Once we're done, we're going to write the function itself. For testing, we choose BALTIMORE as the city and 3 as the biweek.
End of explanation
"""


import csv
with open('../data/Dalziel2015_data.csv') as csvfile:
    reader = csv.DictReader(csvfile)
    print(next(reader))

"""
Explanation: Open the file using the csv package:
End of explanation
"""


with open('../data/Dalziel2015_data.csv') as csvfile:
    reader = csv.DictReader(csvfile)
    for row in reader:
        if row['loc'] == city and int(row['biweek']) == biweek:
            print(row['year'], row['cases'])

"""
Explanation: As you can see, this reads each row in the file an converts it into a dictionary, using the header to name the keys. This makes it very simple to filter the desired records:
End of explanation
"""


import csv

def get_cases_city_biweek(city = "BALTIMORE", biweek = 5):
    with open('../data/Dalziel2015_data.csv') as csvfile:
        reader = csv.DictReader(csvfile)
        for row in reader:
            if row['loc'] == city and int(row['biweek']) == biweek:
                print(row['year'], row['cases'])

"""
Explanation: Now that we have the code ready, we can write a function:
End of explanation
"""


get_cases_city_biweek('BOSTON', 7)

"""
Explanation: We can call the function using another city/biweek, for example BOSTON and 7:
End of explanation
"""


def get_all_cities():
    all_cities = set([])
    with open('../data/Dalziel2015_data.csv') as csvfile:
        reader = csv.DictReader(csvfile)
        for row in reader:
            all_cities.add(row['loc'])
    return(all_cities)

"""
Explanation: Write a function that returns all the cities in the dataset.
There are different ways to do this. Here, the strategy is to construct a set, so that cities are not repeated:
End of explanation
"""


get_all_cities()

"""
Explanation: Now invoke the function:
End of explanation
"""


