adding method SymptomHistogramByBatchcodeTableFactory.createGlobalSymptomHistogramByBatchcodeTable()
This commit is contained in:
@@ -8,3 +8,10 @@ class SymptomHistogramByBatchcodeTableFactory:
|
||||
.to_frame(name = 'SYMPTOM_COUNT_BY_VAX_LOT')
|
||||
.reset_index(level = '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'))
|
||||
|
||||
@@ -62,3 +62,30 @@ class SymptomHistogramByBatchcodeTableFactoryTest(unittest.TestCase):
|
||||
tuples = [['1808982', 'EW0175', 'Blood pressure orthostatic abnormal'],
|
||||
['1808982', 'EW0175', 'Headache'],
|
||||
['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']])))
|
||||
|
||||
Reference in New Issue
Block a user