diff --git a/data/parsers/singapore.py b/data/parsers/singapore.py new file mode 100644 index 000000000..a8bd279f4 --- /dev/null +++ b/data/parsers/singapore.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +""" +Created on Sat May 23 23:15:07 2020 + +@author: hxchua +""" + +import sys +import requests +import csv +import io +from datetime import datetime +import pandas as pd + +from .utils import store_data, stoi + +# ------------------------------------------------------------------------ +# Globals + +URL = "https://raw.githubusercontent.com/hxchua/datadoubleconfirm/master/datasets/covid19_sg.csv" +cols = ['time', 'cases', 'deaths', 'hospitalized', 'icu', 'recovered'] + +# ------------------------------------------------------------------------ +# Main point of entry + +def parse(): + r = requests.get(URL) + if not r.ok: + print(f"Failed to fetch {URL}", file=sys.stderr) + exit(1) + r.close() + sg_data = dict(Singapore=[]) + + df = pd.read_csv(URL) + + df.loc[df['Date'] <= '2020-03-19', 'hosp_cleaned'] = df['Still_Hospitalised'] - df['Intensive_Care_Unit_(ICU)'] + df.loc[df['Date'] > '2020-03-19', 'hosp_cleaned'] = df['General_Wards_MOH_report'] + + for i in range(0,df.shape[0]): + date_str = df['Date'][i] + num_cases = df['Cumulative_Confirmed'][i] + num_deaths = df['Cumulative_Deaths'][i] + num_hosp = df['hosp_cleaned'][i].astype(int) + num_icus = df['Intensive_Care_Unit_(ICU)'][i] + num_recovered = df['Cumulative_Discharged'][i] + + sg_data["Singapore"].append([date_str, num_cases, num_deaths, num_hosp, num_icus, num_recovered]) + + store_data(sg_data, 'singapore', cols) \ No newline at end of file diff --git a/data/sources.json b/data/sources.json index 756d9ddbf..a0b27b4b6 100644 --- a/data/sources.json +++ b/data/sources.json @@ -74,6 +74,11 @@ "dataProvenance": "https://www.mhlw.go.jp/stf/seisakunitsuite/bunya/0000121431_00086.html", "license": "MIT license" }, + "singapore": { + "primarySource": "https://github.com/hxchua/datadoubleconfirm/blob/master/datasets/covid19_sg.csv", + "dataProvenance": "https://data.world/hxchua/covid-19-singapore", + "license": "MIT license" + }, "ecdc": { "primarySource": "https://www.ecdc.europa.eu/sites/default/files/documents/COVID-19-geographic-disbtribution-worldwide--xlsx", "dataProvenance": "European Centre for Disease Prevention and Control",