adding RegionCountsByBatchcodeTablesMergerTest

This commit is contained in:
frankknoll
2023-10-03 23:37:34 +02:00
parent 2788882ec1
commit 6f7f8ef6b0
6 changed files with 62 additions and 8 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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']])))

View File

@@ -0,0 +1,6 @@
from enum import Enum
class Resolution(Enum):
CITY = 1
COUNTRY = 2

View File

@@ -1,11 +1,5 @@
from enum import Enum
import linecache
class Resolution(Enum):
CITY = 1
COUNTRY = 2
from GoogleAnalytics.Resolution import Resolution
class ResolutionProvider:

View File

@@ -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
1 # ----------------------------------------
2 # HowBadIsMyBatch
3 # Batchcode By Country-Country By Clicked Batchcode
4 # 20230730-20230929
5 # ----------------------------------------
6 Clicked Batchcode,Country,Region,City,Event count
7 ,,,,441337,Grand total
8 #003B21A,United States,California,Roseville,200
9 000086A,Germany,Bavaria,Nordlingen,20
10 000086A,Germany,Bavaria,Nuremberg,40