adding method SymptomHistogramByBatchcodeTableFactory.createGlobalSymptomHistogramByBatchcodeTable()

This commit is contained in:
frankknoll
2023-02-10 09:52:39 +01:00
parent 41524ed839
commit 206b2a6649
2 changed files with 34 additions and 0 deletions

View File

@@ -8,3 +8,10 @@ class SymptomHistogramByBatchcodeTableFactory:
.to_frame(name = 'SYMPTOM_COUNT_BY_VAX_LOT') .to_frame(name = 'SYMPTOM_COUNT_BY_VAX_LOT')
.reset_index(level = 'COUNTRY') .reset_index(level = 'COUNTRY')
[['SYMPTOM_COUNT_BY_VAX_LOT', 'COUNTRY']]) [['SYMPTOM_COUNT_BY_VAX_LOT', 'COUNTRY']])
@staticmethod
def createGlobalSymptomHistogramByBatchcodeTable(symptomByBatchcodeTable):
return (symptomByBatchcodeTable
.groupby(symptomByBatchcodeTable.index.names)
['SYMPTOM'].value_counts()
.to_frame(name = 'SYMPTOM_COUNT_BY_VAX_LOT'))

View File

@@ -62,3 +62,30 @@ class SymptomHistogramByBatchcodeTableFactoryTest(unittest.TestCase):
tuples = [['1808982', 'EW0175', 'Blood pressure orthostatic abnormal'], tuples = [['1808982', 'EW0175', 'Blood pressure orthostatic abnormal'],
['1808982', 'EW0175', 'Headache'], ['1808982', 'EW0175', 'Headache'],
['1808982', 'EW0175', 'Blood pressure orthostatic abnormal']]))) ['1808982', 'EW0175', 'Blood pressure orthostatic abnormal']])))
def test_createGlobalSymptomHistogramByBatchcodeTable(self):
# Given
symptomByBatchcodeTable = TestHelper.createDataFrame(
columns = ['SYMPTOM', 'COUNTRY'],
data = [ ['Blood pressure orthostatic abnormal', 'Germany'],
['Blood pressure orthostatic abnormal', 'Germany'],
['Blood pressure orthostatic abnormal', 'Russian Federation'],
['Headache', 'Germany']],
index = pd.MultiIndex.from_tuples(
names = ['VAX_LOT1', 'VAX_LOT2'],
tuples = [['1808982', 'EW0175']] * 4))
# When
globalSymptomHistogramByBatchcodeTable = SymptomHistogramByBatchcodeTableFactory.createGlobalSymptomHistogramByBatchcodeTable(symptomByBatchcodeTable)
# Then
assert_frame_equal(
globalSymptomHistogramByBatchcodeTable,
TestHelper.createDataFrame(
columns = ['SYMPTOM_COUNT_BY_VAX_LOT'],
data = [ [3],
[1]],
index = pd.MultiIndex.from_tuples(
names = ['VAX_LOT1', 'VAX_LOT2', 'SYMPTOM'],
tuples = [['1808982', 'EW0175', 'Blood pressure orthostatic abnormal'],
['1808982', 'EW0175', 'Headache']])))