refactoring

This commit is contained in:
frankknoll
2022-12-14 21:59:22 +01:00
parent 158f5d40a7
commit b8e252c480
389 changed files with 414 additions and 418 deletions

View File

@@ -33,6 +33,7 @@
"from IOUtils import IOUtils\n",
"from Datawrapper import Datawrapper\n",
"from MedianOfFreeBedsByKreisTableFactory import MedianOfFreeBedsByKreisTableFactory\n",
"from TimeseriesReader import readTimeseries\n",
"\n",
"pd.set_option('display.max_rows', 100)\n",
"pd.set_option('display.max_columns', None)\n",
@@ -90,37 +91,6 @@
"saveLastUpdatedIntensivstationen(dateProvider.getLastUpdatedDataSource())"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d021de84",
"metadata": {},
"outputs": [],
"source": [
"def readTimeseries(download = False):\n",
" timeSeriesFile = 'zeitreihe-tagesdaten.csv'\n",
" if download:\n",
" _downloadTimeseries(timeSeriesFile)\n",
"\n",
" timeseries = pd.read_csv(\n",
" timeSeriesFile,\n",
" low_memory = False,\n",
" usecols = ['date', 'bundesland', 'gemeindeschluessel', 'betten_belegt', 'betten_frei'],\n",
" parse_dates = ['date'],\n",
" date_parser = lambda dateStr: pd.to_datetime(dateStr, format = \"%Y-%m-%d\"),\n",
" dtype = {\n",
" 'gemeindeschluessel': 'string',\n",
" 'bundesland': 'string'\n",
" })\n",
" return timeseries.sort_values(by = 'date', ascending = True)\n",
"\n",
"# download https://diviexchange.blob.core.windows.net/%24web/zeitreihe-tagesdaten.csv or https://www.intensivregister.de/#/aktuelle-lage/downloads\n",
"def _downloadTimeseries(timeSeriesFile):\n",
" request.urlretrieve(\n",
" 'https://diviexchange.blob.core.windows.net/%24web/zeitreihe-tagesdaten.csv',\n",
" timeSeriesFile)\n"
]
},
{
"cell_type": "code",
"execution_count": null,

View File

@@ -0,0 +1,26 @@
import pandas as pd
from urllib import request
def readTimeseries(download = False):
timeSeriesFile = 'zeitreihe-tagesdaten.csv'
if download:
_downloadTimeseries(timeSeriesFile)
timeseries = pd.read_csv(
timeSeriesFile,
low_memory = False,
usecols = ['date', 'bundesland', 'gemeindeschluessel', 'betten_belegt', 'betten_frei'],
parse_dates = ['date'],
date_parser = lambda dateStr: pd.to_datetime(dateStr, format = "%Y-%m-%d"),
dtype = {
'gemeindeschluessel': 'string',
'bundesland': 'string'
})
return timeseries.sort_values(by = 'date', ascending = True)
# download https://diviexchange.blob.core.windows.net/%24web/zeitreihe-tagesdaten.csv or https://www.intensivregister.de/#/aktuelle-lage/downloads
def _downloadTimeseries(timeSeriesFile):
request.urlretrieve(
'https://diviexchange.blob.core.windows.net/%24web/zeitreihe-tagesdaten.csv',
timeSeriesFile)