refactoring

This commit is contained in:
frankknoll
2023-04-03 00:03:36 +02:00
parent a029614802
commit a5b95c9318

View File

@@ -6,13 +6,6 @@ class BatchCodeTableFactory:
def __init__(self, dataFrame: pd.DataFrame): def __init__(self, dataFrame: pd.DataFrame):
self.dataFrame = dataFrame self.dataFrame = dataFrame
self.companyColumnAdder = CompanyColumnAdder(dataFrame)
self.countryBatchCodeTable = SummationTableFactory.createSummationTable(
dataFrame.groupby(
[
dataFrame['COUNTRY'],
dataFrame['VAX_LOT']
]))
def createGlobalBatchCodeTable(self): def createGlobalBatchCodeTable(self):
return self._postProcess(SummationTableFactory.createSummationTable(self.dataFrame.groupby('VAX_LOT'))) return self._postProcess(SummationTableFactory.createSummationTable(self.dataFrame.groupby('VAX_LOT')))
@@ -21,7 +14,7 @@ class BatchCodeTableFactory:
return self._postProcess(self._getBatchCodeTableByCountry(country)) return self._postProcess(self._getBatchCodeTableByCountry(country))
def _postProcess(self, batchCodeTable): def _postProcess(self, batchCodeTable):
batchCodeTable = self.companyColumnAdder.addCompanyColumn(batchCodeTable) batchCodeTable = CompanyColumnAdder(self.dataFrame).addCompanyColumn(batchCodeTable)
batchCodeTable = batchCodeTable[ batchCodeTable = batchCodeTable[
[ [
'Adverse Reaction Reports', 'Adverse Reaction Reports',
@@ -35,10 +28,19 @@ class BatchCodeTableFactory:
return batchCodeTable.sort_values(by = 'Severe reports', ascending = False) return batchCodeTable.sort_values(by = 'Severe reports', ascending = False)
def _getBatchCodeTableByCountry(self, country): def _getBatchCodeTableByCountry(self, country):
if country in self.countryBatchCodeTable.index: countryBatchCodeTable = self._getCountryBatchCodeTable()
return self.countryBatchCodeTable.loc[country] if country in countryBatchCodeTable.index:
return countryBatchCodeTable.loc[country]
else: else:
return self._getEmptyBatchCodeTable() return self._getEmptyBatchCodeTable(countryBatchCodeTable)
def _getEmptyBatchCodeTable(self): def _getCountryBatchCodeTable(self):
return self.countryBatchCodeTable[0:0].droplevel(0) return SummationTableFactory.createSummationTable(
self.dataFrame.groupby(
[
self.dataFrame['COUNTRY'],
self.dataFrame['VAX_LOT']
]))
def _getEmptyBatchCodeTable(self, countryBatchCodeTable):
return countryBatchCodeTable[0:0].droplevel(0)