"""Constructs daily time series of COVID-19 testing data for Ireland.Dashboard: https://covid19ireland-geohive.hub.arcgis.com/pages/hospitals-icu--testing"""importjsonimportrequestsimportdatetimeimportpandasaspdfromcowidev.testingimportCountryTestBase
[docs]classIreland(CountryTestBase):location="Ireland"units="tests performed"TESTING_TYPE="PCR only"source_label="Government of Ireland"source_url_ref="https://covid19ireland-geohive.hub.arcgis.com/pages/hospitals-icu--testing"source_url="https://services-eu1.arcgis.com/z6bHNio59iTqqSUY/arcgis/rest/services/LaboratoryLocalTimeSeriesHistoricView/FeatureServer/0/query"rename_columns={"Date_HPSC":"Date","Test24":"Daily change in cumulative total","TotalLabs":"Cumulative total","PosR7":"Positive rate",}
[docs]defsanity_checks(df:pd.DataFrame)->None:"""checks that there are no obvious errors in the scraped data."""df_temp=df.copy()# checks that the max date is less than tomorrow's date.assertdatetime.datetime.strptime(df_temp["Date"].max(),"%Y-%m-%d")<(datetime.datetime.utcnow()+datetime.timedelta(days=1))# checks that there are no duplicate datesassertdf_temp["Date"].duplicated().sum()==0,"One or more rows share the same date."if"Cumulative total"notindf_temp.columns:df_temp["Cumulative total"]=df_temp["Daily change in cumulative total"].cumsum()# checks that the cumulative number of tests on date t is always greater than the figure for t-1:assert(df_temp["Cumulative total"].iloc[1:]>=df_temp["Cumulative total"].shift(1).iloc[1:]).all(),"On one or more dates, `Cumulative total` is greater on date t-1."returnNone