refactoring

This commit is contained in:
Frank Knoll
2024-07-12 10:15:51 +02:00
parent 1e12fd8719
commit d8b23880e2
5 changed files with 69 additions and 184 deletions

View File

@@ -10,8 +10,8 @@ class PageInitializer {
PageInitializer.#initializeSelectElement(
{
selectElement: symptomSelectElement,
onValueSelected: symptom => prrByVaccineTableView.displayPrrByVaccineTable4Symptom(symptom),
minimumInputLength: 4
onValueSelected: (id, text) => prrByVaccineTableView.displayPrrByVaccineTable4Symptom(id, text),
minimumInputLength: 0
});
}
@@ -20,7 +20,7 @@ class PageInitializer {
PageInitializer.#initializeSelectElement(
{
selectElement: vaccineSelectElement,
onValueSelected: vaccine => prrBySymptomTableView.displayPrrBySymptomTable4Vaccine(vaccine),
onValueSelected: (id, text) => prrBySymptomTableView.displayPrrBySymptomTable4Vaccine(id ,text),
minimumInputLength: 0
});
}
@@ -30,8 +30,9 @@ class PageInitializer {
selectElement.on(
'select2:select',
function (event) {
const value = event.params.data.id;
onValueSelected(value);
const id = event.params.data.id;
const text = event.params.data.text;
onValueSelected(id, text);
});
}
}

View File

