diff --git a/src/CountryCountsByClickedBatchcodeProvider.py b/src/CountryCountsByClickedBatchcodeProvider.py index 408491bdcd2..d24365f4c3c 100644 --- a/src/CountryCountsByClickedBatchcodeProvider.py +++ b/src/CountryCountsByClickedBatchcodeProvider.py @@ -15,3 +15,19 @@ class CountryCountsByClickedBatchcodeProvider: inplace = True) exploration.set_index('COUNTRY', append = True, inplace = True) return exploration + + @staticmethod + def getCityCountsByClickedBatchcode(file): + exploration = pd.read_csv(file, index_col = 0, skiprows = [0, 1, 2, 3, 4, 5, 7]) + exploration.index.name = 'VAX_LOT' + exploration.rename( + columns = + { + 'Country': 'COUNTRY', + 'Region': 'REGION', + 'City': 'CITY', + 'Event count': 'CITY_COUNT_BY_VAX_LOT' + }, + inplace = True) + exploration.set_index(['COUNTRY', 'REGION', 'CITY'], append = True, inplace = True) + return exploration diff --git a/src/CountryCountsByClickedBatchcodeProviderTest.py b/src/CountryCountsByClickedBatchcodeProviderTest.py index 11824f162f8..838d6284334 100644 --- a/src/CountryCountsByClickedBatchcodeProviderTest.py +++ b/src/CountryCountsByClickedBatchcodeProviderTest.py @@ -6,7 +6,7 @@ from CountryCountsByClickedBatchcodeProvider import CountryCountsByClickedBatchc class CountryCountsByClickedBatchcodeProviderTest(unittest.TestCase): - def test_mergeCountryCountsByBatchcodeTables(self): + def test_getCountryCountsByClickedBatchcode(self): # Given # When @@ -25,3 +25,23 @@ class CountryCountsByClickedBatchcodeProviderTest(unittest.TestCase): tuples = [['#012M20A', 'United States'], ['#EN6203', 'United States'], ['000006A', 'Japan']]))) + + def test_getCityCountsByClickedBatchcode(self): + # Given + + # When + cityCountsByClickedBatchcodeTable = CountryCountsByClickedBatchcodeProvider.getCityCountsByClickedBatchcode('src/testdata/GoogleAnalytics/CountryByBatchcode 20230730-20230929.csv') + + # Then + assert_frame_equal( + cityCountsByClickedBatchcodeTable, + TestHelper.createDataFrame( + columns = ['CITY_COUNT_BY_VAX_LOT'], + data = [ [100], + [10], + [20]], + index = pd.MultiIndex.from_tuples( + names = ['VAX_LOT', 'COUNTRY', 'REGION', 'CITY'], + tuples = [['#003B21A', 'United States', 'California', 'Roseville'], + ['000086A', 'Germany', 'Bavaria', 'Nordlingen'], + ['000086A', 'Germany', 'Bavaria', 'Nuremberg']]))) diff --git a/src/testdata/GoogleAnalytics/CountryByBatchcode 20230730-20230929.csv b/src/testdata/GoogleAnalytics/CountryByBatchcode 20230730-20230929.csv new file mode 100644 index 00000000000..ac9f5bad994 --- /dev/null +++ b/src/testdata/GoogleAnalytics/CountryByBatchcode 20230730-20230929.csv @@ -0,0 +1,11 @@ +# ---------------------------------------- +# HowBadIsMyBatch +# Batchcode By Country-Country By Clicked Batchcode +# 20230730-20230929 +# ---------------------------------------- + +Clicked Batchcode,Country,Region,City,Event count +,,,,441337,Grand total +#003B21A,United States,California,Roseville,100 +000086A,Germany,Bavaria,Nordlingen,10 +000086A,Germany,Bavaria,Nuremberg,20