adding method HistogramTable2DictTableConverter.convertGlobalHistogramTable2DictTable(globalHistogramTable)
This commit is contained in:
@@ -9,6 +9,13 @@ class HistogramTable2DictTableConverter:
|
|||||||
.reset_index(level = 'COUNTRY')
|
.reset_index(level = 'COUNTRY')
|
||||||
[['SYMPTOM_COUNT_BY_VAX_LOT', 'COUNTRY']])
|
[['SYMPTOM_COUNT_BY_VAX_LOT', 'COUNTRY']])
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def convertGlobalHistogramTable2DictTable(globalSymptomHistogramByBatchcodeTable):
|
||||||
|
vax_lot_columns = globalSymptomHistogramByBatchcodeTable.index.names.difference(['SYMPTOM'])
|
||||||
|
return (globalSymptomHistogramByBatchcodeTable
|
||||||
|
.groupby(vax_lot_columns)
|
||||||
|
.agg(lambda histogram_with_vax_lots: HistogramTable2DictTableConverter._histogram_to_json(histogram_with_vax_lots, vax_lot_columns)))
|
||||||
|
|
||||||
@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)
|
||||||
|
|||||||
@@ -45,3 +45,84 @@ class HistogramTable2DictTableConverterTest(unittest.TestCase):
|
|||||||
data = ['1808982',
|
data = ['1808982',
|
||||||
'EW0175'])))
|
'EW0175'])))
|
||||||
|
|
||||||
|
def test_convertHistogramTable2DictTable2(self):
|
||||||
|
# Given
|
||||||
|
histogramTable = TestHelper.createDataFrame(
|
||||||
|
columns = ['SYMPTOM_COUNT_BY_VAX_LOT', 'COUNTRY'],
|
||||||
|
data = [ [5, 'Germany'],
|
||||||
|
[1, 'Russian Federation'],
|
||||||
|
[2, 'Russian Federation']],
|
||||||
|
index = pd.MultiIndex.from_tuples(
|
||||||
|
names = ['VAX_LOT1', 'SYMPTOM'],
|
||||||
|
tuples = [['1808982', 'Blood pressure orthostatic abnormal'],
|
||||||
|
['1808982', 'Chest discomfort'],
|
||||||
|
['EW0175', 'Chest discomfort']]))
|
||||||
|
|
||||||
|
# When
|
||||||
|
dictTable = HistogramTable2DictTableConverter.convertHistogramTable2DictTable(histogramTable)
|
||||||
|
|
||||||
|
# Then
|
||||||
|
assert_frame_equal(
|
||||||
|
dictTable,
|
||||||
|
TestHelper.createDataFrame(
|
||||||
|
columns = ['SYMPTOM_COUNT_BY_VAX_LOT', 'COUNTRY'],
|
||||||
|
data = [ [
|
||||||
|
{
|
||||||
|
"Blood pressure orthostatic abnormal": 5
|
||||||
|
},
|
||||||
|
'Germany'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"Chest discomfort": 1
|
||||||
|
},
|
||||||
|
'Russian Federation'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"Chest discomfort": 2
|
||||||
|
},
|
||||||
|
'Russian Federation'
|
||||||
|
]],
|
||||||
|
index = pd.Index(
|
||||||
|
name = 'VAX_LOT1',
|
||||||
|
data = ['1808982',
|
||||||
|
'1808982',
|
||||||
|
'EW0175'])))
|
||||||
|
|
||||||
|
def test_convertGlobalHistogramTable2DictTable(self):
|
||||||
|
# Given
|
||||||
|
globalHistogramTable = TestHelper.createDataFrame(
|
||||||
|
columns = ['SYMPTOM_COUNT_BY_VAX_LOT'],
|
||||||
|
data = [ [5],
|
||||||
|
[1],
|
||||||
|
[2]],
|
||||||
|
index = pd.MultiIndex.from_tuples(
|
||||||
|
names = ['VAX_LOT1', 'SYMPTOM'],
|
||||||
|
tuples = [['1808982', 'Blood pressure orthostatic abnormal'],
|
||||||
|
['1808982', 'Chest discomfort'],
|
||||||
|
['EW0175', 'Chest discomfort']]))
|
||||||
|
|
||||||
|
# When
|
||||||
|
dictTable = HistogramTable2DictTableConverter.convertGlobalHistogramTable2DictTable(globalHistogramTable)
|
||||||
|
|
||||||
|
# Then
|
||||||
|
assert_frame_equal(
|
||||||
|
dictTable,
|
||||||
|
TestHelper.createDataFrame(
|
||||||
|
columns = ['SYMPTOM_COUNT_BY_VAX_LOT'],
|
||||||
|
data = [ [
|
||||||
|
{
|
||||||
|
"Blood pressure orthostatic abnormal": 5,
|
||||||
|
"Chest discomfort": 1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"Chest discomfort": 2
|
||||||
|
}
|
||||||
|
]],
|
||||||
|
index = pd.Index(
|
||||||
|
name = 'VAX_LOT1',
|
||||||
|
data = ['1808982',
|
||||||
|
'EW0175'])))
|
||||||
|
|||||||
Reference in New Issue
Block a user