refactoring
This commit is contained in:
22
src/BatchCodeTableHtmlUpdater.py
Normal file
22
src/BatchCodeTableHtmlUpdater.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from bs4 import BeautifulSoup
|
||||
from HtmlTransformerUtil import HtmlTransformerUtil
|
||||
from CountryOptionsSetter import CountryOptionsSetter
|
||||
from DateProvider import DateProvider
|
||||
|
||||
def saveCountryOptions(countryOptions):
|
||||
HtmlTransformerUtil().applySoupTransformerToFile(
|
||||
file = "../docs/batchCodeTable.html",
|
||||
soupTransformer =
|
||||
lambda soup:
|
||||
BeautifulSoup(
|
||||
CountryOptionsSetter().setCountryOptions(html = str(soup), options = countryOptions),
|
||||
'lxml'))
|
||||
|
||||
def saveLastUpdatedBatchCodeTable(lastUpdated):
|
||||
def setLastUpdated(soup):
|
||||
soup.find(id = "last_updated").string.replace_with(lastUpdated.strftime(DateProvider.DATE_FORMAT))
|
||||
return soup
|
||||
|
||||
HtmlTransformerUtil().applySoupTransformerToFile(
|
||||
file = "../docs/batchCodeTable.html",
|
||||
soupTransformer = setLastUpdated)
|
||||
15
src/BatchCodeTablePersister.py
Normal file
15
src/BatchCodeTablePersister.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from IOUtils import IOUtils
|
||||
import numpy as np
|
||||
|
||||
def createAndSaveBatchCodeTableForCountry(createBatchCodeTableForCountry, country, minADRsForLethality = None):
|
||||
batchCodeTable = createBatchCodeTableForCountry(country)
|
||||
batchCodeTable.index.set_names("Batch", inplace = True)
|
||||
if minADRsForLethality is not None:
|
||||
batchCodeTable.loc[batchCodeTable['Adverse Reaction Reports'] < minADRsForLethality, ['Severe reports', 'Lethality']] = [np.nan, np.nan]
|
||||
IOUtils.saveDataFrame(batchCodeTable, '../docs/data/batchCodeTables/' + country)
|
||||
# display(country + ":", batchCodeTable)
|
||||
display(country)
|
||||
|
||||
def createAndSaveBatchCodeTablesForCountries(createBatchCodeTableForCountry, countries, minADRsForLethality = None):
|
||||
for country in countries:
|
||||
createAndSaveBatchCodeTableForCountry(createBatchCodeTableForCountry, country, minADRsForLethality)
|
||||
@@ -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"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
10
src/HtmlUtils.py
Normal file
10
src/HtmlUtils.py
Normal file
@@ -0,0 +1,10 @@
|
||||
def getCountryOptions(countries):
|
||||
return ['<option value="Global" selected>Global</option>'] + _getCountryOptions(countries)
|
||||
|
||||
|
||||
def _getCountryOptions(countries):
|
||||
return [_getCountryOption(country) for country in countries]
|
||||
|
||||
|
||||
def _getCountryOption(country):
|
||||
return '<option value="{country}">{country}</option>'.format(country=country)
|
||||
Reference in New Issue
Block a user