diff --git a/README.md b/README.md index aea9d8d..3172193 100644 --- a/README.md +++ b/README.md @@ -3367,7 +3367,7 @@ continents = pd.read_csv('https://datahub.io/JohnSnowLabs/country-and-continent- df = pd.merge(covid, continents, left_on='iso_code', right_on='Three_Letter_Country_Code') df = df.groupby(['Continent_Name', 'date']).sum().reset_index() df['Total Deaths per Million'] = df.total_deaths * 1e6 / df.population -df = df[('2020-03-14' < df.date) & (df.date < '2020-10-22')] +df = df[('2020-03-14' < df.date) & (df.date < '2020-10-23')] df = df.rename({'date': 'Date', 'Continent_Name': 'Continent'}, axis='columns') line(df, x='Date', y='Total Deaths per Million', color='Continent').show() ``` diff --git a/index.html b/index.html index 8da2457..7aecab9 100644 --- a/index.html +++ b/index.html @@ -2858,7 +2858,7 @@ continents = pd.read_csv('https://datahub.io/JohnSnowL df = pd.merge(covid, continents, left_on='iso_code', right_on='Three_Letter_Country_Code') df = df.groupby(['Continent_Name', 'date']).sum().reset_index() df['Total Deaths per Million'] = df.total_deaths * 1e6 / df.population -df = df[('2020-03-14' < df.date) & (df.date < '2020-10-22')] +df = df[('2020-03-14' < df.date) & (df.date < '2020-10-23')] df = df.rename({'date': 'Date', 'Continent_Name': 'Continent'}, axis='columns') line(df, x='Date', y='Total Deaths per Million', color='Continent').show() diff --git a/web/covid_cases.js b/web/covid_cases.js index 279db68..8a867eb 100644 --- a/web/covid_cases.js +++ b/web/covid_cases.js @@ -252,7 +252,8 @@ if (document.getElementById("e23ccacc-a456-478b-b467-7282a2165921")) { "2020-10-19", "2020-10-20", "2020-10-21", - "2020-10-22" + "2020-10-22", + "2020-10-23" ], "y": [ 100.0, @@ -496,8 +497,9 @@ if (document.getElementById("e23ccacc-a456-478b-b467-7282a2165921")) { 100.94579531386498, 100.82351279089583, 100.76013021633324, - 100.70921780571318, - 100.59579644650836 + 100.70378136188316, + 100.60235832660891, + 100.53639551861964 ], "yaxis": "y2" }, @@ -747,7 +749,8 @@ if (document.getElementById("e23ccacc-a456-478b-b467-7282a2165921")) { "2020-10-19", "2020-10-20", "2020-10-21", - "2020-10-22" + "2020-10-22", + "2020-10-23" ], "y": [ 100.0, @@ -991,8 +994,9 @@ if (document.getElementById("e23ccacc-a456-478b-b467-7282a2165921")) { 116.18301671207496, 116.2653792355378, 116.26964958595707, - 116.28707150548874, - 116.32715094053142 + 116.26232877170584, + 116.29520574354568, + 116.32206652401433 ], "yaxis": "y2" }, @@ -1242,7 +1246,8 @@ if (document.getElementById("e23ccacc-a456-478b-b467-7282a2165921")) { "2020-10-19", "2020-10-20", "2020-10-21", - "2020-10-22" + "2020-10-22", + "2020-10-23" ], "y": [ 100.0, @@ -1485,9 +1490,10 @@ if (document.getElementById("e23ccacc-a456-478b-b467-7282a2165921")) { 122.35777113065551, 123.83856468187685, 125.41920751584826, - 127.18969254820887, - 127.91300448754124, - 129.04446417913965 + 127.18138014691964, + 128.81272370627855, + 129.91843445644795, + 131.25335941953276 ], "yaxis": "y2" }, @@ -1737,7 +1743,8 @@ if (document.getElementById("e23ccacc-a456-478b-b467-7282a2165921")) { "2020-10-19", "2020-10-20", "2020-10-21", - "2020-10-22" + "2020-10-22", + "2020-10-23" ], "y": [ 157636.0, @@ -1974,15 +1981,16 @@ if (document.getElementById("e23ccacc-a456-478b-b467-7282a2165921")) { 74653792.0, 75262828.0, 75840302.0, - 76501660.0, - 77278332.0, - 78083060.0, - 78876772.0, - 79615010.0, - 80339418.0, - 81035986.0, - 81818264.0, - 82707230.0 + 76501664.0, + 77278342.0, + 78083082.0, + 78876896.0, + 79615168.0, + 80339580.0, + 81037390.0, + 81823820.0, + 82722006.0, + 83651126.0 ], "yaxis": "y" } diff --git a/web/covid_cases.png b/web/covid_cases.png index 4da864d..15cc545 100644 Binary files a/web/covid_cases.png and b/web/covid_cases.png differ diff --git a/web/covid_deaths.js b/web/covid_deaths.js index dbd01e0..a40489e 100644 --- a/web/covid_deaths.js +++ b/web/covid_deaths.js @@ -238,7 +238,8 @@ if (document.getElementById("2a950764-39fc-416d-97fe-0a6226a3095f")) { "2020-10-18", "2020-10-19", "2020-10-20", - "2020-10-21" + "2020-10-21", + "2020-10-22" ], "xaxis": "x", "y": [ @@ -462,7 +463,8 @@ if (document.getElementById("2a950764-39fc-416d-97fe-0a6226a3095f")) { 29.530605941746504, 29.670218201217267, 29.812070229556547, - 30.024848272065466 + 30.024848272065466, + 30.233146776837355 ], "yaxis": "y" }, @@ -698,7 +700,8 @@ if (document.getElementById("2a950764-39fc-416d-97fe-0a6226a3095f")) { "2020-10-18", "2020-10-19", "2020-10-20", - "2020-10-21" + "2020-10-21", + "2020-10-22" ], "xaxis": "x", "y": [ @@ -922,7 +925,8 @@ if (document.getElementById("2a950764-39fc-416d-97fe-0a6226a3095f")) { 52.07089649505094, 52.38838012346937, 52.73240850117826, - 53.11878207418384 + 53.11878207418384, + 53.516110623087066 ], "yaxis": "y" }, @@ -1158,7 +1162,8 @@ if (document.getElementById("2a950764-39fc-416d-97fe-0a6226a3095f")) { "2020-10-18", "2020-10-19", "2020-10-20", - "2020-10-21" + "2020-10-21", + "2020-10-22" ], "xaxis": "x", "y": [ @@ -1382,7 +1387,8 @@ if (document.getElementById("2a950764-39fc-416d-97fe-0a6226a3095f")) { 289.66493228505936, 291.1324313445736, 292.75106434811016, - 294.780412497234 + 294.780412497234, + 296.9332059288799 ], "yaxis": "y" }, @@ -1618,7 +1624,8 @@ if (document.getElementById("2a950764-39fc-416d-97fe-0a6226a3095f")) { "2020-10-18", "2020-10-19", "2020-10-20", - "2020-10-21" + "2020-10-21", + "2020-10-22" ], "xaxis": "x", "y": [ @@ -1842,7 +1849,8 @@ if (document.getElementById("2a950764-39fc-416d-97fe-0a6226a3095f")) { 557.8591103687505, 558.7961201833347, 560.0071292577792, - 562.6405665886591 + 562.6405665886591, + 565.6359535591077 ], "yaxis": "y" }, @@ -2078,7 +2086,8 @@ if (document.getElementById("2a950764-39fc-416d-97fe-0a6226a3095f")) { "2020-10-18", "2020-10-19", "2020-10-20", - "2020-10-21" + "2020-10-21", + "2020-10-22" ], "xaxis": "x", "y": [ @@ -2298,11 +2307,12 @@ if (document.getElementById("2a950764-39fc-416d-97fe-0a6226a3095f")) { 24.75687479369271, 24.927780240986447, 24.56465689033343, - 24.588669262660247, - 24.660706379640697, - 24.660706379640697, - 24.684718751967512, - 24.756755868947963 + 24.58203105382687, + 24.65404872292988, + 24.65404872292988, + 24.67805461263088, + 24.75007228173389, + 24.798084061135896 ], "yaxis": "y" }, @@ -2538,7 +2548,8 @@ if (document.getElementById("2a950764-39fc-416d-97fe-0a6226a3095f")) { "2020-10-18", "2020-10-19", "2020-10-20", - "2020-10-21" + "2020-10-21", + "2020-10-22" ], "xaxis": "x", "y": [ @@ -2762,7 +2773,8 @@ if (document.getElementById("2a950764-39fc-416d-97fe-0a6226a3095f")) { 647.8773726099147, 649.5290898417787, 651.861472543314, - 655.0394601286728 + 655.0394601286728, + 658.210478443011 ], "yaxis": "y" } diff --git a/web/covid_deaths.png b/web/covid_deaths.png index 5776ed7..33e88dc 100644 Binary files a/web/covid_deaths.png and b/web/covid_deaths.png differ diff --git a/web/update_plots.py b/web/update_plots.py index f56065c..f28cb63 100755 --- a/web/update_plots.py +++ b/web/update_plots.py @@ -12,18 +12,18 @@ import re def main(): - # print('Updating covid deaths...') - # update_covid_deaths() + print('Updating covid deaths...') + update_covid_deaths() print('Updating covid cases...') update_confirmed_cases() def update_covid_deaths(): def update_readme(date_treshold): - lines = read_file('../README.md') + lines = read_file(Path('..') / 'README.md') out = [re.sub("df.date < '\d{4}-\d{2}-\d{2}'", f"df.date < '{date_treshold}'", line) for line in lines] - write_to_file('../README.md', out) + write_to_file(Path('..') / 'README.md', out) covid = pd.read_csv('https://covid.ourworldindata.org/data/owid-covid-data.csv', usecols=['iso_code', 'date', 'total_deaths', 'population']) continents = pd.read_csv('https://datahub.io/JohnSnowLabs/country-and-continent-codes-' + \ @@ -39,6 +39,7 @@ def update_covid_deaths(): f.update_layout(margin=dict(t=24, b=0), paper_bgcolor='rgba(0, 0, 0, 0)') update_file('covid_deaths.js', f) update_readme(date_treshold) + write_to_png_file('covid_deaths.png', f, width=960, height=340) def update_confirmed_cases(): @@ -46,6 +47,7 @@ def update_confirmed_cases(): df = wrangle_data(*scrape_data()) f = get_figure(df) update_file('covid_cases.js', f) + write_to_png_file('covid_cases.png', f, width=960, height=315) def scrape_data(): def scrape_yahoo(id_): @@ -99,14 +101,21 @@ def update_file(filename, figure): # def read_file(filename): - with open(filename, encoding='utf-8') as file: + p = Path(__file__).resolve().parent / filename + with open(p, encoding='utf-8') as file: return file.readlines() def write_to_file(filename, lines): - with open(filename, 'w', encoding='utf-8') as file: + p = Path(__file__).resolve().parent / filename + with open(p, 'w', encoding='utf-8') as file: file.writelines(lines) +def write_to_png_file(filename, figure, width, height): + p = Path(__file__).resolve().parent / filename + figure.write_image(str(p), width=width, height=height) + + if __name__ == '__main__': main()