Пример #1
0
def result():
    """
    Return list with dicts.
    """
    res_0 = file_with_pollution("Pollution_Kharkiv.csv")
    res_1 = file_with_pollution("Pollution_Dnipro.csv")
    res_1 = res_1[13:]
    res_2 = file_with_pollution("Pollution_Zakarpattya.csv")
    res_2 = res_2[13:]
    res_3 = file_with_pollution("Pollution_Lviv.csv")
    res_3 = res_3[13:]
    res_4 = file_with_pollution("Pollution_Khmelnytski.csv")
    res_4 = res_4[1:]
    res_5 = file_with_pollution("Pollution_Cherkasy.csv")
    res_5 = res_5[13:]
    res_6 = file_with_pollution("Pollution_Mykolaiv.csv")
    res_6 = res_6[6:]
    lst_with_res = [res_0, res_1, res_2, res_3, res_4, res_5, res_6]
    lst_with_names = [
        "Kharkiv", "Dnipro", "Zakarpattya", "Lviv", "Khmelnytski", "Cherkasy",
        "Mykolaiv"
    ]
    lst_with_obl = []
    for i in range(7):
        el = lst_with_res[i]
        dict_with_numbers = {}
        for j in el:
            dict_with_numbers[int(j[0])] = convert(j[1])
        dict_with_names = {}
        dict_with_names[lst_with_names[i]] = dict_with_numbers
        lst_with_obl.append(dict_with_names)
    return lst_with_obl
Пример #2
0
def file_with_pollution(path):
    """
    Open file with pollution and create a dict with number of pollution each year
    """
    f = open(path, encoding='utf-8', errors='ignore')
    data = f.readlines()
    lst_with_data = []
    for i in data:
        i = i.replace('"',
                      ' ').replace("\t",
                                   ' ').replace("\n",
                                                " ").replace("'",
                                                             ' ').split(' ')
        lst_with_data.append(i)
    lst_with_data = lst_with_data[241:][::2]
    a = [['2017', ''], ['189,4', ''], ['107,4', ''], ['73,0', ''], ['6,8', ''],
         ['6,8', ''], ['...', '']]
    lst_with_data = lst_with_data + a
    res_lst = []
    for i in range(13):
        res_lst.append(lst_with_data[i * 7:i * 7 + 2])
    dict_with_years = {}
    for i in res_lst:
        dict_with_years[int(i[0][0])] = convert(i[1][0])
    return dict_with_years
Пример #3
0
def file_with_pollution(path):
    """
    Open file with pollution and create a dict with number of pollution each year
    """
    f = open(path, encoding='utf-8', errors='ignore')
    data = f.readlines()
    lst_with_data = []
    for i in data:
        i = i.replace('"', ' ').replace("\t", ' ').replace("\n", " ").replace("'", ' ').split(' ')
        lst_with_data.append(i)
    lst_with_data = lst_with_data[120:][:-7]
    res_lst = []
    for i in range(13):
        res_lst.append(lst_with_data[i * 7: i * 7 + 2])
    dict_with_years = {}
    for i in res_lst:
            dict_with_years[int(i[0][0])] = convert(i[1][0])
    res_dict = {}
    res_dict["Volyn"] = dict_with_years
    return res_dict
Пример #4
0
def file_with_pollution(path):
    """
    Open file with pollution and create a dict with number of pollution each year.
    """
    f = open(path, encoding='utf-8', errors='ignore')
    data = f.readlines()
    lst_with_data = []
    for i in data:
        i = i.replace('"',
                      ' ').replace("\t",
                                   ' ').replace("\n",
                                                " ").replace("'",
                                                             ' ').split(' ')
        lst_with_data.append(i)
    lst_with_data = lst_with_data[23:][:-1]
    res_lst = []
    for i in lst_with_data:
        res_lst.append(i[:2])
    dict_with_years = {}
    for i in res_lst:
        dict_with_years[int(i[0])] = convert(i[1])
    res_dict = {}
    res_dict["Zaporizhzha"] = dict_with_years
    return res_dict
Пример #5
0
        lst_with_years.append(j)
    dict_2005 = dict_by_year[lst_with_years[0]]
    lst_with_num = []
    for l in dict_2005.keys():
        lst_with_num.append(l)

for i in range(len(lst_with_res)):
    my_dict = lst_with_res[i][lst_with_keys[i]]
    all_percent_of_dead = []
    all_cancer = []
    all_heart = []
    for j in lst_with_years:
        dead = my_dict[j][lst_with_num[0]]
        cancer = my_dict[j][lst_with_num[1]]
        heart = my_dict[j][lst_with_num[2]]
        total = convert(my_dict[j][lst_with_num[3]]) * 1000
        percent_dead = (dead * 100) / total
        percent_cancer = (cancer * 100) / total
        percent_heart = (heart * 100) / total
        lst_with_res[i][lst_with_keys[i]][j][lst_with_num[0]] = round(
            percent_dead, 2)
        lst_with_res[i][lst_with_keys[i]][j][lst_with_num[1]] = round(
            percent_cancer, 2)
        lst_with_res[i][lst_with_keys[i]][j][lst_with_num[2]] = round(
            percent_heart, 2)
        lst_with_res[i][lst_with_keys[i]][j][lst_with_num[3]] = total
        all_percent_of_dead.append(round(percent_dead, 2))
        all_cancer.append(round(percent_cancer, 2))
        all_heart.append(round(percent_heart, 2))
    mid_dead = round(sum(all_percent_of_dead) / len(all_percent_of_dead), 2)
    mid_cancer = round(sum(all_cancer) / len(all_cancer), 2)