diff --git a/src/HowBadIsMyBatch.ipynb b/src/HowBadIsMyBatch.ipynb index 51903cb0a4f..f92e4a1bf6e 100644 --- a/src/HowBadIsMyBatch.ipynb +++ b/src/HowBadIsMyBatch.ipynb @@ -433,6 +433,8 @@ "outputs": [], "source": [ "from SymptomsCausedByVaccines.HtmlUpdater import updateHtmlFile\n", + "from SymptomsCausedByVaccines.PrrByVaccineBySymptomFactory import PrrByVaccineBySymptomFactory\n", + "from SymptomsCausedByVaccines.PrrByVaccineBySymptomTransformer import PrrByVaccineBySymptomTransformer\n", "import pandas as pd" ] }, @@ -450,6 +452,38 @@ "prrByVaccineAndSymptom" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "640868c7", + "metadata": {}, + "outputs": [], + "source": [ + "prrByVaccineBySymptom = PrrByVaccineBySymptomFactory.getPrrByVaccineBySymptom(prrByVaccineAndSymptom)\n", + "prrByVaccineBySymptom" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "760ac423", + "metadata": {}, + "outputs": [], + "source": [ + "prrByVaccineBySymptomWithoutZeroPrrs = PrrByVaccineBySymptomTransformer.removeNonZeroPrrs(prrByVaccineBySymptom)\n", + "prrByVaccineBySymptomWithoutZeroPrrs" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d863007f", + "metadata": {}, + "outputs": [], + "source": [ + "prrByVaccineBySymptomWithoutZeroPrrs.to_excel('tmp/prrByVaccineBySymptomWithoutZeroPrrs.xlsx')" + ] + }, { "cell_type": "code", "execution_count": null, diff --git a/src/SymptomsCausedByVaccines/PrrByVaccineBySymptomTransformer.py b/src/SymptomsCausedByVaccines/PrrByVaccineBySymptomTransformer.py new file mode 100644 index 00000000000..72ab0654c43 --- /dev/null +++ b/src/SymptomsCausedByVaccines/PrrByVaccineBySymptomTransformer.py @@ -0,0 +1,6 @@ +class PrrByVaccineBySymptomTransformer: + + @staticmethod + def removeNonZeroPrrs(prrByVaccineBySymptom): + return prrByVaccineBySymptom.map( + lambda prrByVaccine: {vaccine: prr for vaccine, prr in prrByVaccine.items() if prr != 0}) diff --git a/src/SymptomsCausedByVaccines/PrrByVaccineBySymptomTransformerTest.py b/src/SymptomsCausedByVaccines/PrrByVaccineBySymptomTransformerTest.py new file mode 100644 index 00000000000..d500904acd8 --- /dev/null +++ b/src/SymptomsCausedByVaccines/PrrByVaccineBySymptomTransformerTest.py @@ -0,0 +1,26 @@ +import unittest +from pandas.testing import assert_series_equal +import pandas as pd +from SymptomsCausedByVaccines.PrrByVaccineBySymptomTransformer import PrrByVaccineBySymptomTransformer + +class PrrByVaccineBySymptomTransformerTest(unittest.TestCase): + + def test_filterByNonZeroPrrs(self): + # Given + prrByVaccineBySymptom = pd.Series( + { + '11-beta-hydroxylase deficiency': {'6VAX-F': 0.0, 'ADEN': 0.3}, + '17-hydroxyprogesterone': {'6VAX-F': 1.5, 'ADEN': 0.0} + }) + + # When + prrByVaccineBySymptomWithoutZeroPrrs = PrrByVaccineBySymptomTransformer.removeNonZeroPrrs(prrByVaccineBySymptom) + + # Then + assert_series_equal( + prrByVaccineBySymptomWithoutZeroPrrs, + pd.Series( + { + '11-beta-hydroxylase deficiency': {'ADEN': 0.3}, + '17-hydroxyprogesterone': {'6VAX-F': 1.5} + }))