From 6f7f8ef6b03088000b0f9aa39ba364e5b81759c6 Mon Sep 17 00:00:00 2001 From: frankknoll Date: Tue, 3 Oct 2023 23:37:34 +0200 Subject: [PATCH] adding RegionCountsByBatchcodeTablesMergerTest --- src/GoogleAnalytics/FilesProviderTest.py | 7 +++++- .../RegionCountsByBatchcodeTablesMerger.py | 13 ++++++++++ ...RegionCountsByBatchcodeTablesMergerTest.py | 25 +++++++++++++++++++ src/GoogleAnalytics/Resolution.py | 6 +++++ src/GoogleAnalytics/ResolutionProvider.py | 8 +----- .../CountryByBatchcode 20230929-20230930.csv | 11 ++++++++ 6 files changed, 62 insertions(+), 8 deletions(-) create mode 100644 src/GoogleAnalytics/RegionCountsByBatchcodeTablesMerger.py create mode 100644 src/GoogleAnalytics/RegionCountsByBatchcodeTablesMergerTest.py create mode 100644 src/GoogleAnalytics/Resolution.py create mode 100644 src/testdata/GoogleAnalytics/CountryByBatchcode 20230929-20230930.csv diff --git a/src/GoogleAnalytics/FilesProviderTest.py b/src/GoogleAnalytics/FilesProviderTest.py index 7e8128a55cc..4281a075108 100644 --- a/src/GoogleAnalytics/FilesProviderTest.py +++ b/src/GoogleAnalytics/FilesProviderTest.py @@ -13,7 +13,12 @@ class FilesProviderTest(unittest.TestCase): files = filesProvider.getFilesHavingResolution(Resolution.CITY) # Then - self.assertEqual(files, [dataDir + '/CountryByBatchcode 20230730-20230929.csv']) + self.assertEqual( + files, + [ + dataDir + '/CountryByBatchcode 20230730-20230929.csv', + dataDir + '/CountryByBatchcode 20230929-20230930.csv' + ]) def test_getFilesHavingCountryResolution(self): # Given diff --git a/src/GoogleAnalytics/RegionCountsByBatchcodeTablesMerger.py b/src/GoogleAnalytics/RegionCountsByBatchcodeTablesMerger.py new file mode 100644 index 00000000000..91f99bd46a9 --- /dev/null +++ b/src/GoogleAnalytics/RegionCountsByBatchcodeTablesMerger.py @@ -0,0 +1,13 @@ +from GoogleAnalytics.RegionCountsByClickedBatchcodeProvider import RegionCountsByClickedBatchcodeProvider +from GoogleAnalytics.FilesProvider import FilesProvider +from GoogleAnalytics.Resolution import Resolution +from TablesHelper import TablesHelper + +class RegionCountsByBatchcodeTablesMerger: + + @staticmethod + def getRegionCountsByClickedBatchcode(dataDir): + files = FilesProvider(dataDir).getFilesHavingResolution(Resolution.CITY) + tables = [RegionCountsByClickedBatchcodeProvider.getRegionCountsByClickedBatchcode(file) for file in files] + table = TablesHelper.concatTables_groupByIndex_sum(tables) + return table diff --git a/src/GoogleAnalytics/RegionCountsByBatchcodeTablesMergerTest.py b/src/GoogleAnalytics/RegionCountsByBatchcodeTablesMergerTest.py new file mode 100644 index 00000000000..bed9b856c1e --- /dev/null +++ b/src/GoogleAnalytics/RegionCountsByBatchcodeTablesMergerTest.py @@ -0,0 +1,25 @@ +import unittest +from pandas.testing import assert_frame_equal +from TestHelper import TestHelper +import pandas as pd +from src.GoogleAnalytics.RegionCountsByBatchcodeTablesMerger import RegionCountsByBatchcodeTablesMerger + +class RegionCountsByBatchcodeTablesMergerTest(unittest.TestCase): + + def test_getRegionCountsByClickedBatchcode(self): + # Given + + # When + regionCountsByClickedBatchcodeTable = RegionCountsByBatchcodeTablesMerger.getRegionCountsByClickedBatchcode('src/testdata/GoogleAnalytics') + + # Then + assert_frame_equal( + regionCountsByClickedBatchcodeTable, + TestHelper.createDataFrame( + columns = ['REGION_COUNT_BY_VAX_LOT'], + data = [ [100 + 200], + [(10 + 20) + (20 + 40)]], + index = pd.MultiIndex.from_tuples( + names = ['VAX_LOT', 'COUNTRY', 'REGION'], + tuples = [['#003B21A', 'United States', 'California'], + ['000086A', 'Germany', 'Bavaria']]))) diff --git a/src/GoogleAnalytics/Resolution.py b/src/GoogleAnalytics/Resolution.py new file mode 100644 index 00000000000..ad3c982acfb --- /dev/null +++ b/src/GoogleAnalytics/Resolution.py @@ -0,0 +1,6 @@ +from enum import Enum + + +class Resolution(Enum): + CITY = 1 + COUNTRY = 2 diff --git a/src/GoogleAnalytics/ResolutionProvider.py b/src/GoogleAnalytics/ResolutionProvider.py index ea9b87dac24..d7f75adab05 100644 --- a/src/GoogleAnalytics/ResolutionProvider.py +++ b/src/GoogleAnalytics/ResolutionProvider.py @@ -1,11 +1,5 @@ -from enum import Enum import linecache - - -class Resolution(Enum): - CITY = 1 - COUNTRY = 2 - +from GoogleAnalytics.Resolution import Resolution class ResolutionProvider: diff --git a/src/testdata/GoogleAnalytics/CountryByBatchcode 20230929-20230930.csv b/src/testdata/GoogleAnalytics/CountryByBatchcode 20230929-20230930.csv new file mode 100644 index 00000000000..1caaefef8ed --- /dev/null +++ b/src/testdata/GoogleAnalytics/CountryByBatchcode 20230929-20230930.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,200 +000086A,Germany,Bavaria,Nordlingen,20 +000086A,Germany,Bavaria,Nuremberg,40