refactoring
This commit is contained in:
@@ -281,16 +281,25 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"class BatchCodeTableFactory:\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 = SummationTableFactory.createSummationTable(\n",
|
||||||
|
" self.dataFrame.groupby(\n",
|
||||||
|
" [\n",
|
||||||
|
" self.dataFrame['COUNTRY'],\n",
|
||||||
|
" self.dataFrame['VAX_LOT']\n",
|
||||||
|
" ]))\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def createGlobalBatchCodeTable(self):\n",
|
" def createGlobalBatchCodeTable(self):\n",
|
||||||
" return self.createBatchCodeTableByCountry(None)\n",
|
" return self._postProcess(SummationTableFactory.createSummationTable(self.dataFrame.groupby('VAX_LOT')))\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def createBatchCodeTableByCountry(self, country):\n",
|
" def createBatchCodeTableByCountry(self, country):\n",
|
||||||
" batchCodeTable = self._createBatchCodeTableByCountry(country)\n",
|
" return self._postProcess(self._getBatchCodeTableByCountry(country))\n",
|
||||||
" batchCodeTable = CompanyColumnAdder.addCompanyColumn(batchCodeTable, CompanyColumnAdder.createCompanyByBatchCodeTable(self.dataFrame))\n",
|
"\n",
|
||||||
|
" def _postProcess(self, batchCodeTable):\n",
|
||||||
|
" batchCodeTable = CompanyColumnAdder.addCompanyColumn(\n",
|
||||||
|
" batchCodeTable,\n",
|
||||||
|
" CompanyColumnAdder.createCompanyByBatchCodeTable(self.dataFrame))\n",
|
||||||
" batchCodeTable = batchCodeTable[\n",
|
" batchCodeTable = batchCodeTable[\n",
|
||||||
" [\n",
|
" [\n",
|
||||||
" 'Adverse Reaction Reports',\n",
|
" 'Adverse Reaction Reports',\n",
|
||||||
@@ -301,33 +310,16 @@
|
|||||||
" 'Severe reports',\n",
|
" 'Severe reports',\n",
|
||||||
" 'Lethality'\n",
|
" 'Lethality'\n",
|
||||||
" ]]\n",
|
" ]]\n",
|
||||||
" return batchCodeTable.sort_values(by = 'Severe reports', ascending = False)\n",
|
" return batchCodeTable.sort_values(by='Severe reports', ascending=False)\n",
|
||||||
"\n",
|
"\n",
|
||||||
" # FK-TODO: refactor\n",
|
" def _getBatchCodeTableByCountry(self, country):\n",
|
||||||
" def _createBatchCodeTableByCountry(self, country):\n",
|
" if country in self.countryBatchCodeTable.index:\n",
|
||||||
" if country is None:\n",
|
" return self.countryBatchCodeTable.loc[country]\n",
|
||||||
" return SummationTableFactory.createSummationTable(self.dataFrame.groupby('VAX_LOT'))\n",
|
" else:\n",
|
||||||
|
" return self._getEmptyBatchCodeTable()\n",
|
||||||
"\n",
|
"\n",
|
||||||
" if self.countryBatchCodeTable is None:\n",
|
" def _getEmptyBatchCodeTable(self):\n",
|
||||||
" self.countryBatchCodeTable = self._getCountryBatchCodeTable()\n",
|
" return self.countryBatchCodeTable[0:0].droplevel(0)\n"
|
||||||
" \n",
|
|
||||||
" return self._getCountry(self.countryBatchCodeTable, country)\n",
|
|
||||||
"\n",
|
|
||||||
" def _getCountryBatchCodeTable(self):\n",
|
|
||||||
" return SummationTableFactory.createSummationTable(\n",
|
|
||||||
" self.dataFrame.groupby(\n",
|
|
||||||
" [\n",
|
|
||||||
" self.dataFrame['COUNTRY'],\n",
|
|
||||||
" self.dataFrame['VAX_LOT']\n",
|
|
||||||
" ]))\n",
|
|
||||||
"\n",
|
|
||||||
" def _getCountry(self, countryBatchCodeTable, country):\n",
|
|
||||||
" return countryBatchCodeTable.loc[country] if country in countryBatchCodeTable.index else self._getEmptyBatchCodeTable(countryBatchCodeTable)\n",
|
|
||||||
" \n",
|
|
||||||
" def _getEmptyBatchCodeTable(self, countryBatchCodeTable):\n",
|
|
||||||
" return countryBatchCodeTable[0:0].droplevel(0)\n",
|
|
||||||
"\n",
|
|
||||||
" "
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user