analysis.py - views

This commit is contained in:
0xFugue 2023-08-21 22:17:38 +05:30
parent 5442a79a01
commit bc21e91d04

View File

@ -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()