refactoring
This commit is contained in:
@@ -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
11
src/TablesHelper.py
Normal 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())
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user