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