adding GoogleAnalyticsReaderTest
This commit is contained in:
32
src/GoogleAnalyticsReader.py
Normal file
32
src/GoogleAnalyticsReader.py
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
import linecache
|
||||||
|
import glob
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
|
class GoogleAnalyticsReader:
|
||||||
|
|
||||||
|
def __init__(self, dataDir):
|
||||||
|
self.dataDir = dataDir
|
||||||
|
|
||||||
|
def getDateRange(self):
|
||||||
|
return self._getMinMaxDateRange(self._getDateRanges())
|
||||||
|
|
||||||
|
def _getDateRanges(self):
|
||||||
|
return [self._getDateRange(file) for file in self._getFiles()]
|
||||||
|
|
||||||
|
def _getFiles(self):
|
||||||
|
return glob.glob(self.dataDir + '/*')
|
||||||
|
|
||||||
|
def _getDateRange(self, file):
|
||||||
|
dateRangeLine = linecache.getline(file, 4)
|
||||||
|
startDate, endDate = dateRangeLine[2:10], dateRangeLine[11:19]
|
||||||
|
return self._str2Date(startDate), self._str2Date(endDate)
|
||||||
|
|
||||||
|
def _str2Date(self, str):
|
||||||
|
return datetime.strptime(str, '%Y%m%d').date()
|
||||||
|
|
||||||
|
def _getMinMaxDateRange(self, dateRanges):
|
||||||
|
minDateRange = min([dateRange[0] for dateRange in dateRanges])
|
||||||
|
maxDateRange = max([dateRange[1] for dateRange in dateRanges])
|
||||||
|
return minDateRange, maxDateRange
|
||||||
|
|
||||||
15
src/GoogleAnalyticsReaderTest.py
Normal file
15
src/GoogleAnalyticsReaderTest.py
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import unittest
|
||||||
|
from datetime import date
|
||||||
|
from GoogleAnalyticsReader import GoogleAnalyticsReader
|
||||||
|
|
||||||
|
class GoogleAnalyticsReaderTest(unittest.TestCase):
|
||||||
|
|
||||||
|
def test_getDateRange(self):
|
||||||
|
# Given
|
||||||
|
googleAnalyticsReader = GoogleAnalyticsReader(dataDir = 'src/testdata/GoogleAnalytics')
|
||||||
|
|
||||||
|
# When
|
||||||
|
dateRange = googleAnalyticsReader.getDateRange()
|
||||||
|
|
||||||
|
# Then
|
||||||
|
self.assertEqual(dateRange, (date(2023, 3, 2), date(2023, 5, 31)))
|
||||||
6
src/testdata/GoogleAnalytics/Country By Clicked Batchcode 20230302-20230430.csv
vendored
Normal file
6
src/testdata/GoogleAnalytics/Country By Clicked Batchcode 20230302-20230430.csv
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
# ----------------------------------------
|
||||||
|
# HowBadIsMyBatch
|
||||||
|
# Batchcode By Country-Country By Clicked Batchcode
|
||||||
|
# 20230302-20230430
|
||||||
|
# ----------------------------------------
|
||||||
|
|
||||||
|
5
src/testdata/GoogleAnalytics/Country By Clicked Batchcode 20230501-20230531.csv
vendored
Normal file
5
src/testdata/GoogleAnalytics/Country By Clicked Batchcode 20230501-20230531.csv
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# ----------------------------------------
|
||||||
|
# HowBadIsMyBatch
|
||||||
|
# Batchcode By Country-Country By Clicked Batchcode
|
||||||
|
# 20230501-20230531
|
||||||
|
# ----------------------------------------
|
||||||
|
Reference in New Issue
Block a user