Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b632add

Browse files
committed
Updated plot images
1 parent de13783 commit b632add

File tree

7 files changed

+73
-44
lines changed

7 files changed

+73
-44
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3367,7 +3367,7 @@ continents = pd.read_csv('https://datahub.io/JohnSnowLabs/country-and-continent-
33673367
df = pd.merge(covid, continents, left_on='iso_code', right_on='Three_Letter_Country_Code')
33683368
df = df.groupby(['Continent_Name', 'date']).sum().reset_index()
33693369
df['Total Deaths per Million'] = df.total_deaths * 1e6 / df.population
3370-
df = df[('2020-03-14' < df.date) & (df.date < '2020-10-22')]
3370+
df = df[('2020-03-14' < df.date) & (df.date < '2020-10-23')]
33713371
df = df.rename({'date': 'Date', 'Continent_Name': 'Continent'}, axis='columns')
33723372
line(df, x='Date', y='Total Deaths per Million', color='Continent').show()
33733373
```

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2858,7 +2858,7 @@
28582858
df = pd.merge(covid, continents, left_on=<span class="hljs-string">'iso_code'</span>, right_on=<span class="hljs-string">'Three_Letter_Country_Code'</span>)
28592859
df = df.groupby([<span class="hljs-string">'Continent_Name'</span>, <span class="hljs-string">'date'</span>]).sum().reset_index()
28602860
df[<span class="hljs-string">'Total Deaths per Million'</span>] = df.total_deaths * <span class="hljs-number">1e6</span> / df.population
2861-
df = df[(<span class="hljs-string">'2020-03-14'</span> &lt; df.date) &amp; (df.date &lt; <span class="hljs-string">'2020-10-22'</span>)]
2861+
df = df[(<span class="hljs-string">'2020-03-14'</span> &lt; df.date) &amp; (df.date &lt; <span class="hljs-string">'2020-10-23'</span>)]
28622862
df = df.rename({<span class="hljs-string">'date'</span>: <span class="hljs-string">'Date'</span>, <span class="hljs-string">'Continent_Name'</span>: <span class="hljs-string">'Continent'</span>}, axis=<span class="hljs-string">'columns'</span>)
28632863
line(df, x=<span class="hljs-string">'Date'</span>, y=<span class="hljs-string">'Total Deaths per Million'</span>, color=<span class="hljs-string">'Continent'</span>).show()
28642864
</code></pre></div>

web/covid_cases.js

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@ if (document.getElementById("e23ccacc-a456-478b-b467-7282a2165921")) {
252252
"2020-10-19",
253253
"2020-10-20",
254254
"2020-10-21",
255-
"2020-10-22"
255+
"2020-10-22",
256+
"2020-10-23"
256257
],
257258
"y": [
258259
100.0,
@@ -496,8 +497,9 @@ if (document.getElementById("e23ccacc-a456-478b-b467-7282a2165921")) {
496497
100.94579531386498,
497498
100.82351279089583,
498499
100.76013021633324,
499-
100.70921780571318,
500-
100.59579644650836
500+
100.70378136188316,
501+
100.60235832660891,
502+
100.53639551861964
501503
],
502504
"yaxis": "y2"
503505
},
@@ -747,7 +749,8 @@ if (document.getElementById("e23ccacc-a456-478b-b467-7282a2165921")) {
747749
"2020-10-19",
748750
"2020-10-20",
749751
"2020-10-21",
750-
"2020-10-22"
752+
"2020-10-22",
753+
"2020-10-23"
751754
],
752755
"y": [
753756
100.0,
@@ -991,8 +994,9 @@ if (document.getElementById("e23ccacc-a456-478b-b467-7282a2165921")) {
991994
116.18301671207496,
992995
116.2653792355378,
993996
116.26964958595707,
994-
116.28707150548874,
995-
116.32715094053142
997+
116.26232877170584,
998+
116.29520574354568,
999+
116.32206652401433
9961000
],
9971001
"yaxis": "y2"
9981002
},
@@ -1242,7 +1246,8 @@ if (document.getElementById("e23ccacc-a456-478b-b467-7282a2165921")) {
12421246
"2020-10-19",
12431247
"2020-10-20",
12441248
"2020-10-21",
1245-
"2020-10-22"
1249+
"2020-10-22",
1250+
"2020-10-23"
12461251
],
12471252
"y": [
12481253
100.0,
@@ -1485,9 +1490,10 @@ if (document.getElementById("e23ccacc-a456-478b-b467-7282a2165921")) {
14851490
122.35777113065551,
14861491
123.83856468187685,
14871492
125.41920751584826,
1488-
127.18969254820887,
1489-
127.91300448754124,
1490-
129.04446417913965
1493+
127.18138014691964,
1494+
128.81272370627855,
1495+
129.91843445644795,
1496+
131.25335941953276
14911497
],
14921498
"yaxis": "y2"
14931499
},
@@ -1737,7 +1743,8 @@ if (document.getElementById("e23ccacc-a456-478b-b467-7282a2165921")) {
17371743
"2020-10-19",
17381744
"2020-10-20",
17391745
"2020-10-21",
1740-
"2020-10-22"
1746+
"2020-10-22",
1747+
"2020-10-23"
17411748
],
17421749
"y": [
17431750
157636.0,
@@ -1974,15 +1981,16 @@ if (document.getElementById("e23ccacc-a456-478b-b467-7282a2165921")) {
19741981
74653792.0,
19751982
75262828.0,
19761983
75840302.0,
1977-
76501660.0,
1978-
77278332.0,
1979-
78083060.0,
1980-
78876772.0,
1981-
79615010.0,
1982-
80339418.0,
1983-
81035986.0,
1984-
81818264.0,
1985-
82707230.0
1984+
76501664.0,
1985+
77278342.0,
1986+
78083082.0,
1987+
78876896.0,
1988+
79615168.0,
1989+
80339580.0,
1990+
81037390.0,
1991+
81823820.0,
1992+
82722006.0,
1993+
83651126.0
19861994
],
19871995
"yaxis": "y"
19881996
}

web/covid_cases.png

-43.8 KB
Loading

web/covid_deaths.js

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,8 @@ if (document.getElementById("2a950764-39fc-416d-97fe-0a6226a3095f")) {
238238
"2020-10-18",
239239
"2020-10-19",
240240
"2020-10-20",
241-
"2020-10-21"
241+
"2020-10-21",
242+
"2020-10-22"
242243
],
243244
"xaxis": "x",
244245
"y": [
@@ -462,7 +463,8 @@ if (document.getElementById("2a950764-39fc-416d-97fe-0a6226a3095f")) {
462463
29.530605941746504,
463464
29.670218201217267,
464465
29.812070229556547,
465-
30.024848272065466
466+
30.024848272065466,
467+
30.233146776837355
466468
],
467469
"yaxis": "y"
468470
},
@@ -698,7 +700,8 @@ if (document.getElementById("2a950764-39fc-416d-97fe-0a6226a3095f")) {
698700
"2020-10-18",
699701
"2020-10-19",
700702
"2020-10-20",
701-
"2020-10-21"
703+
"2020-10-21",
704+
"2020-10-22"
702705
],
703706
"xaxis": "x",
704707
"y": [
@@ -922,7 +925,8 @@ if (document.getElementById("2a950764-39fc-416d-97fe-0a6226a3095f")) {
922925
52.07089649505094,
923926
52.38838012346937,
924927
52.73240850117826,
925-
53.11878207418384
928+
53.11878207418384,
929+
53.516110623087066
926930
],
927931
"yaxis": "y"
928932
},
@@ -1158,7 +1162,8 @@ if (document.getElementById("2a950764-39fc-416d-97fe-0a6226a3095f")) {
11581162
"2020-10-18",
11591163
"2020-10-19",
11601164
"2020-10-20",
1161-
"2020-10-21"
1165+
"2020-10-21",
1166+
"2020-10-22"
11621167
],
11631168
"xaxis": "x",
11641169
"y": [
@@ -1382,7 +1387,8 @@ if (document.getElementById("2a950764-39fc-416d-97fe-0a6226a3095f")) {
13821387
289.66493228505936,
13831388
291.1324313445736,
13841389
292.75106434811016,
1385-
294.780412497234
1390+
294.780412497234,
1391+
296.9332059288799
13861392
],
13871393
"yaxis": "y"
13881394
},
@@ -1618,7 +1624,8 @@ if (document.getElementById("2a950764-39fc-416d-97fe-0a6226a3095f")) {
16181624
"2020-10-18",
16191625
"2020-10-19",
16201626
"2020-10-20",
1621-
"2020-10-21"
1627+
"2020-10-21",
1628+
"2020-10-22"
16221629
],
16231630
"xaxis": "x",
16241631
"y": [
@@ -1842,7 +1849,8 @@ if (document.getElementById("2a950764-39fc-416d-97fe-0a6226a3095f")) {
18421849
557.8591103687505,
18431850
558.7961201833347,
18441851
560.0071292577792,
1845-
562.6405665886591
1852+
562.6405665886591,
1853+
565.6359535591077
18461854
],
18471855
"yaxis": "y"
18481856
},
@@ -2078,7 +2086,8 @@ if (document.getElementById("2a950764-39fc-416d-97fe-0a6226a3095f")) {
20782086
"2020-10-18",
20792087
"2020-10-19",
20802088
"2020-10-20",
2081-
"2020-10-21"
2089+
"2020-10-21",
2090+
"2020-10-22"
20822091
],
20832092
"xaxis": "x",
20842093
"y": [
@@ -2298,11 +2307,12 @@ if (document.getElementById("2a950764-39fc-416d-97fe-0a6226a3095f")) {
22982307
24.75687479369271,
22992308
24.927780240986447,
23002309
24.56465689033343,
2301-
24.588669262660247,
2302-
24.660706379640697,
2303-
24.660706379640697,
2304-
24.684718751967512,
2305-
24.756755868947963
2310+
24.58203105382687,
2311+
24.65404872292988,
2312+
24.65404872292988,
2313+
24.67805461263088,
2314+
24.75007228173389,
2315+
24.798084061135896
23062316
],
23072317
"yaxis": "y"
23082318
},
@@ -2538,7 +2548,8 @@ if (document.getElementById("2a950764-39fc-416d-97fe-0a6226a3095f")) {
25382548
"2020-10-18",
25392549
"2020-10-19",
25402550
"2020-10-20",
2541-
"2020-10-21"
2551+
"2020-10-21",
2552+
"2020-10-22"
25422553
],
25432554
"xaxis": "x",
25442555
"y": [
@@ -2762,7 +2773,8 @@ if (document.getElementById("2a950764-39fc-416d-97fe-0a6226a3095f")) {
27622773
647.8773726099147,
27632774
649.5290898417787,
27642775
651.861472543314,
2765-
655.0394601286728
2776+
655.0394601286728,
2777+
658.210478443011
27662778
],
27672779
"yaxis": "y"
27682780
}

web/covid_deaths.png

-57.1 KB
Loading

web/update_plots.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@
1212

1313

1414
def main():
15-
# print('Updating covid deaths...')
16-
# update_covid_deaths()
15+
print('Updating covid deaths...')
16+
update_covid_deaths()
1717
print('Updating covid cases...')
1818
update_confirmed_cases()
1919

2020

2121
def update_covid_deaths():
2222
def update_readme(date_treshold):
23-
lines = read_file('../README.md')
23+
lines = read_file(Path('..') / 'README.md')
2424
out = [re.sub("df.date < '\d{4}-\d{2}-\d{2}'", f"df.date < '{date_treshold}'", line)
2525
for line in lines]
26-
write_to_file('../README.md', out)
26+
write_to_file(Path('..') / 'README.md', out)
2727
covid = pd.read_csv('https://covid.ourworldindata.org/data/owid-covid-data.csv',
2828
usecols=['iso_code', 'date', 'total_deaths', 'population'])
2929
continents = pd.read_csv('https://datahub.io/JohnSnowLabs/country-and-continent-codes-' + \
@@ -39,13 +39,15 @@ def update_readme(date_treshold):
3939
f.update_layout(margin=dict(t=24, b=0), paper_bgcolor='rgba(0, 0, 0, 0)')
4040
update_file('covid_deaths.js', f)
4141
update_readme(date_treshold)
42+
write_to_png_file('covid_deaths.png', f, width=960, height=340)
4243

4344

4445
def update_confirmed_cases():
4546
def main():
4647
df = wrangle_data(*scrape_data())
4748
f = get_figure(df)
4849
update_file('covid_cases.js', f)
50+
write_to_png_file('covid_cases.png', f, width=960, height=315)
4951

5052
def scrape_data():
5153
def scrape_yahoo(id_):
@@ -99,14 +101,21 @@ def update_file(filename, figure):
99101
#
100102

101103
def read_file(filename):
102-
with open(filename, encoding='utf-8') as file:
104+
p = Path(__file__).resolve().parent / filename
105+
with open(p, encoding='utf-8') as file:
103106
return file.readlines()
104107

105108

106109
def write_to_file(filename, lines):
107-
with open(filename, 'w', encoding='utf-8') as file:
110+
p = Path(__file__).resolve().parent / filename
111+
with open(p, 'w', encoding='utf-8') as file:
108112
file.writelines(lines)
109113

110114

115+
def write_to_png_file(filename, figure, width, height):
116+
p = Path(__file__).resolve().parent / filename
117+
figure.write_image(str(p), width=width, height=height)
118+
119+
111120
if __name__ == '__main__':
112121
main()

0 commit comments

Comments
 (0)