From 2788882ec1d075c84ef1ce1935db5118c1947b66 Mon Sep 17 00:00:00 2001 From: frankknoll Date: Tue, 3 Oct 2023 22:51:33 +0200 Subject: [PATCH] refactoring --- src/CountryCountsByBatchcodeTablesMerger.py | 11 ++--------- src/TablesHelper.py | 11 +++++++++++ ...tchcodeTablesMergerTest.py => TablesHelperTest.py} | 8 ++++---- 3 files changed, 17 insertions(+), 13 deletions(-) create mode 100644 src/TablesHelper.py rename src/{CountryCountsByBatchcodeTablesMergerTest.py => TablesHelperTest.py} (82%) diff --git a/src/CountryCountsByBatchcodeTablesMerger.py b/src/CountryCountsByBatchcodeTablesMerger.py index b46a8e298c2..f3adeee4475 100644 --- a/src/CountryCountsByBatchcodeTablesMerger.py +++ b/src/CountryCountsByBatchcodeTablesMerger.py @@ -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(): diff --git a/src/TablesHelper.py b/src/TablesHelper.py new file mode 100644 index 00000000000..9c935212926 --- /dev/null +++ b/src/TablesHelper.py @@ -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()) diff --git a/src/CountryCountsByBatchcodeTablesMergerTest.py b/src/TablesHelperTest.py similarity index 82% rename from src/CountryCountsByBatchcodeTablesMergerTest.py rename to src/TablesHelperTest.py index 1dc4d98618d..6f6dd82f907 100644 --- a/src/CountryCountsByBatchcodeTablesMergerTest.py +++ b/src/TablesHelperTest.py @@ -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