From bc21e91d04c7998c4c42b0ac4638185286eeb831 Mon Sep 17 00:00:00 2001 From: 0xFugue <119708655+0xFugue@users.noreply.github.com> Date: Mon, 21 Aug 2023 22:17:38 +0530 Subject: [PATCH] analysis.py - views --- scripts/analysis.py | 65 +++++++++++++++++++++++++++++++++------------ 1 file changed, 48 insertions(+), 17 deletions(-) diff --git a/scripts/analysis.py b/scripts/analysis.py index a73fd61..61cb2b7 100644 --- a/scripts/analysis.py +++ b/scripts/analysis.py @@ -1,27 +1,31 @@ +import os import typer +import json +import pandas as pd +import numpy as np import logging as log from pathlib import Path +import matplotlib.pyplot as plt -def read_csv(sim_dfile): - df=None +def read_json(fname): + with open(fname) as f: + cdata = json.load(f) + return cdata + + +def read_csv(fname): + df = pd.read_csv(fname, header=0, comment='#', skipinitialspace = True ) return df -def write_csv(df): - pass + +def write_csv(df, fname): + df.to_csv(fname) -def plot_vtimes(df, oprefix=""): - pass +app = typer.Typer() - -def compute_vtimes(df): - pass - - -def main(ctx: typer.Context, - config_file: Path = typer.Option("config.json", - exists=True, file_okay=True, readable=True, - help="Set the config file"), +@app.command() +def views(ctx: typer.Context, data_file: Path = typer.Option("simout.csv", exists=True, file_okay=True, readable=True, help="Set the simulation data file"), @@ -30,8 +34,35 @@ def main(ctx: typer.Context, debug: bool = typer.Option(True, help="Set debug") ): - log.info(config_file, data_file, oprefix, debug) + log.basicConfig(level=log.INFO) + tag = os.path.splitext(os.path.basename(data_file))[0] + + df = read_csv(data_file) + steps_df = data=df.drop_duplicates('current_view').step_id.diff().values[1:] + views_df = df['current_view'].unique()[1:] + + fig, axes = plt.subplots(1, 1, layout='constrained', sharey=False) + fig.set_figwidth(12) + fig.set_figheight(10) + + fig.suptitle(f'View installation times :: {tag}') + axes.set_ylabel("Number of Epochs") + axes.set_xlabel("Views") + axes.set_xticks([x + 1 for x in range(max(views_df.astype(int)))]) + axes.set_yticks([x + 1 for x in range(max(steps_df.astype(int)))]) + + axes.plot(views_df, steps_df, linestyle='--', marker='o') + plt.show() + plt.savefig(f'{oprefix}-view-installion-times.pdf', format="pdf", bbox_inches="tight") + + +@app.command() +def other_commands(): + pass if __name__ == "__main__": - typer.run(main) + app() + + +