From daf07fcf5bc902ee3b61612cacbc8509c0184bd1 Mon Sep 17 00:00:00 2001 From: 0xFugue <119708655+0xFugue@users.noreply.github.com> Date: Tue, 22 Aug 2023 22:46:49 +0530 Subject: [PATCH] batch processing --- scripts/analysis.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/scripts/analysis.py b/scripts/analysis.py index 9bf642f..4bb57d0 100644 --- a/scripts/analysis.py +++ b/scripts/analysis.py @@ -8,6 +8,7 @@ import numpy as np import logging as log from pathlib import Path import matplotlib.pyplot as plt +from os import walk def read_json(fname): with open(fname) as f: @@ -23,6 +24,7 @@ def read_csv(fname): def write_csv(df, fname): df.to_csv(fname) + def compute_view_finalisation_times(df, conf, oprefix, tag="tag", plot=False, epoch=True): num_nodes = conf["node_count"] two3rd = math.floor(num_nodes * 2/3) + 1 @@ -56,10 +58,11 @@ def compute_view_finalisation_times(df, conf, oprefix, tag="tag", plot=False, ep plt.show() plt.savefig(f'{oprefix}-view-finalisation-times.pdf', format="pdf", bbox_inches="tight") + app = typer.Typer() @app.command() -def views(ctx: typer.Context, +def view(ctx: typer.Context, data_file: Path = typer.Option("config.json", exists=True, file_okay=True, readable=True, help="Set the simulation config file"), @@ -72,19 +75,26 @@ def views(ctx: typer.Context, log.basicConfig(level=log.INFO) tag = os.path.splitext(os.path.basename(data_file))[0] - conf = read_json(config_file) - df = read_csv(data_file) + conf, df = read_json(config_file), read_csv(data_file) compute_view_finalisation_times(df, conf, oprefix, tag, plot=True, epoch=True) -def view_batch(ctx: typer.Context, - path: Path = typer.Option("./", +@app.command() +def views(ctx: typer.Context, + path: Path = typer.Option("../", exists=True, dir_okay=True, readable=True, help="Set the simulation config file"), oprefix: str = typer.Option("output", help="Set the output prefix for the plots") ): - pass + fin = [] + conf_fnames = next(walk(f'{path}/configs'), (None, None, []))[2] # [] if no file + for conf in conf_fnames: + prefix = os.path.splitext(os.path.basename(conf))[0] + conf = read_json(f'{path}/configs/{conf}') + df = read_csv(f'{path}/output/{prefix}.csv') + res = compute_view_finalisation_times(df, conf, oprefix, tag, plot=True, epoch=True) + fin.append(res)