@@ -2,7 +2,7 @@ class PrrByKeyTableView {
#prrByKeyTable;
#downloadPrrByKeyTableButton;
#value;
#text;
#valueName;
#prrByKeyProvider;
@@ -14,11 +14,11 @@ class PrrByKeyTableView {
this.#prrByKeyProvider = prrByKeyProvider;
}
displayPrrByKeyTable4Value(value) {
displayPrrByKeyTable4Value(id, text) {
UIUtils.disableButton(this.#downloadPrrByKeyTableButton);
this.#prrByKeyProvider(value)
this.#prrByKeyProvider(id)
.then(prrByKey => {
this.#value = value;
this.#text = text;
this.#prrByKeyTable.display(prrByKey);
UIUtils.enableButton(this.#downloadPrrByKeyTableButton);
});
@@ -36,9 +36,8 @@ class PrrByKeyTableView {
UIUtils.downloadUrlAsFilename(
window.URL.createObjectURL(
new Blob(
[this.#prrByKeyTable.getDisplayedTableAsCsv(`# ${this.#valueName}: ${this.#value}`)],
[this.#prrByKeyTable.getDisplayedTableAsCsv(`# ${this.#valueName}: ${this.#text}`)],
{ type: 'text/csv' })),
this.#value
);
this.#text);
}
}

View File

@@ -10,8 +10,8 @@ class PrrBySymptomTableView {
PrrByVaccineProvider.getPrrBySymptom);
}
displayPrrBySymptomTable4Vaccine(vaccine) {
this.#delegate.displayPrrByKeyTable4Value(vaccine);
displayPrrBySymptomTable4Vaccine(id, text) {
this.#delegate.displayPrrByKeyTable4Value(id, text);
}
#createPrrBySymptomTable(tableElement) {

View File

@@ -10,8 +10,8 @@ class PrrByVaccineTableView {
PrrByVaccineProvider.getPrrByVaccine);
}
displayPrrByVaccineTable4Symptom(symptom) {
this.#delegate.displayPrrByKeyTable4Value(symptom);
displayPrrByVaccineTable4Symptom(id, text) {
this.#delegate.displayPrrByKeyTable4Value(id, text);
}
#createPrrByVaccineTable(tableElement) {

View File

@@ -467,44 +467,11 @@
{
"cell_type": "code",
"execution_count": null,
"id": "4ad05656",
"metadata": {},
"outputs": [],
"source": [
"prrByVaccineAndSymptom = pd.read_csv(\n",
" 'data/prrByDrugAndSymptom-EudraVigilance.csv',\n",
" index_col = 'DRUG')\n",
"prrByVaccineAndSymptom"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7aed1621",
"metadata": {},
"outputs": [],
"source": [
"prrByVaccineAndSymptom = DataFrameFilter.withoutZeroRowsAndZeroColumns(prrByVaccineAndSymptom)\n",
"prrByVaccineAndSymptom"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b41b60c7",
"metadata": {},
"outputs": [],
"source": [
"webAppBaseDir = os.getcwd() + '/../docs/SymptomsCausedByDrugs'"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "26f72e75",
"id": "f38924ec",
"metadata": {},
"outputs": [],
"source": [
"def saveProportionalReportingRatios4PrrByVaccineBySymptomWithoutZeroPrrs(prrByVaccineAndSymptom, webAppBaseDir):\n",
" prrByVaccineBySymptom = PrrSeriesFactory.getPrrByVaccineBySymptom(prrByVaccineAndSymptom)\n",
"\n",
" prrByVaccineBySymptomWithoutZeroPrrs = PrrSeriesTransformer.filterByNonZeroPrrs(prrByVaccineBySymptom)\n",
@@ -516,16 +483,18 @@
" directory = os.path.normpath(webAppBaseDir + '/data/ProportionalReportingRatios/symptoms'))\n",
"\n",
" del prrByVaccineBySymptomWithoutZeroPrrs\n",
"gc.collect()"
" gc.collect()\n",
" return filenameBySymptom"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5bfdcbdd",
"id": "e1237c0b",
"metadata": {},
"outputs": [],
"source": [
"def saveProportionalReportingRatios4PrrBySymptomByVaccineWithHighPrrs(prrByVaccineAndSymptom, webAppBaseDir):\n",
" prrBySymptomByVaccine = PrrSeriesFactory.getPrrBySymptomByVaccine(prrByVaccineAndSymptom)\n",
" prrBySymptomByVaccineWithHighPrrs = PrrSeriesTransformer.filterPrrs(prrBySymptomByVaccine, lambda prr: prr >= 2)\n",
" del prrBySymptomByVaccine\n",
@@ -536,16 +505,21 @@
" directory = os.path.normpath(webAppBaseDir + '/data/ProportionalReportingRatios/vaccines'))\n",
"\n",
" del prrBySymptomByVaccineWithHighPrrs\n",
"gc.collect()"
" gc.collect()\n",
" return filenameByDrug"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cc97b8d4",
"id": "64ccf3c9",
"metadata": {},
"outputs": [],
"source": [
"def saveProportionalReportingRatiosAndUpdateHtmlFile(prrByVaccineAndSymptom, webAppBaseDir):\n",
" prrByVaccineAndSymptom = DataFrameFilter.withoutZeroRowsAndZeroColumns(prrByVaccineAndSymptom)\n",
" filenameBySymptom = saveProportionalReportingRatios4PrrByVaccineBySymptomWithoutZeroPrrs(prrByVaccineAndSymptom, webAppBaseDir)\n",
" filenameByDrug = saveProportionalReportingRatios4PrrBySymptomByVaccineWithHighPrrs(prrByVaccineAndSymptom, webAppBaseDir)\n",
" updateHtmlFile(\n",
" symptomsDescr = {\n",
" 'symptoms': list(prrByVaccineAndSymptom.columns),\n",
@@ -553,7 +527,21 @@
" vaccinesDescr = {\n",
" 'vaccines': list(prrByVaccineAndSymptom.index),\n",
" 'filenameByDrug': filenameByDrug },\n",
" htmlFile = os.path.normpath(webAppBaseDir + '/index.html'))"
" htmlFile = os.path.normpath(webAppBaseDir + '/index.html'))\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3db1a115",
"metadata": {},
"outputs": [],
"source": [
"saveProportionalReportingRatiosAndUpdateHtmlFile(\n",
" prrByVaccineAndSymptom = pd.read_csv(\n",
" 'data/prrByDrugAndSymptom-EudraVigilance-10.csv',\n",
" index_col = 'DRUG'),\n",
" webAppBaseDir = os.getcwd() + '/../docs/SymptomsCausedByDrugs')"
]
},
{
@@ -567,22 +555,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "5cd9935f",
"metadata": {},
"outputs": [],
"source": [
"from SymptomsCausedByVaccines.DataFrameFilter import DataFrameFilter\n",
"from SymptomsCausedByVaccines.HtmlUpdater import updateHtmlFile, updateHtmlFile4SymptomsCausedByCOVIDLots\n",
"from SymptomsCausedByVaccines.PrrSeriesFactory import PrrSeriesFactory\n",
"from SymptomsCausedByVaccines.PrrSeriesTransformer import PrrSeriesTransformer\n",
"from SymptomsCausedByVaccines.ProportionalReportingRatiosPersister import saveProportionalReportingRatios\n",
"import os\n",
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0974c307",
"metadata": {},
"outputs": [],
"source": [
@@ -597,101 +570,13 @@
{
"cell_type": "code",
"execution_count": null,
"id": "dfa98cd9",
"metadata": {},
"outputs": [],
"source": [
"prrByVaccineAndSymptom = DataFrameFilter.withoutZeroRowsAndZeroColumns(prrByVaccineAndSymptom)\n",
"prrByVaccineAndSymptom"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "640868c7",
"metadata": {},
"outputs": [],
"source": [
"prrByVaccineBySymptom = PrrSeriesFactory.getPrrByVaccineBySymptom(prrByVaccineAndSymptom)\n",
"prrByVaccineBySymptom"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0f247c64",
"metadata": {},
"outputs": [],
"source": [
"prrBySymptomByVaccine = PrrSeriesFactory.getPrrBySymptomByVaccine(prrByVaccineAndSymptom)\n",
"prrBySymptomByVaccine"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "760ac423",
"metadata": {},
"outputs": [],
"source": [
"prrByVaccineBySymptomWithoutZeroPrrs = PrrSeriesTransformer.filterByNonZeroPrrs(prrByVaccineBySymptom)\n",
"prrByVaccineBySymptomWithoutZeroPrrs"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f07203e4",
"metadata": {},
"outputs": [],
"source": [
"prrBySymptomByVaccineWithHighPrrs = PrrSeriesTransformer.filterPrrs(prrBySymptomByVaccine, lambda prr: prr >= 2)\n",
"prrBySymptomByVaccineWithHighPrrs"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"webAppBaseDir = os.getcwd() + '/../docs/SymptomsCausedByVaccines'"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0b40071c",
"metadata": {},
"outputs": [],
"source": [
"saveProportionalReportingRatios(\n",
" prrByVaccineBySymptomWithoutZeroPrrs,\n",
" directory = os.path.normpath(webAppBaseDir + '/data/ProportionalReportingRatios/symptoms'))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fac4b34f",
"metadata": {},
"outputs": [],
"source": [
"saveProportionalReportingRatios(\n",
" prrBySymptomByVaccineWithHighPrrs,\n",
" directory = os.path.normpath(webAppBaseDir + '/data/ProportionalReportingRatios/vaccines'))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "803dfbef",
"metadata": {},
"outputs": [],
"source": [
"updateHtmlFile(\n",
" symptoms = list(prrByVaccineAndSymptom.columns),\n",
" vaccines = list(prrByVaccineAndSymptom.index),\n",
" htmlFile = os.path.normpath(webAppBaseDir + '/index.html'))"
"saveProportionalReportingRatiosAndUpdateHtmlFile(\n",
" prrByVaccineAndSymptom = prrByVaccineAndSymptom,\n",
" webAppBaseDir = os.getcwd() + '/../docs/SymptomsCausedByVaccines')"
]
},
{