refactoring

This commit is contained in:
frankknoll
2022-11-22 17:24:43 +01:00
parent b463c5e01e
commit 36a5733a17
3 changed files with 24 additions and 60 deletions

View File

@@ -7,16 +7,16 @@ from DateProvider import DateProvider
from BatchCodeTablePersister import createAndSaveBatchCodeTables from BatchCodeTablePersister import createAndSaveBatchCodeTables
def updateBatchCodeTableHtmlFile(internationalVaersCovid19): def updateBatchCodeTableHtmlFile(internationalVaersCovid19, batchCodeTableHtmlFile):
countryOptions = getCountryOptions(getCountries(internationalVaersCovid19)) countryOptions = getCountryOptions(getCountries(internationalVaersCovid19))
saveCountryOptions(countryOptions) _saveCountryOptions(countryOptions, batchCodeTableHtmlFile)
saveLastUpdatedBatchCodeTable(DateProvider().getLastUpdatedDataSource()) _saveLastUpdatedBatchCodeTable(DateProvider().getLastUpdatedDataSource(), batchCodeTableHtmlFile)
createAndSaveBatchCodeTables(internationalVaersCovid19, minADRsForLethality=100) createAndSaveBatchCodeTables(internationalVaersCovid19, minADRsForLethality=100)
def saveCountryOptions(countryOptions): def _saveCountryOptions(countryOptions, batchCodeTableHtmlFile):
HtmlTransformerUtil().applySoupTransformerToFile( HtmlTransformerUtil().applySoupTransformerToFile(
file = "../docs/batchCodeTable.html", file = batchCodeTableHtmlFile,
soupTransformer = soupTransformer =
lambda soup: lambda soup:
BeautifulSoup( BeautifulSoup(
@@ -24,12 +24,12 @@ def saveCountryOptions(countryOptions):
'lxml')) 'lxml'))
def saveLastUpdatedBatchCodeTable(lastUpdated): def _saveLastUpdatedBatchCodeTable(lastUpdated, batchCodeTableHtmlFile):
def setLastUpdated(soup): def setLastUpdated(soup):
soup.find(id = "last_updated").string.replace_with(lastUpdated.strftime(DateProvider.DATE_FORMAT)) soup.find(id = "last_updated").string.replace_with(lastUpdated.strftime(DateProvider.DATE_FORMAT))
return soup return soup
HtmlTransformerUtil().applySoupTransformerToFile( HtmlTransformerUtil().applySoupTransformerToFile(
file = "../docs/batchCodeTable.html", file = batchCodeTableHtmlFile,
soupTransformer = setLastUpdated) soupTransformer = setLastUpdated)

View File

@@ -10,7 +10,13 @@
"import pandas as pd\n", "import pandas as pd\n",
"\n", "\n",
"pd.set_option('display.max_rows', 100)\n", "pd.set_option('display.max_rows', 100)\n",
"pd.set_option('display.max_columns', None)" "pd.set_option('display.max_columns', None)\n",
"\n",
"from VAERSFileDownloader import updateVAERSFiles\n",
"from datetime import datetime\n",
"from DateProvider import DateProvider\n",
"from InternationalVaersCovid19Provider import getInternationalVaersCovid19\n",
"from BatchCodeTableHtmlUpdater import updateBatchCodeTableHtmlFile"
] ]
}, },
{ {
@@ -20,9 +26,7 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"from datetime import datetime\n", "print(datetime.now().strftime(\"%d.%m.%Y, %H:%M:%S Uhr\"))\n"
"\n",
"print(datetime.now().strftime(\"%d.%m.%Y, %H:%M:%S Uhr\"))"
] ]
}, },
{ {
@@ -32,7 +36,6 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"from DateProvider import DateProvider\n",
"dateProvider = DateProvider()\n", "dateProvider = DateProvider()\n",
"print(' lastUpdated:', dateProvider.getLastUpdated())\n", "print(' lastUpdated:', dateProvider.getLastUpdated())\n",
"print('lastUpdatedDataSource:', dateProvider.getLastUpdatedDataSource()) \n", "print('lastUpdatedDataSource:', dateProvider.getLastUpdatedDataSource()) \n",
@@ -59,17 +62,7 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"pwd = getWorkingDirectory()" "getWorkingDirectory()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "501f6c7b",
"metadata": {},
"outputs": [],
"source": [
"pwd"
] ]
}, },
{ {
@@ -83,45 +76,11 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "9ccc73b3", "id": "a793dff0",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"# FK-TODO: das Modell erst dann laden, wenn es wirklich gebraucht wird\n", "updateVAERSFiles(needsUpdate, getWorkingDirectory())"
"from VAERSFileDownloader import downloadVAERSFileAndUnzip"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9a9e4d1e",
"metadata": {},
"outputs": [],
"source": [
"if needsUpdate:\n",
" workingDirectory = getWorkingDirectory()\n",
" downloadVAERSFileAndUnzip('2022VAERSData.zip', workingDirectory)\n",
" downloadVAERSFileAndUnzip('NonDomesticVAERSData.zip', workingDirectory)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2f0f9b4b",
"metadata": {},
"outputs": [],
"source": [
"from BatchCodeTableHtmlUpdater import updateBatchCodeTableHtmlFile"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "62132e68",
"metadata": {},
"outputs": [],
"source": [
"from InternationalVaersCovid19Provider import getInternationalVaersCovid19"
] ]
}, },
{ {
@@ -142,7 +101,7 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"updateBatchCodeTableHtmlFile(internationalVaersCovid19)" "updateBatchCodeTableHtmlFile(internationalVaersCovid19, batchCodeTableHtmlFile=\"../docs/batchCodeTable.html\")"
] ]
}, },
{ {

View File

@@ -55,3 +55,8 @@ def downloadVAERSFileAndUnzip(file, workingDirectory):
unzipAndRemove( unzipAndRemove(
zipFile = downloadedFile, zipFile = downloadedFile,
dstDir = workingDirectory + '/VAERS/') dstDir = workingDirectory + '/VAERS/')
def updateVAERSFiles(needsUpdate, workingDirectory):
if needsUpdate:
downloadVAERSFileAndUnzip('2022VAERSData.zip', workingDirectory)
downloadVAERSFileAndUnzip('NonDomesticVAERSData.zip', workingDirectory)