Files
HowBadIsMyBatch/src/BatchCodeTableFactory.py
frankknoll e87fe0c8ba refactoring
2022-11-22 12:40:26 +01:00

46 lines
1.7 KiB
Python

import pandas as pd
from CompanyColumnAdder import CompanyColumnAdder
from SummationTableFactory import SummationTableFactory
class BatchCodeTableFactory:
def __init__(self, dataFrame: pd.DataFrame):
self.dataFrame = dataFrame
self.companyColumnAdder = CompanyColumnAdder(dataFrame)
self.countryBatchCodeTable = SummationTableFactory.createSummationTable(
dataFrame.groupby(
[
dataFrame['COUNTRY'],
dataFrame['VAX_LOT']
]))
def createGlobalBatchCodeTable(self):
return self._postProcess(SummationTableFactory.createSummationTable(self.dataFrame.groupby('VAX_LOT')))
def createBatchCodeTableByCountry(self, country):
return self._postProcess(self._getBatchCodeTableByCountry(country))
def _postProcess(self, batchCodeTable):
batchCodeTable = self.companyColumnAdder.addCompanyColumn(batchCodeTable)
batchCodeTable = batchCodeTable[
[
'Adverse Reaction Reports',
'Deaths',
'Disabilities',
'Life Threatening Illnesses',
'Company',
'Countries',
'Severe reports',
'Lethality'
]]
return batchCodeTable.sort_values(by = 'Severe reports', ascending = False)
def _getBatchCodeTableByCountry(self, country):
if country in self.countryBatchCodeTable.index:
return self.countryBatchCodeTable.loc[country]
else:
return self._getEmptyBatchCodeTable()
def _getEmptyBatchCodeTable(self):
return self.countryBatchCodeTable[0:0].droplevel(0)