From 1f85b912361295f5ebb406d1fac2fc2e5e798836 Mon Sep 17 00:00:00 2001 From: fordprefect Date: Tue, 15 Dec 2020 12:11:59 +0100 Subject: [PATCH] fix data url and adapt to new data format, including type conversion, location name changes etc --- all_countries.py | 1 + coronavis.py | 47 ++++++++++++++++++++++++++++++++++++++-- doubling_time.py | 5 ++++- index.html | 9 ++++---- population_repository.py | 5 +++-- 5 files changed, 58 insertions(+), 9 deletions(-) diff --git a/all_countries.py b/all_countries.py index fac96c2..e6fc086 100644 --- a/all_countries.py +++ b/all_countries.py @@ -17,6 +17,7 @@ corr = {"Chile": 10000, "Peru": 10000, "Bolivia": 3000, "Yemen": 220, + "Turkey": 100000, } def plot(data, countries, pop): diff --git a/coronavis.py b/coronavis.py index 5d8a362..9321048 100644 --- a/coronavis.py +++ b/coronavis.py @@ -32,7 +32,7 @@ def get_data(): tries = 10 delay = 10 - dataurl = "https://covid.ourworldindata.org/data/ecdc/full_data.csv" + dataurl = "https://covid.ourworldindata.org/data/owid-covid-data.csv" date = datetime.date.today() datafile = f"{date}-full-data.csv" @@ -62,13 +62,56 @@ def get_data(): date,location,new_cases,new_deaths,total_cases,total_deaths = row elif len(row) == 10: date,location,new_cases,new_deaths,total_cases,total_deaths,weekly_cases,weekly_deaths,biweekly_cases,biweekly_deaths = row + elif len(row) == 50: + iso_code,continent,location,date,total_cases,new_cases,new_cases_smoothed,total_deaths,new_deaths,new_deaths_smoothed,total_cases_per_million,new_cases_per_million,new_cases_smoothed_per_million,total_deaths_per_million,new_deaths_per_million,new_deaths_smoothed_per_million,reproduction_rate,icu_patients,icu_patients_per_million,hosp_patients,hosp_patients_per_million,weekly_icu_admissions,weekly_icu_admissions_per_million,weekly_hosp_admissions,weekly_hosp_admissions_per_million,new_tests,total_tests,total_tests_per_thousand,new_tests_per_thousand,new_tests_smoothed,new_tests_smoothed_per_thousand,positive_rate,tests_per_case,tests_units,stringency_index,population,population_density,median_age,aged_65_older,aged_70_older,gdp_per_capita,extreme_poverty,cardiovasc_death_rate,diabetes_prevalence,female_smokers,male_smokers,handwashing_facilities,hospital_beds_per_thousand,life_expectancy,human_development_index = row else: print(f"WARNING! Table format changed, new header:\n{row})") exit(1) - + # break loop if header if location=="location": # table header continue + # cast to num type + if isinstance(total_cases, str): + if total_cases in ('', ' ', '0.0'): + total_cases = 0 + try: + total_cases = int(total_cases) + except: + try: + total_cases = float(total_cases) + except: + print("tc failed") + if isinstance(new_cases, str): + if new_cases in ('', ' ', '0.0'): + new_cases = 0 + try: + new_cases = int(new_cases) + except: + try: + new_cases = float(new_cases) + except: + print("nc failed") + if isinstance(new_deaths, str): + if new_deaths in ('', ' ', '0.0'): + new_deaths = 0 + try: + new_deaths = int(new_deaths) + except: + try: + new_deaths = float(new_deaths) + except: + print("nd failed") + if isinstance(total_deaths, str): + if total_deaths in ('', ' ', '0.0'): + total_deaths = 0 + try: + total_deaths = int(total_deaths) + except: + try: + total_deaths = float(total_deaths) + except: + print("td failed") if location not in data: data[location] = [] year, month, day = date.split("-") diff --git a/doubling_time.py b/doubling_time.py index 5892fdb..b95ad3b 100644 --- a/doubling_time.py +++ b/doubling_time.py @@ -19,7 +19,10 @@ def plot(data, countries, pop): window_size = 7 tchar = moving_average(np.array(new_cases),window_size)/moving_average(np.array(total_cases),window_size) thalf = np.log(2)/tchar - day_of_100_cases = np.argwhere(np.array(total_cases) > 99)[0][0] + try: + day_of_100_cases = np.argwhere(np.array(total_cases) > 99)[0][0] + except: + return new_time_axis = time[int(window_size/2):-int(window_size/2)] pp.plot(new_time_axis[50:], thalf[50:], label=f"{loc}", marker=".") diff --git a/index.html b/index.html index 7f69498..93562f6 100644 --- a/index.html +++ b/index.html @@ -25,6 +25,7 @@ Das wird aber ganz massiv durch die Testrate, Meldekette, politische Einflussnah die einzelnen Länder sehr unterschiedlich sein!

