starting RegionCountsByClickedBatchcodeProviderTest
This commit is contained in:
@@ -42,6 +42,7 @@ class CountryCountsByClickedBatchcodeProvider:
|
|||||||
},
|
},
|
||||||
index_columns = ['COUNTRY'])
|
index_columns = ['COUNTRY'])
|
||||||
|
|
||||||
|
# FK-TODO: move this method to a new class named GoogleAnalytics.GoogleAnalyticsReader
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _read_csv(file, columns, index_columns):
|
def _read_csv(file, columns, index_columns):
|
||||||
dataframe = pd.read_csv(file, index_col = 0, skiprows = [0, 1, 2, 3, 4, 5, 7])
|
dataframe = pd.read_csv(file, index_col = 0, skiprows = [0, 1, 2, 3, 4, 5, 7])
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import pandas as pd
|
||||||
|
from GoogleAnalytics.ResolutionProvider import Resolution, ResolutionProvider
|
||||||
|
from CountryCountsByClickedBatchcodeProvider import CountryCountsByClickedBatchcodeProvider
|
||||||
|
|
||||||
|
class RegionCountsByClickedBatchcodeProvider:
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def getRegionCountsByClickedBatchcode(file):
|
||||||
|
cityCountsByClickedBatchcodeTable = RegionCountsByClickedBatchcodeProvider._getCityCountsByClickedBatchcode(file)
|
||||||
|
return (cityCountsByClickedBatchcodeTable
|
||||||
|
.groupby(['VAX_LOT', 'COUNTRY', 'REGION'])
|
||||||
|
.agg(REGION_COUNT_BY_VAX_LOT =
|
||||||
|
pd.NamedAgg(
|
||||||
|
column = 'CITY_COUNT_BY_VAX_LOT',
|
||||||
|
aggfunc = sum)))
|
||||||
|
|
||||||
|
# FK-TODO: delegate same method CountryCountsByClickedBatchcodeProvider._getCityCountsByClickedBatchcode() to here
|
||||||
|
@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'])
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import unittest
|
||||||
|
from pandas.testing import assert_frame_equal
|
||||||
|
from TestHelper import TestHelper
|
||||||
|
import pandas as pd
|
||||||
|
from GoogleAnalytics.RegionCountsByClickedBatchcodeProvider import RegionCountsByClickedBatchcodeProvider
|
||||||
|
|
||||||
|
class RegionCountsByClickedBatchcodeProviderTest(unittest.TestCase):
|
||||||
|
|
||||||
|
def test_getRegionCountsByClickedBatchcode(self):
|
||||||
|
# Given
|
||||||
|
|
||||||
|
# When
|
||||||
|
regionCountsByClickedBatchcodeTable = RegionCountsByClickedBatchcodeProvider.getRegionCountsByClickedBatchcode('src/testdata/GoogleAnalytics/CountryByBatchcode 20230730-20230929.csv')
|
||||||
|
|
||||||
|
# Then
|
||||||
|
assert_frame_equal(
|
||||||
|
regionCountsByClickedBatchcodeTable,
|
||||||
|
TestHelper.createDataFrame(
|
||||||
|
columns = ['REGION_COUNT_BY_VAX_LOT'],
|
||||||
|
data = [ [100],
|
||||||
|
[10 + 20]],
|
||||||
|
index = pd.MultiIndex.from_tuples(
|
||||||
|
names = ['VAX_LOT', 'COUNTRY', 'REGION'],
|
||||||
|
tuples = [['#003B21A', 'United States', 'California'],
|
||||||
|
['000086A', 'Germany', 'Bavaria']])))
|
||||||
Reference in New Issue
Block a user