refactoring

This commit is contained in:
frankknoll
2023-10-03 22:51:33 +02:00
parent 93ff6fcaeb
commit 2788882ec1
3 changed files with 17 additions and 13 deletions

View File

@@ -1,19 +1,12 @@
import pandas as pd
import glob
from CountryCountsByClickedBatchcodeProvider import CountryCountsByClickedBatchcodeProvider
from TablesHelper import TablesHelper
class CountryCountsByBatchcodeTablesMerger:
@staticmethod
def mergeCountryCountsByBatchcodeTables(countryCountsByBatchcodeTables):
return (pd
.concat(countryCountsByBatchcodeTables)
.groupby(countryCountsByBatchcodeTables[0].index.names)
.sum())
@staticmethod
def getCountryCountsByClickedBatchcodeTable():
return CountryCountsByBatchcodeTablesMerger.mergeCountryCountsByBatchcodeTables(CountryCountsByBatchcodeTablesMerger._getTables())
return TablesHelper.concatTables_groupByIndex_sum(CountryCountsByBatchcodeTablesMerger._getTables())
@staticmethod
def _getTables():

11
src/TablesHelper.py Normal file
View File

@@ -0,0 +1,11 @@
import pandas as pd
class TablesHelper:
@staticmethod
def concatTables_groupByIndex_sum(tables):
return (pd
.concat(tables)
.groupby(tables[0].index.names)
.sum())

View File

@@ -2,11 +2,11 @@ import unittest
from pandas.testing import assert_frame_equal
from TestHelper import TestHelper
import pandas as pd
from CountryCountsByBatchcodeTablesMerger import CountryCountsByBatchcodeTablesMerger
from TablesHelper import TablesHelper
class CountryCountsByBatchcodeTablesMergerTest(unittest.TestCase):
class TablesHelperTest(unittest.TestCase):
def test_mergeCountryCountsByBatchcodeTables(self):
def test_concatTables_groupByIndex_sum(self):
# Given
countryCountsByBatchcodeTable1 = TestHelper.createDataFrame(
columns = ['COUNTRY_COUNT_BY_VAX_LOT'],
@@ -24,7 +24,7 @@ class CountryCountsByBatchcodeTablesMergerTest(unittest.TestCase):
tuples = [['12345', 'Germany']]))
# When
mergedCountryCountsByBatchcodeTables = CountryCountsByBatchcodeTablesMerger.mergeCountryCountsByBatchcodeTables(
mergedCountryCountsByBatchcodeTables = TablesHelper.concatTables_groupByIndex_sum(
[
countryCountsByBatchcodeTable1,
countryCountsByBatchcodeTable2