saveBarChartDescriptionTable()
This commit is contained in:
@@ -1,25 +0,0 @@
|
||||
import pandas as pd
|
||||
|
||||
class CountryCountsByBatchcodeTable2BarChartDescriptionsConverter:
|
||||
|
||||
@staticmethod
|
||||
def convert2BarChartDescriptionTable(countryCountsByBatchcodeTable):
|
||||
return (countryCountsByBatchcodeTable
|
||||
.reset_index(level = 'COUNTRY')
|
||||
.rename(
|
||||
columns =
|
||||
{
|
||||
'COUNTRY': 'countries',
|
||||
'COUNTRY_COUNT_BY_VAX_LOT Clicked': 'frequencies guessed',
|
||||
'COUNTRY_COUNT_BY_VAX_LOT Before Deletion': 'frequencies before deletion'
|
||||
})
|
||||
.groupby('VAX_LOT')
|
||||
.apply(CountryCountsByBatchcodeTable2BarChartDescriptionsConverter._convert2BarChartDescription)
|
||||
.rename('BAR_CHART_DESCRIPTION')
|
||||
.to_frame())
|
||||
|
||||
@staticmethod
|
||||
def _convert2BarChartDescription(countryCountsTable):
|
||||
barChartDescription = countryCountsTable.to_dict('list')
|
||||
barChartDescription['batchcode'] = countryCountsTable.index.values[0]
|
||||
return barChartDescription
|
||||
@@ -1,54 +0,0 @@
|
||||
import unittest
|
||||
import pandas as pd
|
||||
from pandas.testing import assert_frame_equal
|
||||
from TestHelper import TestHelper
|
||||
from CountryCountsByBatchcodeTable2BarChartDescriptionsConverter import CountryCountsByBatchcodeTable2BarChartDescriptionsConverter
|
||||
|
||||
class CountryCountsByBatchcodeTable2BarChartDescriptionsConverterTest(unittest.TestCase):
|
||||
|
||||
def test_convert2BarChartDescriptionTable(self):
|
||||
# Given
|
||||
countryCountsByBatchcodeTable = TestHelper.createDataFrame(
|
||||
columns = ['COUNTRY_COUNT_BY_VAX_LOT Clicked', 'COUNTRY_COUNT_BY_VAX_LOT Before Deletion'],
|
||||
data = [ [10, 20],
|
||||
[15, 30],
|
||||
[70, 80]],
|
||||
index = pd.MultiIndex.from_tuples(
|
||||
names = ['VAX_LOT', 'COUNTRY'],
|
||||
tuples = [('!D0181', 'Germany'),
|
||||
('!D0181', 'Hungary'),
|
||||
('# 009C01A', 'Germany')]))
|
||||
|
||||
# When
|
||||
barChartDescriptionTable = CountryCountsByBatchcodeTable2BarChartDescriptionsConverter.convert2BarChartDescriptionTable(countryCountsByBatchcodeTable)
|
||||
|
||||
# Then
|
||||
assert_frame_equal(
|
||||
barChartDescriptionTable,
|
||||
TestHelper.createDataFrame(
|
||||
columns = ['BAR_CHART_DESCRIPTION'],
|
||||
data = [
|
||||
[
|
||||
{
|
||||
'batchcode': '!D0181',
|
||||
'countries': ['Germany', 'Hungary'],
|
||||
'frequencies guessed': [10, 15],
|
||||
'frequencies before deletion': [20, 30]
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
'batchcode': '# 009C01A',
|
||||
'countries': ['Germany'],
|
||||
'frequencies guessed': [70],
|
||||
'frequencies before deletion': [80]
|
||||
}
|
||||
]
|
||||
],
|
||||
index = pd.Index(
|
||||
[
|
||||
'!D0181',
|
||||
'# 009C01A'
|
||||
],
|
||||
name = 'VAX_LOT')),
|
||||
check_dtype = True)
|
||||
@@ -181,9 +181,9 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from CountryCountsByBatchcodeTable2BarChartDescriptionsConverter import CountryCountsByBatchcodeTable2BarChartDescriptionsConverter\n",
|
||||
"from CountryCountsByBatchcodeTable2BarChartDescriptionTableConverter import CountryCountsByBatchcodeTable2BarChartDescriptionTableConverter\n",
|
||||
"\n",
|
||||
"barChartDescriptionTable = CountryCountsByBatchcodeTable2BarChartDescriptionsConverter.convert2BarChartDescriptionTable(countryCountsByBatchcode)\n",
|
||||
"barChartDescriptionTable = CountryCountsByBatchcodeTable2BarChartDescriptionTableConverter.convert2BarChartDescriptionTable(countryCountsByBatchcode)\n",
|
||||
"barChartDescriptionTable"
|
||||
]
|
||||
},
|
||||
@@ -194,11 +194,9 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from IOUtils import IOUtils\n",
|
||||
"from BarChartDescriptionTablePersister import saveBarChartDescriptionTable\n",
|
||||
"\n",
|
||||
"IOUtils.saveDataFrameAsJson(\n",
|
||||
" barChartDescriptionTable,\n",
|
||||
" '../docs/data/barChartDescriptionTable.json')"
|
||||
"saveBarChartDescriptionTable(barChartDescriptionTable)"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user