refactoring

This commit is contained in:
frankknoll
2022-02-21 13:55:08 +01:00
parent abb65f214c
commit 31963fa40b

View File

@@ -283,14 +283,23 @@
"\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",
@@ -303,31 +312,14 @@
" ]]\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",
" "
] ]
}, },
{ {