diff --git a/consensus_decentralization/aggregate.py b/consensus_decentralization/aggregate.py index 394794e..898226c 100644 --- a/consensus_decentralization/aggregate.py +++ b/consensus_decentralization/aggregate.py @@ -97,7 +97,7 @@ def aggregate(project, output_dir, timeframe, aggregate_by, force_aggregate, map mapped_data = hlp.read_mapped_project_data(project_io_dir) aggregator = Aggregator(project, project_io_dir, mapped_data) - filename = f'{aggregate_by}_from_{timeframe[0]}_to_{timeframe[1]}.csv' + filename = hlp.get_blocks_per_entity_filename(aggregate_by=aggregate_by, timeframe=timeframe) output_file = aggregator.aggregated_data_dir / filename if not output_file.is_file() or force_aggregate: diff --git a/consensus_decentralization/helper.py b/consensus_decentralization/helper.py index 13a21ff..34a637d 100644 --- a/consensus_decentralization/helper.py +++ b/consensus_decentralization/helper.py @@ -291,3 +291,32 @@ def format_time_chunks(time_chunks, granularity): timeframe_chunks = [f'{chunk[0].strftime("%Y-%m-%d")} to {chunk[1].strftime("%Y-%m-%d")}' for chunk in time_chunks] return timeframe_chunks + + +def get_granularity_from_aggregate_by(aggregate_by): + """ + Determines the granularity (adverb to be used in the output file names) from the aggregate_by argument + :param aggregate_by: str that can be one of day, week, month, year, all + :returns: str that is the corresponding adverb of aggregate_by + """ + if aggregate_by == 'day': + return 'daily' + elif aggregate_by == 'week': + return 'weekly' + elif aggregate_by == 'month': + return 'monthly' + elif aggregate_by == 'year': + return 'yearly' + else: + return 'all' + + +def get_blocks_per_entity_filename(aggregate_by, timeframe): + """ + Determines the filename of the csv file that contains the aggregated data + :param aggregate_by: str that can be one of day, week, month, year, all + :param timeframe: tuple of (start_date, end_date) where each date is a datetime.date object + :returns: str that corresponds to the filename of the csv file + """ + granularity = get_granularity_from_aggregate_by(aggregate_by) + return f'{granularity}_from_{timeframe[0]}_to_{timeframe[1]}.csv' diff --git a/run.py b/run.py index 1d4fffd..960b4b2 100644 --- a/run.py +++ b/run.py @@ -6,7 +6,7 @@ from consensus_decentralization.parse import parse from consensus_decentralization.plot import plot from consensus_decentralization.helper import valid_date, RAW_DATA_DIR, OUTPUT_DIR, get_default_ledgers, \ - get_default_start_end_dates, get_timeframe_beginning, get_timeframe_end + get_default_start_end_dates, get_timeframe_beginning, get_timeframe_end, get_blocks_per_entity_filename logging.basicConfig(format='[%(asctime)s] %(message)s', datefmt='%Y/%m/%d %I:%M:%S %p', level=logging.INFO) @@ -46,7 +46,7 @@ def main(projects, timeframe, aggregate_by, force_map, make_plots, make_animated used_metrics = analyze( projects=projects, - aggregated_data_filename=f'{aggregate_by}_from_{timeframe[0]}_to_{timeframe[1]}.csv', + aggregated_data_filename=get_blocks_per_entity_filename(aggregate_by=aggregate_by, timeframe=timeframe), output_dir=output_dir )