updating html file with vaccines from table

This commit is contained in:
frankknoll
2023-10-10 10:30:26 +02:00
parent e457568ef6
commit 16b5d7a57f
4 changed files with 215 additions and 17 deletions

View File

@@ -205,18 +205,6 @@
"countryCountsByBatchcode"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0d755bc8",
"metadata": {},
"outputs": [],
"source": [
"# df = countryCountsByBatchcode.loc[(slice(None), 'Germany'), :][['COUNTRY_COUNT_BY_VAX_LOT Clicked']].sort_values(by = 'COUNTRY_COUNT_BY_VAX_LOT Clicked', ascending = False)\n",
"symptomByVaccineInPercent = countryCountsByBatchcode.loc[(slice(None), 'Germany'), :].sort_values(by = 'COUNTRY_COUNT_BY_VAX_LOT Clicked', ascending = False)\n",
"symptomByVaccineInPercent"
]
},
{
"cell_type": "code",
"execution_count": null,
@@ -437,6 +425,17 @@
"# Symptoms caused by Vaccines\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5cd9935f",
"metadata": {},
"outputs": [],
"source": [
"from SymptomsCausedByVaccines.HtmlUpdater import updateHtmlFile\n",
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": null,
@@ -444,13 +443,11 @@
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"\n",
"symptomByVaccineInPercent = pd.read_csv(\n",
"symptomByVaccine = pd.read_csv(\n",
" 'data/ratings-1990-2022.csv',\n",
" index_col = 'VAX_TYPE',\n",
" usecols = lambda columnName: columnName != 'Unnamed: 0')\n",
"symptomByVaccineInPercent"
"symptomByVaccine"
]
},
{
@@ -460,7 +457,20 @@
"metadata": {},
"outputs": [],
"source": [
"symptomByVaccineInPercent.loc['COVID19'].sum()"
"symptomByVaccine.loc['COVID19'].sum()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "803dfbef",
"metadata": {},
"outputs": [],
"source": [
"updateHtmlFile(\n",
" symptomByVaccine,\n",
" htmlFile = \"../docs/SymptomsCausedByVaccines/index.html\",\n",
" lastUpdated = dateProvider.getLastUpdatedDataSource())"
]
}
],

View File

@@ -0,0 +1,34 @@
from bs4 import BeautifulSoup
from HtmlTransformerUtil import HtmlTransformerUtil
from DateProvider import DateProvider
from SymptomsCausedByVaccines.Analyzer import Analyzer
from SymptomsCausedByVaccines.HtmlUtils import getVaccineOptions
from SymptomsCausedByVaccines.OptionsSetter import OptionsSetter
def updateHtmlFile(symptomByVaccine, htmlFile, lastUpdated):
vaccineOptions = getVaccineOptions(Analyzer(symptomByVaccine).getVaccines())
_saveVaccineOptions(vaccineOptions, htmlFile)
saveLastUpdated2HtmlFile(lastUpdated, htmlFile)
def _saveVaccineOptions(vaccineOptions, htmlFile):
HtmlTransformerUtil().applySoupTransformerToFile(
file=htmlFile,
soupTransformer = lambda soup:
BeautifulSoup(
OptionsSetter().setOptions(
html = str(soup),
selectElementId = 'vaccineSelect',
options = vaccineOptions),
'lxml'))
# FK-TODO: DRY with src/BatchCodeTableHtmlUpdater.py
def saveLastUpdated2HtmlFile(lastUpdated, htmlFile):
def setLastUpdated(soup):
soup.find(id="last_updated").string.replace_with(
lastUpdated.strftime(DateProvider.DATE_FORMAT))
return soup
HtmlTransformerUtil().applySoupTransformerToFile(
file = htmlFile,
soupTransformer = setLastUpdated)

View File

@@ -0,0 +1,10 @@
def getVaccineOptions(vaccines):
return ['<option hidden disabled selected value>Select Vaccine</option>'] + _getVaccineOptions(vaccines)
def _getVaccineOptions(vaccines):
return [_getVaccineOption(vaccine) for vaccine in vaccines]
def _getVaccineOption(vaccine):
return '<option value="{vaccine}">{vaccine}</option>'.format(vaccine=vaccine)