From e2bc81bce103e0b91b941fbea29ec08e0edc2075 Mon Sep 17 00:00:00 2001 From: frankknoll Date: Sun, 20 Feb 2022 21:04:01 +0100 Subject: [PATCH] refactoring --- src/HowBadIsMyBatch.ipynb | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/HowBadIsMyBatch.ipynb b/src/HowBadIsMyBatch.ipynb index 7d3b52ab564..857adf65d2e 100644 --- a/src/HowBadIsMyBatch.ipynb +++ b/src/HowBadIsMyBatch.ipynb @@ -1464,8 +1464,8 @@ "metadata": {}, "outputs": [], "source": [ - "def createAndSaveAndDisplayBatchCodeTableByCountry(internationalLotTableFactory, country, minADRsForLethality = None):\n", - " batchCodeTable = internationalLotTableFactory.createBatchCodeTableByCountry(country)\n", + "def createAndSaveAndDisplayBatchCodeTableByCountry(createBatchCodeTable, country, minADRsForLethality = None):\n", + " batchCodeTable = createBatchCodeTable(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", @@ -1475,7 +1475,7 @@ "def createAndSaveAndDisplayBatchCodeTablesByCountry(vaers, countries, minADRsForLethality = None):\n", " internationalLotTableFactory = InternationalLotTableFactory(vaers)\n", " for country in countries:\n", - " createAndSaveAndDisplayBatchCodeTableByCountry(internationalLotTableFactory, country, minADRsForLethality)" + " createAndSaveAndDisplayBatchCodeTableByCountry(lambda country: internationalLotTableFactory.createBatchCodeTableByCountry(country), country, minADRsForLethality)" ] }, { @@ -1533,8 +1533,8 @@ "metadata": {}, "outputs": [], "source": [ - "internationalLotTableFactory = InternationalLotTableFactory(internationalVaers)\n", - "globalBatchCodeTable = internationalLotTableFactory.createGlobalBatchCodeTable()" + "globalBatchCodeTable = InternationalLotTableFactory(internationalVaers).createGlobalBatchCodeTable()\n", + "globalBatchCodeTable" ] }, { @@ -1544,13 +1544,10 @@ "metadata": {}, "outputs": [], "source": [ - " # FK-TODO: DRY with createAndSaveAndDisplayBatchCodeTableByCountry()\n", - " minADRsForLethality = 100\n", - " globalBatchCodeTable.index.set_names(\"Batch\", inplace = True)\n", - " if minADRsForLethality is not None:\n", - " globalBatchCodeTable.loc[globalBatchCodeTable['Adverse Reaction Reports'] < minADRsForLethality, ['Severe reports', 'Lethality']] = [np.nan, np.nan]\n", - " IOUtils.saveDataFrame(globalBatchCodeTable, '../docs/data/Global')\n", - " display('Global' + \":\", globalBatchCodeTable)\n" + "createAndSaveAndDisplayBatchCodeTableByCountry(\n", + " createBatchCodeTable = lambda country: globalBatchCodeTable,\n", + " country = 'Global',\n", + " minADRsForLethality = 100)\n" ] }, {