refactoring
This commit is contained in:
@@ -291,26 +291,6 @@
|
|||||||
" return manufacturerByBatchCodeTable.set_index('VAX_LOT')\n"
|
" return manufacturerByBatchCodeTable.set_index('VAX_LOT')\n"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": null,
|
|
||||||
"id": "09e6b511",
|
|
||||||
"metadata": {},
|
|
||||||
"outputs": [],
|
|
||||||
"source": [
|
|
||||||
"class InternationalLotTableFactory:\n",
|
|
||||||
" \n",
|
|
||||||
" def __init__(self, dataFrame : pd.DataFrame):\n",
|
|
||||||
" self.dataFrame = DataFrameFilter().filterByCovid19(dataFrame)\n",
|
|
||||||
" self.batchCodeTableByCountryFactory = BatchCodeTableByCountryFactory(dataFrame)\n",
|
|
||||||
"\n",
|
|
||||||
" def createBatchCodeTableByCountry(self, country):\n",
|
|
||||||
" return self.batchCodeTableByCountryFactory.createBatchCodeTableByCountry(country)\n",
|
|
||||||
"\n",
|
|
||||||
" def createGlobalBatchCodeTable(self):\n",
|
|
||||||
" return self.createBatchCodeTableByCountry(None)\n"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
@@ -318,12 +298,15 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"class BatchCodeTableByCountryFactory:\n",
|
"class BatchCodeTableFactory:\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def __init__(self, dataFrame : pd.DataFrame):\n",
|
" def __init__(self, dataFrame : pd.DataFrame):\n",
|
||||||
" self.dataFrame = DataFrameFilter().filterByCovid19(dataFrame)\n",
|
" self.dataFrame = DataFrameFilter().filterByCovid19(dataFrame)\n",
|
||||||
" self.countryBatchCodeTable = None\n",
|
" self.countryBatchCodeTable = None\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
" def createGlobalBatchCodeTable(self):\n",
|
||||||
|
" return self.createBatchCodeTableByCountry(None)\n",
|
||||||
|
"\n",
|
||||||
" def createBatchCodeTableByCountry(self, country):\n",
|
" def createBatchCodeTableByCountry(self, country):\n",
|
||||||
" batchCodeTable = self._createBatchCodeTableByCountry(country)\n",
|
" batchCodeTable = self._createBatchCodeTableByCountry(country)\n",
|
||||||
" batchCodeTable = CompanyColumnAdder.addCompanyColumn(batchCodeTable, CompanyColumnAdder.createCompanyByBatchCodeTable(self.dataFrame))\n",
|
" batchCodeTable = CompanyColumnAdder.addCompanyColumn(batchCodeTable, CompanyColumnAdder.createCompanyByBatchCodeTable(self.dataFrame))\n",
|
||||||
@@ -555,7 +538,7 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"from pandas.testing import assert_frame_equal\n",
|
"from pandas.testing import assert_frame_equal\n",
|
||||||
"\n",
|
"\n",
|
||||||
"class InternationalLotTableFactoryTest(unittest.TestCase):\n",
|
"class BatchCodeTableFactoryTest(unittest.TestCase):\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def test_createBatchCodeTableByCountry(self):\n",
|
" def test_createBatchCodeTableByCountry(self):\n",
|
||||||
" # Given\n",
|
" # Given\n",
|
||||||
@@ -571,10 +554,10 @@
|
|||||||
" \"4711\",\n",
|
" \"4711\",\n",
|
||||||
" \"0815\"])\n",
|
" \"0815\"])\n",
|
||||||
" dataFrame = SevereColumnAdder.addSevereColumn(dataFrame)\n",
|
" dataFrame = SevereColumnAdder.addSevereColumn(dataFrame)\n",
|
||||||
" internationalLotTableFactory = InternationalLotTableFactory(dataFrame)\n",
|
" batchCodeTableFactory = BatchCodeTableFactory(dataFrame)\n",
|
||||||
" \n",
|
" \n",
|
||||||
" # When\n",
|
" # When\n",
|
||||||
" batchCodeTable = internationalLotTableFactory.createBatchCodeTableByCountry('France')\n",
|
" batchCodeTable = batchCodeTableFactory.createBatchCodeTableByCountry('France')\n",
|
||||||
"\n",
|
"\n",
|
||||||
" # Then\n",
|
" # Then\n",
|
||||||
" assert_frame_equal(\n",
|
" assert_frame_equal(\n",
|
||||||
@@ -605,10 +588,10 @@
|
|||||||
" \"4711\",\n",
|
" \"4711\",\n",
|
||||||
" \"0815\"])\n",
|
" \"0815\"])\n",
|
||||||
" dataFrame = SevereColumnAdder.addSevereColumn(dataFrame)\n",
|
" dataFrame = SevereColumnAdder.addSevereColumn(dataFrame)\n",
|
||||||
" internationalLotTableFactory = InternationalLotTableFactory(dataFrame)\n",
|
" batchCodeTableFactory = BatchCodeTableFactory(dataFrame)\n",
|
||||||
" \n",
|
" \n",
|
||||||
" # When\n",
|
" # When\n",
|
||||||
" batchCodeTable = internationalLotTableFactory.createGlobalBatchCodeTable()\n",
|
" batchCodeTable = batchCodeTableFactory.createGlobalBatchCodeTable()\n",
|
||||||
"\n",
|
"\n",
|
||||||
" # Then\n",
|
" # Then\n",
|
||||||
" assert_frame_equal(\n",
|
" assert_frame_equal(\n",
|
||||||
@@ -641,10 +624,10 @@
|
|||||||
" \"4711\",\n",
|
" \"4711\",\n",
|
||||||
" \"0815\"])\n",
|
" \"0815\"])\n",
|
||||||
" dataFrame = SevereColumnAdder.addSevereColumn(dataFrame)\n",
|
" dataFrame = SevereColumnAdder.addSevereColumn(dataFrame)\n",
|
||||||
" internationalLotTableFactory = InternationalLotTableFactory(dataFrame)\n",
|
" batchCodeTableFactory = BatchCodeTableFactory(dataFrame)\n",
|
||||||
" \n",
|
" \n",
|
||||||
" # When\n",
|
" # When\n",
|
||||||
" batchCodeTable = internationalLotTableFactory.createBatchCodeTableByCountry('non existing country')\n",
|
" batchCodeTable = batchCodeTableFactory.createBatchCodeTableByCountry('non existing country')\n",
|
||||||
"\n",
|
"\n",
|
||||||
" # Then\n",
|
" # Then\n",
|
||||||
" assert_frame_equal(\n",
|
" assert_frame_equal(\n",
|
||||||
@@ -748,7 +731,8 @@
|
|||||||
" if minADRsForLethality is not None:\n",
|
" if minADRsForLethality is not None:\n",
|
||||||
" batchCodeTable.loc[batchCodeTable['Adverse Reaction Reports'] < minADRsForLethality, ['Severe reports', 'Lethality']] = [np.nan, np.nan]\n",
|
" batchCodeTable.loc[batchCodeTable['Adverse Reaction Reports'] < minADRsForLethality, ['Severe reports', 'Lethality']] = [np.nan, np.nan]\n",
|
||||||
" IOUtils.saveDataFrame(batchCodeTable, '../docs/data/' + country)\n",
|
" IOUtils.saveDataFrame(batchCodeTable, '../docs/data/' + country)\n",
|
||||||
" display(country + \":\", batchCodeTable)\n",
|
" # display(country + \":\", batchCodeTable)\n",
|
||||||
|
" display(country)\n",
|
||||||
"\n",
|
"\n",
|
||||||
"def createAndSaveBatchCodeTablesForCountries(createBatchCodeTableForCountry, countries, minADRsForLethality = None):\n",
|
"def createAndSaveBatchCodeTablesForCountries(createBatchCodeTableForCountry, countries, minADRsForLethality = None):\n",
|
||||||
" for country in countries:\n",
|
" for country in countries:\n",
|
||||||
@@ -789,17 +773,17 @@
|
|||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"minADRsForLethality = 100\n",
|
"minADRsForLethality = 100\n",
|
||||||
"internationalLotTableFactory = InternationalLotTableFactory(internationalVaers)\n",
|
"batchCodeTableFactory = BatchCodeTableFactory(internationalVaers)\n",
|
||||||
"\n",
|
"\n",
|
||||||
"createAndSaveBatchCodeTablesForCountries(\n",
|
"createAndSaveBatchCodeTablesForCountries(\n",
|
||||||
" createBatchCodeTableForCountry = lambda country: internationalLotTableFactory.createBatchCodeTableByCountry(country),\n",
|
" createBatchCodeTableForCountry = lambda country: batchCodeTableFactory.createBatchCodeTableByCountry(country),\n",
|
||||||
" countries = countries,\n",
|
" countries = countries,\n",
|
||||||
" minADRsForLethality = minADRsForLethality)\n",
|
" minADRsForLethality = minADRsForLethality)\n",
|
||||||
"\n",
|
"\n",
|
||||||
"createAndSaveBatchCodeTableForCountry(\n",
|
"createAndSaveBatchCodeTableForCountry(\n",
|
||||||
" createBatchCodeTableForCountry = lambda country: internationalLotTableFactory.createGlobalBatchCodeTable(),\n",
|
" createBatchCodeTableForCountry = lambda country: batchCodeTableFactory.createGlobalBatchCodeTable(),\n",
|
||||||
" country = 'Global',\n",
|
" country = 'Global',\n",
|
||||||
" minADRsForLethality = minADRsForLethality)\n"
|
" minADRsForLethality = minADRsForLethality)"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in New Issue
Block a user