[docs]classRwanda(CountryTestBase):location:str="Rwanda"units:str="samples tested"source_label:str="Rwanda Ministry of Health"source_url:str="https://gis.rbc.gov.rw/server/rest/services/Hosted/service_b580a3db9319449e82045881f1667b01/FeatureServer/0/query"source_url_ref:str="https://rbc.gov.rw/index.php?id=707"rename_columns:dict={# "attributes.sample_tested": "Daily change in cumulative total","attributes.cumulative_test":"Cumulative total","attributes.created_date":"Date",}date_start:str="2021-11-08"params:dict={"f":"json","where":"1=1","returnGeometry":False,"spatialRel":"esriSpatialRelIntersects","orderByFields":"created_date desc","outFields":"*","resultRecordCount":32000,"resultType":"standard","cacheHint":True,}
[docs]defread(self)->pd.DataFrame:"""Reads data from source."""data=request_json(self.source_url,params=self.params)df=pd.json_normalize(data,record_path=["features"]).dropna(subset=["attributes.cumulative_test"])returndf
[docs]defpipe_date(self,df:pd.DataFrame)->pd.DataFrame:"""Cleans date column"""returndf.assign(Date=clean_date_series(df["Date"],unit="ms"))
[docs]defpipeline(self,df:pd.DataFrame)->pd.DataFrame:"""pipeline for data"""return(df.pipe(self.pipe_rename_columns).pipe(self.pipe_date).pipe(self.pipe_filter).pipe(self.pipe_metadata).pipe(make_monotonic).sort_values("Date").drop_duplicates(subset=["Cumulative total"],keep="first"))
[docs]defexport(self):"""Exports data to csv"""df=self.read().pipe(self.pipeline)self.export_datafile(df,attach=True)