refining SymptomHistogramByBatchcodeTableFactoryTest
This commit is contained in:
@@ -11,5 +11,5 @@ class HistogramTable2DictTableConverter:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _histogram_to_json(histogram_with_vax_lots, vax_lot_columns):
|
def _histogram_to_json(histogram_with_vax_lots, vax_lot_columns):
|
||||||
histogram = histogram_with_vax_lots.reset_index(level = vax_lot_columns, drop=True)
|
histogram = histogram_with_vax_lots.reset_index(level = vax_lot_columns, drop = True)
|
||||||
return histogram.to_dict()
|
return histogram.to_dict()
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ class SymptomHistogramByBatchcodeTableFactory:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def createSymptomHistogramByBatchcodeTable(symptomByBatchcodeTable):
|
def createSymptomHistogramByBatchcodeTable(symptomByBatchcodeTable):
|
||||||
return (
|
return (symptomByBatchcodeTable
|
||||||
symptomByBatchcodeTable
|
.groupby(symptomByBatchcodeTable.index.names + ['COUNTRY'])
|
||||||
.groupby(symptomByBatchcodeTable.index.names)
|
|
||||||
['SYMPTOM'].value_counts()
|
['SYMPTOM'].value_counts()
|
||||||
.to_frame(name = 'SYMPTOM_COUNT_BY_VAX_LOT')
|
.to_frame(name = 'SYMPTOM_COUNT_BY_VAX_LOT')
|
||||||
)
|
.reset_index(level = 'COUNTRY')
|
||||||
|
[['SYMPTOM_COUNT_BY_VAX_LOT', 'COUNTRY']])
|
||||||
|
|||||||
@@ -9,10 +9,10 @@ class SymptomHistogramByBatchcodeTableFactoryTest(unittest.TestCase):
|
|||||||
def test_createSymptomHistogramByBatchcodeTable(self):
|
def test_createSymptomHistogramByBatchcodeTable(self):
|
||||||
# Given
|
# Given
|
||||||
symptomByBatchcodeTable = TestHelper.createDataFrame(
|
symptomByBatchcodeTable = TestHelper.createDataFrame(
|
||||||
columns = ['SYMPTOM'],
|
columns = ['SYMPTOM', 'COUNTRY'],
|
||||||
data = [ ['Blood pressure orthostatic abnormal'],
|
data = [ ['Blood pressure orthostatic abnormal', 'Germany'],
|
||||||
['Blood pressure orthostatic abnormal'],
|
['Blood pressure orthostatic abnormal', 'Germany'],
|
||||||
['Blood pressure orthostatic abnormal']],
|
['Blood pressure orthostatic abnormal', 'Germany']],
|
||||||
index = pd.Index(
|
index = pd.Index(
|
||||||
name = 'VAX_LOT1',
|
name = 'VAX_LOT1',
|
||||||
data = ['EW0175',
|
data = ['EW0175',
|
||||||
@@ -26,9 +26,9 @@ class SymptomHistogramByBatchcodeTableFactoryTest(unittest.TestCase):
|
|||||||
assert_frame_equal(
|
assert_frame_equal(
|
||||||
symptomHistogramByBatchcodeTable,
|
symptomHistogramByBatchcodeTable,
|
||||||
TestHelper.createDataFrame(
|
TestHelper.createDataFrame(
|
||||||
columns = ['SYMPTOM_COUNT_BY_VAX_LOT'],
|
columns = ['SYMPTOM_COUNT_BY_VAX_LOT', 'COUNTRY'],
|
||||||
data = [ [1],
|
data = [ [1, 'Germany'],
|
||||||
[2]],
|
[2, 'Germany']],
|
||||||
index = pd.MultiIndex.from_tuples(
|
index = pd.MultiIndex.from_tuples(
|
||||||
names = ['VAX_LOT1', 'SYMPTOM'],
|
names = ['VAX_LOT1', 'SYMPTOM'],
|
||||||
tuples = [['1808982', 'Blood pressure orthostatic abnormal'],
|
tuples = [['1808982', 'Blood pressure orthostatic abnormal'],
|
||||||
@@ -37,13 +37,14 @@ class SymptomHistogramByBatchcodeTableFactoryTest(unittest.TestCase):
|
|||||||
def test_createSymptomHistogramByBatchcodeTable_two_VAX_LOTs_Index(self):
|
def test_createSymptomHistogramByBatchcodeTable_two_VAX_LOTs_Index(self):
|
||||||
# Given
|
# Given
|
||||||
symptomByBatchcodeTable = TestHelper.createDataFrame(
|
symptomByBatchcodeTable = TestHelper.createDataFrame(
|
||||||
columns = ['SYMPTOM'],
|
columns = ['SYMPTOM', 'COUNTRY'],
|
||||||
data = [ ['Blood pressure orthostatic abnormal'],
|
data = [ ['Blood pressure orthostatic abnormal', 'Germany'],
|
||||||
['Blood pressure orthostatic abnormal'],
|
['Blood pressure orthostatic abnormal', 'Germany'],
|
||||||
['Headache']],
|
['Blood pressure orthostatic abnormal', 'Russian Federation'],
|
||||||
|
['Headache', 'Germany']],
|
||||||
index = pd.MultiIndex.from_tuples(
|
index = pd.MultiIndex.from_tuples(
|
||||||
names = ['VAX_LOT1', 'VAX_LOT2'],
|
names = ['VAX_LOT1', 'VAX_LOT2'],
|
||||||
tuples = [['1808982', 'EW0175']] * 3))
|
tuples = [['1808982', 'EW0175']] * 4))
|
||||||
|
|
||||||
# When
|
# When
|
||||||
symptomHistogramByBatchcodeTable = SymptomHistogramByBatchcodeTableFactory.createSymptomHistogramByBatchcodeTable(symptomByBatchcodeTable)
|
symptomHistogramByBatchcodeTable = SymptomHistogramByBatchcodeTableFactory.createSymptomHistogramByBatchcodeTable(symptomByBatchcodeTable)
|
||||||
@@ -52,10 +53,12 @@ class SymptomHistogramByBatchcodeTableFactoryTest(unittest.TestCase):
|
|||||||
assert_frame_equal(
|
assert_frame_equal(
|
||||||
symptomHistogramByBatchcodeTable,
|
symptomHistogramByBatchcodeTable,
|
||||||
TestHelper.createDataFrame(
|
TestHelper.createDataFrame(
|
||||||
columns = ['SYMPTOM_COUNT_BY_VAX_LOT'],
|
columns = ['SYMPTOM_COUNT_BY_VAX_LOT', 'COUNTRY'],
|
||||||
data = [ [2],
|
data = [ [2, 'Germany'],
|
||||||
[1]],
|
[1, 'Germany'],
|
||||||
|
[1, 'Russian Federation']],
|
||||||
index = pd.MultiIndex.from_tuples(
|
index = pd.MultiIndex.from_tuples(
|
||||||
names = ['VAX_LOT1', 'VAX_LOT2', 'SYMPTOM'],
|
names = ['VAX_LOT1', 'VAX_LOT2', 'SYMPTOM'],
|
||||||
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']])))
|
||||||
|
|||||||
Reference in New Issue
Block a user