Skip to content

Commit

Permalink
Use adverb in aggregated data filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
LadyChristina committed Oct 2, 2023
1 parent c1f5e1e commit 90b0c96
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
2 changes: 1 addition & 1 deletion consensus_decentralization/aggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
29 changes: 29 additions & 0 deletions consensus_decentralization/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
4 changes: 2 additions & 2 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
)

Expand Down

0 comments on commit 90b0c96

Please sign in to comment.