Die Daten stammen von hier und werden dort aus den WHO- und ECDC-Reports generiert. +Von den extrem reichhaltigen Daten dort verarbeite ich nur die Zahl der Neufälle.

Aktuelle Daten aus Deutschland mit vielen Hintergründen finden sich im Lagebericht des RKI. @@ -61,7 +62,7 @@ Aktuelle Daten aus Deutschland mit vielen Hintergründen finden sich im Germany
Austria
Belgium
-
Czech Republic
+
Czech Republic
Denmark
France
Italy
@@ -154,7 +155,7 @@ Aktuelle Daten aus Deutschland mit vielen Hintergründen finden sich im
Cuba
Curacao
Cyprus
-
Czech Republic
+
Czech Republic
Democratic Republic of Congo
Denmark
Djibouti
@@ -219,7 +220,7 @@ Aktuelle Daten aus Deutschland mit vielen Hintergründen finden sich im
Liechtenstein
Lithuania
Luxembourg
-
Macedonia
+
North Macedonia
Madagascar
Malawi
Malaysia
@@ -284,7 +285,7 @@ Aktuelle Daten aus Deutschland mit vielen Hintergründen finden sich im
Sri Lanka
Sudan
Suriname
-
Swaziland
+
Swaziland
Sweden
Switzerland
Syria
diff --git a/population_repository.py b/population_repository.py index 3a0d358..9698657 100644 --- a/population_repository.py +++ b/population_repository.py @@ -47,6 +47,7 @@ pop = {'Afghanistan': {'key': 'Afghanistan', 'pop': 38928341, 'year': 2020}, 'Cuba': {'key': 'Cuba', 'pop': 11326616, 'year': 2020}, 'Curacao': {'key': 'Curaçao', 'pop': 164100, 'year': 2020}, 'Cyprus': {'key': 'Cyprus', 'pop': 875899, 'year': 2020}, 'Czech Republic': {'key': 'Czechia', 'pop': 10708982, 'year': 2020}, + 'Czechia': {'key': 'Czechia', 'pop': 10708982, 'year': 2020}, 'Democratic Republic of Congo': {'key': 'Democratic_Republic_of_the_Congo', 'pop': 89561404, 'year': 2020}, 'Denmark': {'key': 'Denmark', 'pop': 5792203, 'year': 2020}, 'Djibouti': {'key': 'Djibouti', 'pop': 988002, 'year': 2020}, @@ -58,7 +59,7 @@ pop = {'Afghanistan': {'key': 'Afghanistan', 'pop': 38928341, 'year': 2020}, 'Equatorial Guinea': {'key': 'Equatorial_Guinea', 'pop': 1402985, 'year': 2020}, 'Eritrea': {'key': 'Eritrea', 'pop': 3546427, 'year': 2020}, 'Estonia': {'key': 'Estonia', 'pop': 1326539, 'year': 2020}, - 'Swaziland': {'key': 'Eswatini', 'pop': 1160164, 'year': 2020}, + 'Eswatini': {'key': 'Eswatini', 'pop': 1160164, 'year': 2020}, 'Ethiopia': {'key': 'Ethiopia', 'pop': 114963583, 'year': 2020}, 'Falkland Islands': {'key': 'Falkland_Islands_(Malvinas)', 'pop': 3483, 'year': 2020}, 'Faeroe Islands': {'key': 'Faroe_Islands', 'pop': 48865, 'year': 2020}, @@ -130,7 +131,7 @@ pop = {'Afghanistan': {'key': 'Afghanistan', 'pop': 38928341, 'year': 2020}, 'Nicaragua': {'key': 'Nicaragua', 'pop': 6624554, 'year': 2020}, 'Niger': {'key': 'Niger', 'pop': 24206636, 'year': 2020}, 'Nigeria': {'key': 'Nigeria', 'pop': 206139587, 'year': 2020}, - 'Macedonia': {'key': 'North_Macedonia', 'pop': 2083380, 'year': 2020}, + 'North Macedonia': {'key': 'North_Macedonia', 'pop': 2083380, 'year': 2020}, 'Northern Mariana Islands': {'key': 'Northern_Mariana_Islands', 'pop': 57557, 'year': 2020}, 'Norway': {'key': 'Norway', 'pop': 5421242, 'year': 2020}, 'Oman': {'key': 'Oman', 'pop': 5106622, 'year': 2020}, 'Pakistan': {'key': 'Pakistan', 'pop': 220892331, 'year': 2020},