Skip to content

Commit

Permalink
add singapore parser
Browse files Browse the repository at this point in the history
  • Loading branch information
hxchua committed May 23, 2020
1 parent d666106 commit 62d7a0a
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions data/parsers/singapore.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 62d7a0a

Please sign in to comment.