CSSEGISandData / COVID-19

Novel Coronavirus (COVID-19) Cases, provided by JHU CSSE
https://systems.jhu.edu/research/public-health/ncov/
29.14k stars 18.46k forks source link

Python Script for COVID-19 JHU.EDU CSSE Data Analytics #802

Open VTSTech opened 4 years ago

VTSTech commented 4 years ago

Hello,

My name is Nigel Todman, I'm a software developer from Canada. I've written a Python script to parse the JHU CSSE Data from GitHub and produce various stats and metrics. Perhaps this would be useful to yourself or your colleagues. I often found myself making these calculations by hand every day. And now I can produce these stats globally or nationally rather quickly. (or even automatically)

Screenshot: Source Code: https://github.com/Veritas83/VTSTech-COVID19.py

Regards,

Nigel Todman Software Developer/Technical Consultant VTSTech Veritas Technical Solutions

hbdo commented 4 years ago

Hello,

Thank you for your script. However getcc method really bothered me. Too many elif commands are unpythonic. The correct way to do it is to use a list or a dict. It both has a faster runtime and makes it easier to add, remove or change the country codes.

I couldn't find a way to add commit to your code on gist (probably not possible). Thus I paste my suggestion here so you can copy and update your script if you find this useful.

country_dict = {
"af" : "Afghanistan"
"ax" : "Aland"
"al" : "Albania"
"dz" : "Algeria"
"as" : "American Samoa"
"ad" : "Andorra"
"ao" : "Angola"
"ai" : "Anguilla"
"aq" : "Antarctica"
"ag" : "Antigua and Barbuda"
"ar" : "Argentina"
"am" : "Armenia"
"aw" : "Aruba"
"au" : "Australia"
"at" : "Austria"
"az" : "Azerbaijan"
"bs" : "Bahamas"
"bh" : "Bahrain"
"bd" : "Bangladesh"
"bb" : "Barbados"
"by" : "Belarus"
"be" : "Belgium"
"bz" : "Belize"
"bj" : "Benin"
"bm" : "Bermuda"
"bt" : "Bhutan"
"bo" : "Bolivia"
"bq" : "Bonaire, Sint Eustatius and Saba"
"ba" : "Bosnia and Herzegovina"
"bw" : "Botswana"
"bv" : "Bouvet Island"
"br" : "Brazil"
"io" : "British Indian Ocean Territory"
"bn" : "Brunei Darussalam"
"bg" : "Bulgaria"
"bf" : "Burkina Faso"
"bi" : "Burundi"
"kh" : "Cambodia"
"cm" : "Cameroon"
"ca" : "Canada"
"cv" : "Cabo Verde"
"ky" : "Cayman Islands"
"cf" : "Central African Republic"
"td" : "Chad"
"cl" : "Chile"
"cn" : "China"
"cx" : "Christmas Island"
"cc" : "Cocos (Keeling) Islands"
"co" : "Colombia"
"cs" : "Cruise Ship"
"km" : "Comoros"
"cg" : "Congo (Kinshasa)"
"cd" : "Congo (Democratic Republic of the)"
"ck" : "Cook Islands"
"cr" : "Costa Rica"
"ci" : "Cote d'Ivoire"
"hr" : "Croatia"
"cu" : "Cuba"
"cw" : "Curacao"
"cy" : "Cyprus"
"cz" : "Czech Republic"
"dk" : "Denmark"
"dj" : "Djibouti"
"dm" : "Dominica"
"do" : "Dominican Republic"
"ec" : "Ecuador"
"eg" : "Egypt"
"sv" : "El Salvador"
"gq" : "Equatorial Guinea"
"er" : "Eritrea"
"ee" : "Estonia"
"et" : "Ethiopia"
"fk" : "Falkland Islands (Malvinas)"
"fo" : "Faroe Islands"
"fj" : "Fiji"
"fi" : "Finland"
"fr" : "France"
"gf" : "French Guiana"
"pf" : "French Polynesia"
"tf" : "French Southern Territories"
"ga" : "Gabon"
"gm" : "Gambia"
"ge" : "Georgia"
"de" : "Germany"
"gh" : "Ghana"
"gi" : "Gibraltar"
"gr" : "Greece"
"gl" : "Greenland"
"gd" : "Grenada"
"gp" : "Guadeloupe"
"gu" : "Guam"
"gt" : "Guatemala"
"gg" : "Guernsey"
"gn" : "Guinea"
"gw" : "Guinea-Bissau"
"gy" : "Guyana"
"ht" : "Haiti"
"hm" : "Heard Island and McDonald Islands"
"va" : "Holy See"
"hn" : "Honduras"
"hk" : "Hong Kong"
"hu" : "Hungary"
"is" : "Iceland"
"in" : "India"
"id" : "Indonesia"
"ir" : "Iran"
"iq" : "Iraq"
"ie" : "Ireland"
"im" : "Isle of Man"
"il" : "Israel"
"it" : "Italy"
"jm" : "Jamaica"
"jp" : "Japan"
"je" : "Jersey"
"jo" : "Jordan"
"kz" : "Kazakhstan"
"ke" : "Kenya"
"ki" : "Kiribati"
"kp" : "North Korea"
"kr" : "South Korea"
"kw" : "Kuwait"
"kg" : "Kyrgyzstan"
"la" : "Lao People's Democratic Republic"
"lv" : "Latvia"
"lb" : "Lebanon"
"ls" : "Lesotho"
"lr" : "Liberia"
"ly" : "Libya"
"li" : "Liechtenstein"
"lt" : "Lithuania"
"lu" : "Luxembourg"
"mo" : "Macao"
"mk" : "North Macedonia"
"mg" : "Madagascar"
"mw" : "Malawi"
"my" : "Malaysia"
"mv" : "Maldives"
"ml" : "Mali"
"mt" : "Malta"
"mh" : "Marshall Islands"
"mq" : "Martinique"
"mr" : "Mauritania"
"mu" : "Mauritius"
"yt" : "Mayotte"
"mx" : "Mexico"
"fm" : "Micronesia"
"md" : "Moldova"
"mc" : "Monaco"
"mn" : "Mongolia"
"me" : "Montenegro"
"ms" : "Montserrat"
"ma" : "Morocco"
"mz" : "Mozambique"
"mm" : "Myanmar"
"na" : "Namibia"
"nr" : "Nauru"
"np" : "Nepal"
"nl" : "Netherlands"
"nc" : "New Caledonia"
"nz" : "New Zealand"
"ni" : "Nicaragua"
"ne" : "Niger"
"ng" : "Nigeria"
"nu" : "Niue"
"nf" : "Norfolk Island"
"mp" : "Northern Mariana Islands"
"no" : "Norway"
"om" : "Oman"
"pk" : "Pakistan"
"pw" : "Palau"
"ps" : "occupied Palestinian territory"
"pa" : "Panama"
"pg" : "Papua New Guinea"
"py" : "Paraguay"
"pe" : "Peru"
"ph" : "Philippines"
"pn" : "Pitcairn"
"pl" : "Poland"
"pt" : "Portugal"
"pr" : "Puerto Rico"
"qa" : "Qatar"
"re" : "Reunion"
"ro" : "Romania"
"ru" : "Russian Federation"
"rw" : "Rwanda"
"bl" : "Saint Barthelemy"
"sh" : "Saint Helena, Ascension and Tristan da Cunha"
"kn" : "Saint Kitts and Nevis"
"lc" : "Saint Lucia"
"mf" : "Saint Martin (French part)"
"pm" : "Saint Pierre and Miquelon"
"vc" : "Saint Vincent and the Grenadines"
"ws" : "Samoa"
"sm" : "San Marino"
"st" : "Sao Tome and Principe"
"sa" : "Saudi Arabia"
"sn" : "Senegal"
"rs" : "Serbia"
"sc" : "Seychelles"
"sl" : "Sierra Leone"
"sg" : "Singapore"
"sx" : "Sint Maarten (Dutch part)"
"sk" : "Slovakia"
"si" : "Slovenia"
"sb" : "Solomon Islands"
"so" : "Somalia"
"za" : "South Africa"
"gs" : "South Georgia and the South Sandwich Islands"
"ss" : "South Sudan"
"es" : "Spain"
"lk" : "Sri Lanka"
"sd" : "Sudan"
"sr" : "Suriname"
"sj" : "Svalbard and Jan Mayen"
"sz" : "Swaziland"
"se" : "Sweden"
"ch" : "Switzerland"
"sy" : "Syrian Arab Republic"
"tw" : "Taiwan, Province of China"
"tj" : "Tajikistan"
"tz" : "Tanzania, United Republic of"
"th" : "Thailand"
"tl" : "Timor-Leste"
"tg" : "Togo"
"tk" : "Tokelau"
"to" : "Tonga"
"tt" : "Trinidad and Tobago"
"tn" : "Tunisia"
"tr" : "Turkey"
"tm" : "Turkmenistan"
"tc" : "Turks and Caicos Islands"
"tv" : "Tuvalu"
"ug" : "Uganda"
"ua" : "Ukraine"
"ae" : "United Arab Emirates"
"gb" : "United Kingdom"
"us" : "US"
"um" : "United States Minor Outlying Islands"
"uy" : "Uruguay"
"uz" : "Uzbekistan"
"vu" : "Vanuatu"
"ve" : "Venezuela (Bolivarian Republic of)"
"vn" : "Viet Nam"
"vg" : "Virgin Islands (British)"
"vi" : "Virgin Islands (U.S.)"
"wf" : "Wallis and Futuna"
"eh" : "Western Sahara"
"ye" : "Yemen"
"zm" : "Zambia"
"zw" : "Zimbabwe"}

def getcc(cc):
    return country_dict[cc.lower()]
Bost commented 4 years ago

@hbdo you're missing Kosovo @Veritas83 see https://github.com/ExpDev07/coronavirus-tracker-api/blob/master/app/utils/countrycodes.py It has also some aliases. I think I named them synonyms there. Anyway the same written in clojure exists also in my repo https://github.com/Bost/corona_cases

What about joining forces guys?

Bost commented 4 years ago

See also https://github.com/covid19-data/covid19-data

VTSTech commented 4 years ago

Thx for suggestions, Script updated. I'll see about moving the gist to a github repo later today.

Now on GitHub https://github.com/Veritas83/VTSTech-COVID19.py

Quick Install:

git clone https://github.com/CSSEGISandData/COVID-19
cd COVID-19
wget https://github.com/Veritas83/VTSTech-COVID19.py/raw/master/VTSTech-COVID19.py
RichWellum commented 4 years ago

Great work @Veritas83 ! I also wrote a small tool: Github - it's concept was much smaller in depth - a continuous running count of totals, and an alert (saved results and Tweet) when something changes. It tweets to this account: tweet - that's just my account though. Would be cool to incorporate your tool and send out some of these deeper level results.

Note my tool is also in pypi - which you might think about for the future.