From d90d9c9fd533d0f1a4776dde621b0799acd92ab0 Mon Sep 17 00:00:00 2001 From: Iain Dillingham Date: Wed, 13 Dec 2023 17:21:35 +0000 Subject: [PATCH 1/3] Increase size of graph title ...from medium to large. --- analysis/plot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/analysis/plot.py b/analysis/plot.py index 4d697f1..293d0b3 100644 --- a/analysis/plot.py +++ b/analysis/plot.py @@ -100,7 +100,7 @@ def plot(by_day, by_week): ax.grid(True) ax.margins(x=0) min_ts, max_ts = [num2date(x) for x in ax.get_xlim()] - ax.set_title(f"From {min_ts:%Y-%m-%d} to {max_ts:%Y-%m-%d}", fontsize="medium") + ax.set_title(f"From {min_ts:%Y-%m-%d} to {max_ts:%Y-%m-%d}", fontsize="large") ax.set_ylabel("Event Counts") ax.set_ylim(0) ax.legend(loc="upper right") From b506081453ea4188afad2b63c6a89cc30afc0ce6 Mon Sep 17 00:00:00 2001 From: Iain Dillingham Date: Wed, 13 Dec 2023 18:05:50 +0000 Subject: [PATCH 2/3] Move `date_format` to `utils` --- analysis/render_report.py | 7 +------ analysis/utils.py | 5 +++++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/analysis/render_report.py b/analysis/render_report.py index e786df4..70a587c 100644 --- a/analysis/render_report.py +++ b/analysis/render_report.py @@ -58,14 +58,9 @@ def b64encode(path): return f"data:{mtype};base64, {encoded}" -def date_format(date): - """Formats the given date as, for example, "1 January 2023".""" - return f"{date:%-d %B %Y}" # the - removes the leading zero, but not on Windows - - # register template filters ENVIRONMENT.filters["b64encode"] = b64encode -ENVIRONMENT.filters["date_format"] = date_format +ENVIRONMENT.filters["date_format"] = utils.date_format def render_report(data): diff --git a/analysis/utils.py b/analysis/utils.py index 2daf557..e9d2729 100644 --- a/analysis/utils.py +++ b/analysis/utils.py @@ -27,3 +27,8 @@ def slugify(s): # remove leading and trailing dashes and underscores s = s.strip("-_") return s.lower() + + +def date_format(date): + """Formats the given date as, for example, "1 January 2023".""" + return f"{date:%-d %B %Y}" # the - removes the leading zero, but not on Windows From 423f13e1c64b201f6a4b3ac88ffea47ca03aa64f Mon Sep 17 00:00:00 2001 From: Iain Dillingham Date: Wed, 13 Dec 2023 18:06:34 +0000 Subject: [PATCH 3/3] Get graph titles from `from_date`/`from_offset` Doing so should help readers navigate the graphs. --- analysis/plot.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/analysis/plot.py b/analysis/plot.py index 293d0b3..fd135a4 100644 --- a/analysis/plot.py +++ b/analysis/plot.py @@ -6,7 +6,6 @@ import click import pandas from matplotlib import pyplot -from matplotlib.dates import num2date from analysis import click_types, utils @@ -41,7 +40,7 @@ def main(from_date, from_offset, d_out): utils.makedirs(d_out) - figs_cols = plot(by_day, by_week) + figs_cols = plot(by_day, by_week, get_plot_title(from_date, from_offset)) for fig, col in figs_cols: f_stem = utils.slugify(col) fig.savefig(d_out / f"{f_stem}.png") @@ -77,7 +76,14 @@ def get_date_ranges_from_offset(data_frame, from_offset): yield _DateRange(table_name, from_, to_) -def plot(by_day, by_week): +def get_plot_title(from_date, from_offset): + if from_date is not None: + return f"Event activity for the period from {utils.date_format(from_date)} to the report run date" + if from_offset is not None: + return f"The last {from_offset} days of event activity" + + +def plot(by_day, by_week, plot_title): cols = by_day.columns.union(by_week.columns) for col in cols: fig, ax = pyplot.subplots(figsize=(15, 7)) @@ -99,8 +105,7 @@ def plot(by_day, by_week): ax.grid(True) ax.margins(x=0) - min_ts, max_ts = [num2date(x) for x in ax.get_xlim()] - ax.set_title(f"From {min_ts:%Y-%m-%d} to {max_ts:%Y-%m-%d}", fontsize="large") + ax.set_title(plot_title) ax.set_ylabel("Event Counts") ax.set_ylim(0) ax.legend(loc="upper right")