refactoring

This commit is contained in:
frankknoll
2022-11-22 14:25:36 +01:00
parent e0a86efa96
commit 8d1f38dfb6
4 changed files with 51 additions and 77 deletions

View File

@@ -7,7 +7,6 @@
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"\n",
"pd.set_option('display.max_rows', 100)\n",
@@ -124,26 +123,6 @@
"from BatchCodeTableFactory import BatchCodeTableFactory"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4db36933",
"metadata": {},
"outputs": [],
"source": [
"from HtmlTransformerUtil import HtmlTransformerUtil"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "32d4eecf",
"metadata": {},
"outputs": [],
"source": [
"from CountryOptionsSetter import CountryOptionsSetter"
]
},
{
"cell_type": "code",
"execution_count": null,
@@ -151,44 +130,7 @@
"metadata": {},
"outputs": [],
"source": [
"from bs4 import BeautifulSoup\n",
"\n",
"\n",
"def saveCountryOptions(countryOptions):\n",
" HtmlTransformerUtil().applySoupTransformerToFile(\n",
" file = \"../docs/batchCodeTable.html\",\n",
" soupTransformer =\n",
" lambda soup:\n",
" BeautifulSoup(\n",
" CountryOptionsSetter().setCountryOptions(html = str(soup), options = countryOptions),\n",
" 'lxml'))\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f02dddfe",
"metadata": {},
"outputs": [],
"source": [
"def saveLastUpdatedBatchCodeTable(lastUpdated):\n",
" def setLastUpdated(soup):\n",
" soup.find(id = \"last_updated\").string.replace_with(lastUpdated.strftime(DateProvider.DATE_FORMAT))\n",
" return soup\n",
"\n",
" HtmlTransformerUtil().applySoupTransformerToFile(\n",
" file = \"../docs/batchCodeTable.html\",\n",
" soupTransformer = setLastUpdated)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6aa28541",
"metadata": {},
"outputs": [],
"source": [
"from IOUtils import IOUtils"
"from BatchCodeTableHtmlUpdater import saveCountryOptions, saveLastUpdatedBatchCodeTable"
]
},
{
@@ -220,18 +162,7 @@
"metadata": {},
"outputs": [],
"source": [
"def createAndSaveBatchCodeTableForCountry(createBatchCodeTableForCountry, country, minADRsForLethality = None):\n",
" batchCodeTable = createBatchCodeTableForCountry(country)\n",
" batchCodeTable.index.set_names(\"Batch\", inplace = True)\n",
" if minADRsForLethality is not None:\n",
" batchCodeTable.loc[batchCodeTable['Adverse Reaction Reports'] < minADRsForLethality, ['Severe reports', 'Lethality']] = [np.nan, np.nan]\n",
" IOUtils.saveDataFrame(batchCodeTable, '../docs/data/batchCodeTables/' + country)\n",
" # display(country + \":\", batchCodeTable)\n",
" display(country)\n",
"\n",
"def createAndSaveBatchCodeTablesForCountries(createBatchCodeTableForCountry, countries, minADRsForLethality = None):\n",
" for country in countries:\n",
" createAndSaveBatchCodeTableForCountry(createBatchCodeTableForCountry, country, minADRsForLethality)"
"from BatchCodeTablePersister import createAndSaveBatchCodeTableForCountry, createAndSaveBatchCodeTablesForCountries"
]
},
{
@@ -241,11 +172,7 @@
"metadata": {},
"outputs": [],
"source": [
"def getCountryOptions(countries):\n",
" return [getCountryOption(country) for country in countries]\n",
"\n",
"def getCountryOption(country):\n",
" return '<option value=\"{country}\">{country}</option>'.format(country = country)"
"from HtmlUtils import getCountryOptions"
]
},
{
@@ -256,7 +183,7 @@
"outputs": [],
"source": [
"countries = sorted(internationalVaersCovid19['COUNTRY'].unique())\n",
"countryOptions = ['<option value=\"Global\" selected>Global</option>'] + getCountryOptions(countries)"
"countryOptions = getCountryOptions(countries)\n"
]
},
{