X-Git-Url: https://git.njae.me.uk/?p=covid19.git;a=blobdiff_plain;f=international_comparison.py;fp=international_comparison.py;h=213560930552e1ba777f427035050c1c57d16b44;hp=0000000000000000000000000000000000000000;hb=5afedd66506be7575034ae6deebcfaa7c2ced978;hpb=4abff18d7988bdea04a267a08a0792ba570fe0bd diff --git a/international_comparison.py b/international_comparison.py new file mode 100644 index 0000000..2135609 --- /dev/null +++ b/international_comparison.py @@ -0,0 +1,102 @@ +#!/usr/bin/env python +# coding: utf-8 +# %% +# Data from [European Centre for Disease Prevention and Control](https://www.ecdc.europa.eu/en/publications-data/download-todays-data-geographic-distribution-covid-19-cases-worldwide) + +# %% +import itertools +import collections +import json +import pandas as pd +import numpy as np +from scipy.stats import gmean +import datetime + +from sqlalchemy.types import Integer, Text, String, DateTime, Date, Float +from sqlalchemy import create_engine + +import matplotlib as mpl +import matplotlib.pyplot as plt +plt.ioff() + + +# %% +connection_string = 'postgresql://covid:3NbjJTkT63@localhost/covid' + + +# %% +engine = create_engine(connection_string) + + +# %% +DEATH_COUNT_THRESHOLD = 10 +COUNTRIES_CORE = tuple(sorted('IT DE UK ES IE FR BE'.split())) +COUNTRIES_NORDIC = tuple('SE NO DK FI UK'.split()) +COUNTRIES_FRIENDS = tuple('IT UK ES BE SI MX'.split()) +# COUNTRIES_FRIENDS = 'IT UK ES BE SI PT'.split() + +COUNTRIES_AMERICAS = ('AG', 'AR', 'AW', 'BS', 'BB', 'BZ', 'BM', 'BO', 'BR', 'VG', 'KY', # excluding Canada and USA + 'CL', 'CO', 'CR', 'CU', 'CW', 'DM', 'DO', 'EC', 'SV', 'GL', 'GD', 'GT', + 'GY', 'HT', 'HN', 'JM', 'MX', 'MS', 'NI', 'PA', 'PY', 'PE', 'PR', 'KN', + 'LC', 'VC', 'SX', 'SR', 'TT', 'TC', 'VI', 'UY', 'VE') +COUNTRIES_OF_INTEREST = tuple(set(COUNTRIES_CORE + COUNTRIES_FRIENDS)) +COUNTRIES_ALL = tuple(set(COUNTRIES_CORE + COUNTRIES_FRIENDS + COUNTRIES_NORDIC + COUNTRIES_AMERICAS)) + + +# %% +query_string = f'''select report_date, geo_id, deaths_weekly, culm_deaths +from weekly_cases +where geo_id in {COUNTRIES_CORE} +order by report_date, geo_id''' + +country_data = pd.read_sql_query(query_string, + engine, + index_col = 'report_date', + parse_dates = ['report_date'] + ) + + +# %% +deaths_culm = country_data.pivot(columns='geo_id', values='culm_deaths') + + +# %% +ax = deaths_culm.loc['2020-03-15':].plot(figsize=(10, 6), title="Total deaths, linear") +ax.set_xlabel(f"Date") +for c in COUNTRIES_CORE: + lvi = deaths_culm[c].last_valid_index() + ax.text(x = lvi + pd.Timedelta(days=1), y = deaths_culm[c][lvi], s = f"{c}: {deaths_culm[c][lvi]:.0f}") +plt.savefig('covid_deaths_total_linear.png') + + +# %% +deaths_weekly = country_data.pivot(columns='geo_id', values='deaths_weekly') + + +# %% +ax = deaths_weekly.loc['2020-03-01':, COUNTRIES_CORE].plot(figsize=(10, 6), title="Deaths per week") +ax.set_xlabel('Date') +for c in COUNTRIES_CORE: + lvi = deaths_weekly[c].last_valid_index() + ax.text(x = lvi + pd.Timedelta(days=1), y = deaths_weekly[c][lvi], s = c) +plt.savefig('covid_deaths_per_week.png') + + +# %% +ax = deaths_weekly.iloc[-6:].plot(figsize=(10, 6), title="Deaths per week")#, ylim=(-10, 100)) +ax.set_xlabel("Date") + +text_x_pos = deaths_weekly.last_valid_index() + pd.Timedelta(days=0.5) + +for c in COUNTRIES_CORE: + lvi = deaths_weekly[c].last_valid_index() +# if c != 'ES': + ax.text(x = text_x_pos, y = deaths_weekly[c][lvi], s = f"{c}: {deaths_weekly[c][lvi]:.0f}") +plt.savefig('deaths_by_date_last_6_weeks.png') + + +# %% + + + +