From 93ff6fcaeb1a1007b79ad0b998c1a32f6f8f67be Mon Sep 17 00:00:00 2001 From: frankknoll Date: Tue, 3 Oct 2023 22:02:59 +0200 Subject: [PATCH] refactoring --- ...CountryCountsByClickedBatchcodeProvider.py | 26 +++---------------- src/GoogleAnalytics/GoogleAnalyticsReader.py | 13 ++++++++++ .../RegionCountsByClickedBatchcodeProvider.py | 5 ++-- 3 files changed, 19 insertions(+), 25 deletions(-) create mode 100644 src/GoogleAnalytics/GoogleAnalyticsReader.py diff --git a/src/CountryCountsByClickedBatchcodeProvider.py b/src/CountryCountsByClickedBatchcodeProvider.py index 1a2ddeb5390..f339fc81e4a 100644 --- a/src/CountryCountsByClickedBatchcodeProvider.py +++ b/src/CountryCountsByClickedBatchcodeProvider.py @@ -1,5 +1,7 @@ import pandas as pd from GoogleAnalytics.ResolutionProvider import Resolution, ResolutionProvider +from GoogleAnalytics.GoogleAnalyticsReader import GoogleAnalyticsReader +from GoogleAnalytics.RegionCountsByClickedBatchcodeProvider import RegionCountsByClickedBatchcodeProvider class CountryCountsByClickedBatchcodeProvider: @@ -22,34 +24,14 @@ class CountryCountsByClickedBatchcodeProvider: @staticmethod def _getCityCountsByClickedBatchcode(file): - return CountryCountsByClickedBatchcodeProvider._read_csv( - file = file, - columns = { - 'Country': 'COUNTRY', - 'Region': 'REGION', - 'City': 'CITY', - 'Event count': 'CITY_COUNT_BY_VAX_LOT' - }, - index_columns = ['COUNTRY', 'REGION', 'CITY']) + return RegionCountsByClickedBatchcodeProvider._getCityCountsByClickedBatchcode(file) @staticmethod def _getCountryCountsByClickedBatchcode_fromCountryResolution(file): - return CountryCountsByClickedBatchcodeProvider._read_csv( + return GoogleAnalyticsReader.read_csv( file = file, columns = { 'Country': 'COUNTRY', 'Event count': 'COUNTRY_COUNT_BY_VAX_LOT' }, index_columns = ['COUNTRY']) - - # FK-TODO: move this method to a new class named GoogleAnalytics.GoogleAnalyticsReader - @staticmethod - def _read_csv(file, columns, index_columns): - dataframe = pd.read_csv(file, index_col = 0, skiprows = [0, 1, 2, 3, 4, 5, 7]) - dataframe.index.name = 'VAX_LOT' - dataframe.rename( - columns = columns, - inplace = True) - dataframe.set_index(index_columns, append = True, inplace = True) - return dataframe - \ No newline at end of file diff --git a/src/GoogleAnalytics/GoogleAnalyticsReader.py b/src/GoogleAnalytics/GoogleAnalyticsReader.py new file mode 100644 index 00000000000..48cee99e1d1 --- /dev/null +++ b/src/GoogleAnalytics/GoogleAnalyticsReader.py @@ -0,0 +1,13 @@ +import pandas as pd + +class GoogleAnalyticsReader: + + @staticmethod + def read_csv(file, columns, index_columns): + dataframe = pd.read_csv(file, index_col = 0, skiprows = [0, 1, 2, 3, 4, 5, 7]) + dataframe.index.name = 'VAX_LOT' + dataframe.rename( + columns = columns, + inplace = True) + dataframe.set_index(index_columns, append = True, inplace = True) + return dataframe diff --git a/src/GoogleAnalytics/RegionCountsByClickedBatchcodeProvider.py b/src/GoogleAnalytics/RegionCountsByClickedBatchcodeProvider.py index dd80a9790be..0ddc2ab2c4b 100644 --- a/src/GoogleAnalytics/RegionCountsByClickedBatchcodeProvider.py +++ b/src/GoogleAnalytics/RegionCountsByClickedBatchcodeProvider.py @@ -1,6 +1,5 @@ import pandas as pd -from GoogleAnalytics.ResolutionProvider import Resolution, ResolutionProvider -from CountryCountsByClickedBatchcodeProvider import CountryCountsByClickedBatchcodeProvider +from GoogleAnalytics.GoogleAnalyticsReader import GoogleAnalyticsReader class RegionCountsByClickedBatchcodeProvider: @@ -17,7 +16,7 @@ class RegionCountsByClickedBatchcodeProvider: # FK-TODO: delegate same method CountryCountsByClickedBatchcodeProvider._getCityCountsByClickedBatchcode() to here @staticmethod def _getCityCountsByClickedBatchcode(file): - return CountryCountsByClickedBatchcodeProvider._read_csv( + return GoogleAnalyticsReader.read_csv( file = file, columns = { 'Country': 'COUNTRY',