Skip to content

Commit

Permalink
Additional refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisRBe committed Nov 21, 2020
1 parent 3ec018d commit 3dc51d2
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/p2p_account_statement_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,26 @@ def __parse_service_config(self):
config = safe_load(ymlconfig)
self.config = Config(config)

def __process_statement(self, statement, aggregate="daily"):
"""
Processes each statement read from the account statement file. First, format in into the dictionary.
Then check what aggregation should be applied.
- daily: add directly to the output list.
- monthly: add it to intermediate aggregation collection.
:param statement: Contains one line from the account statement file
:param aggregate: specify the aggregation format; e.g. daily or monthly. Defaults to daily.
:return:
"""
formatted_account_entry = self.__format_statement(statement)
if formatted_account_entry:
if aggregate == "daily":
self.output_list.append(formatted_account_entry)
elif aggregate == "monthly":
self.__aggregate_statements_monthly(formatted_account_entry)

def parse_account_statement(self, aggregate="daily"):
"""
read a platform account statement csv file and filter the content according to the given configuration file.
Expand All @@ -141,12 +161,7 @@ def parse_account_statement(self, aggregate="daily"):
account_statement = csv.DictReader(infile, dialect=dialect)

for statement in account_statement:
formatted_account_entry = self.__format_statement(statement)
if formatted_account_entry:
if aggregate == "daily":
self.output_list.append(formatted_account_entry)
elif aggregate == "monthly":
self.__aggregate_statements_monthly(formatted_account_entry)
self.__process_statement(aggregate=aggregate, statement=statement)

if aggregate == "monthly":
self.__migrate_data_to_output()
Expand Down

0 comments on commit 3dc51d2

Please sign in to comment.