Add timestamped default output naming

This commit is contained in:
thePR0M3TH3AN committed 2025-05-31 08:28:40 -04:00
1 parent 07fe399771
commit a8f2b4f4f6
4 files changed
+51 -7

No files matched your search

+15 -2
View File
@@ -20,6 +20,20 @@ import pandas as pd
import sqlite3
def save_figure(fig: plt.Figure, output: str | None, script_path: str) -> Path:
"""Save ``fig`` to ``output`` or a timestamped path under ``outputs/``."""
out_path = (
Path(output)
if output is not None
else Path("outputs")
/ f"{Path(script_path).stem}_{datetime.now().strftime('%Y%m%d_%H%M%S')}.png"
)
out_path.parent.mkdir(parents=True, exist_ok=True)
fig.savefig(out_path)
print(f"Saved figure to {out_path}")
return out_path
def fetch_series_multi(
series: Iterable[str],
start: datetime,
@@ -97,8 +111,7 @@ def main(argv: list[str] | None = None) -> plt.Figure:
data = fetch_series_multi(args.series, start_dt, end_dt, args.db)
fig = plot_series(data)
if args.output:
fig.savefig(args.output)
save_figure(fig, args.output, __file__)
if argv is None:
fig.show()
return fig