refactoring
This commit is contained in:
@@ -2,6 +2,17 @@ from bs4 import BeautifulSoup
|
||||
from HtmlTransformerUtil import HtmlTransformerUtil
|
||||
from CountryOptionsSetter import CountryOptionsSetter
|
||||
from DateProvider import DateProvider
|
||||
from HtmlUtils import getCountryOptions, getCountries
|
||||
from DateProvider import DateProvider
|
||||
from BatchCodeTablePersister import createAndSaveBatchCodeTables
|
||||
|
||||
|
||||
def updateBatchCodeTableHtmlFile(internationalVaersCovid19):
|
||||
countryOptions = getCountryOptions(getCountries(internationalVaersCovid19))
|
||||
saveCountryOptions(countryOptions)
|
||||
saveLastUpdatedBatchCodeTable(DateProvider().getLastUpdatedDataSource())
|
||||
createAndSaveBatchCodeTables(internationalVaersCovid19, minADRsForLethality=100)
|
||||
|
||||
|
||||
def saveCountryOptions(countryOptions):
|
||||
HtmlTransformerUtil().applySoupTransformerToFile(
|
||||
@@ -12,6 +23,7 @@ def saveCountryOptions(countryOptions):
|
||||
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))
|
||||
@@ -20,3 +32,4 @@ def saveLastUpdatedBatchCodeTable(lastUpdated):
|
||||
HtmlTransformerUtil().applySoupTransformerToFile(
|
||||
file = "../docs/batchCodeTable.html",
|
||||
soupTransformer = setLastUpdated)
|
||||
|
||||
@@ -1,15 +1,38 @@
|
||||
from IOUtils import IOUtils
|
||||
from BatchCodeTableFactory import BatchCodeTableFactory
|
||||
import numpy as np
|
||||
from HtmlUtils import getCountries
|
||||
|
||||
def createAndSaveBatchCodeTableForCountry(createBatchCodeTableForCountry, country, minADRsForLethality = None):
|
||||
|
||||
def createAndSaveBatchCodeTables(internationalVaersCovid19, minADRsForLethality):
|
||||
batchCodeTableFactory = BatchCodeTableFactory(internationalVaersCovid19)
|
||||
_createAndSaveBatchCodeTablesForCountries(
|
||||
createBatchCodeTableForCountry=lambda country: batchCodeTableFactory.createBatchCodeTableByCountry(
|
||||
country),
|
||||
countries=getCountries(internationalVaersCovid19),
|
||||
minADRsForLethality=minADRsForLethality)
|
||||
_createAndSaveBatchCodeTableForCountry(
|
||||
createBatchCodeTableForCountry=lambda country: batchCodeTableFactory.createGlobalBatchCodeTable(),
|
||||
country='Global',
|
||||
minADRsForLethality=minADRsForLethality)
|
||||
|
||||
|
||||
def _createAndSaveBatchCodeTableForCountry(createBatchCodeTableForCountry, country, minADRsForLethality=None):
|
||||
batchCodeTable = createBatchCodeTableForCountry(country)
|
||||
batchCodeTable.index.set_names("Batch", inplace = True)
|
||||
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)
|
||||
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):
|
||||
|
||||
def _createAndSaveBatchCodeTablesForCountries(createBatchCodeTableForCountry, countries, minADRsForLethality=None):
|
||||
for country in countries:
|
||||
createAndSaveBatchCodeTableForCountry(createBatchCodeTableForCountry, country, minADRsForLethality)
|
||||
_createAndSaveBatchCodeTableForCountry(
|
||||
createBatchCodeTableForCountry, country, minADRsForLethality)
|
||||
|
||||
@@ -103,26 +103,6 @@
|
||||
" downloadVAERSFileAndUnzip('NonDomesticVAERSData.zip', workingDirectory)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "3ebcba86",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from DataFrameFilter import DataFrameFilter"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "71456a79",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from BatchCodeTableFactory import BatchCodeTableFactory"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -130,17 +110,17 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from BatchCodeTableHtmlUpdater import saveCountryOptions, saveLastUpdatedBatchCodeTable"
|
||||
"from BatchCodeTableHtmlUpdater import updateBatchCodeTableHtmlFile"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "86e0e4f2",
|
||||
"id": "62132e68",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from VaersReader import getVaersForYears, getNonDomesticVaers"
|
||||
"from InternationalVaersCovid19Provider import getInternationalVaersCovid19"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -150,42 +130,10 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"internationalVaers = pd.concat([getVaersForYears([2020, 2021, 2022]), getNonDomesticVaers()])\n",
|
||||
"internationalVaersCovid19 = DataFrameFilter().filterByCovid19(internationalVaers)\n",
|
||||
"internationalVaersCovid19 = getInternationalVaersCovid19([2020, 2021, 2022])\n",
|
||||
"internationalVaersCovid19"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "ff259a35",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from BatchCodeTablePersister import createAndSaveBatchCodeTableForCountry, createAndSaveBatchCodeTablesForCountries"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "cc1ef82a",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from HtmlUtils import getCountryOptions"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "0c4d04fb",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"countries = sorted(internationalVaersCovid19['COUNTRY'].unique())\n",
|
||||
"countryOptions = getCountryOptions(countries)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -193,38 +141,7 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"saveCountryOptions(countryOptions)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "9c7485b5",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"saveLastUpdatedBatchCodeTable(dateProvider.getLastUpdatedDataSource())"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "7e7e01a5",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"minADRsForLethality = 100\n",
|
||||
"batchCodeTableFactory = BatchCodeTableFactory(internationalVaersCovid19)\n",
|
||||
"\n",
|
||||
"createAndSaveBatchCodeTablesForCountries(\n",
|
||||
" createBatchCodeTableForCountry = lambda country: batchCodeTableFactory.createBatchCodeTableByCountry(country),\n",
|
||||
" countries = countries,\n",
|
||||
" minADRsForLethality = minADRsForLethality)\n",
|
||||
"\n",
|
||||
"createAndSaveBatchCodeTableForCountry(\n",
|
||||
" createBatchCodeTableForCountry = lambda country: batchCodeTableFactory.createGlobalBatchCodeTable(),\n",
|
||||
" country = 'Global',\n",
|
||||
" minADRsForLethality = minADRsForLethality)"
|
||||
"updateBatchCodeTableHtmlFile(internationalVaersCovid19)"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
def getCountries(internationalVaersCovid19):
|
||||
return sorted(internationalVaersCovid19['COUNTRY'].unique())
|
||||
|
||||
|
||||
def getCountryOptions(countries):
|
||||
return ['<option value="Global" selected>Global</option>'] + _getCountryOptions(countries)
|
||||
|
||||
|
||||
8
src/InternationalVaersCovid19Provider.py
Normal file
8
src/InternationalVaersCovid19Provider.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from DataFrameFilter import DataFrameFilter
|
||||
from VaersReader import getVaersForYears, getNonDomesticVaers
|
||||
import pandas as pd
|
||||
|
||||
def getInternationalVaersCovid19(years):
|
||||
internationalVaers = pd.concat([getVaersForYears(years), getNonDomesticVaers()])
|
||||
internationalVaersCovid19 = DataFrameFilter().filterByCovid19(internationalVaers)
|
||||
return internationalVaersCovid19
|
||||
Reference in New Issue
Block a user