Compare commits
2 Commits
35c8862aa8
...
0471251edf
Author | SHA1 | Date |
---|---|---|
0xFugue | 0471251edf | |
0xFugue | 0ebc6b7f03 |
|
@ -12,33 +12,40 @@ import matplotlib.pyplot as plt
|
||||||
from os import walk
|
from os import walk
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
|
# read a json and return the dict
|
||||||
def read_json(fname):
|
def read_json(fname):
|
||||||
with open(fname) as f:
|
with open(fname) as f:
|
||||||
cdata = json.load(f)
|
cdata = json.load(f)
|
||||||
return cdata
|
return cdata
|
||||||
|
|
||||||
|
# write the json from a dict
|
||||||
def write_json(dic, fname):
|
def write_json(dic, fname):
|
||||||
dic_str = {str(k): str(v) for k,v in dic.items()}
|
dic_str = {str(k): str(v) for k,v in dic.items()}
|
||||||
jdump = json.dumps(dic_str, indent=4, sort_keys=True)
|
jdump = json.dumps(dic_str, indent=4, sort_keys=True)
|
||||||
with open(fname, 'w') as f:
|
with open(fname, 'w') as f:
|
||||||
f.write(jdump)
|
f.write(jdump)
|
||||||
|
|
||||||
|
# read a serialised python dict
|
||||||
def read_dict(fname):
|
def read_dict(fname):
|
||||||
with open(fname, 'r') as f:
|
with open(fname, 'r') as f:
|
||||||
return eval(f.read())
|
return eval(f.read())
|
||||||
|
|
||||||
|
# write a serialised python fict
|
||||||
def write_dict(dic, fname):
|
def write_dict(dic, fname):
|
||||||
with open(fname, 'w') as f:
|
with open(fname, 'w') as f:
|
||||||
return f.write(str(dic))
|
return f.write(str(dic))
|
||||||
|
|
||||||
|
# read the output csv and return a panadas dataframe
|
||||||
def read_csv(fname):
|
def read_csv(fname):
|
||||||
df = pd.read_csv(fname, header=0, comment='#', skipinitialspace = True )
|
df = pd.read_csv(fname, header=0, comment='#', skipinitialspace = True )
|
||||||
return df
|
return df
|
||||||
|
|
||||||
|
# write pandas dataframe as csv
|
||||||
def write_csv(df, fname):
|
def write_csv(df, fname):
|
||||||
df.to_csv(fname)
|
df.to_csv(fname)
|
||||||
|
|
||||||
|
|
||||||
|
# compute the steps it took to compute the views, and tag the tree depth
|
||||||
def compute_view_finalisation_times(df, conf, oprefix, simtype, tag="tag", plot=False):
|
def compute_view_finalisation_times(df, conf, oprefix, simtype, tag="tag", plot=False):
|
||||||
if simtype == "tree":
|
if simtype == "tree":
|
||||||
num_nodes = conf["node_count"]
|
num_nodes = conf["node_count"]
|
||||||
|
@ -52,16 +59,21 @@ def compute_view_finalisation_times(df, conf, oprefix, simtype, tag="tag", plot=
|
||||||
two3rd = math.floor(conf["node_count"] * 2/3) + 1
|
two3rd = math.floor(conf["node_count"] * 2/3) + 1
|
||||||
#two3rd = math.floor(conf["node_count"] * 3/3)
|
#two3rd = math.floor(conf["node_count"] * 3/3)
|
||||||
|
|
||||||
views, view2fin_time = df.current_view.unique()[:-2], {}
|
# for view_offset^th view, last view_offset number of views will need to be omitted
|
||||||
|
view_offset = 1
|
||||||
|
#views, view2fin_time = df.current_view.unique()[:-2], {}
|
||||||
|
views, view2fin_time = df.current_view.unique()[:-view_offset], {}
|
||||||
log.debug(f'views: {conf["stream_settings"]["path"]} {views}, {df.current_view.unique()}')
|
log.debug(f'views: {conf["stream_settings"]["path"]} {views}, {df.current_view.unique()}')
|
||||||
|
|
||||||
|
print(df.current_view.unique(), df.step_id.unique(), df.columns)
|
||||||
for start_view in views:
|
for start_view in views:
|
||||||
end_view = start_view + 2
|
end_view = start_view + view_offset
|
||||||
start_idx = df.index[(df['current_view'] == start_view)][0]
|
start_idx = df.index[(df['current_view'] == start_view)][0]
|
||||||
end_idx = df.index[(df['current_view'] == end_view)][two3rd-1]
|
end_idx = df.index[(df['current_view'] == end_view)][two3rd-1]
|
||||||
start_step = df.iloc[start_idx].step_id
|
start_step = df.iloc[start_idx].step_id
|
||||||
end_step = df.iloc[end_idx].step_id
|
end_step = df.iloc[end_idx].step_id
|
||||||
view2fin_time[start_view] = end_step - start_step
|
view2fin_time[start_view] = end_step - start_step
|
||||||
|
#print(f'TEST {conf["stream_settings"]["path"]}, {view2fin_time[start_view]}, {(start_view, start_idx, start_step)}, {(end_idx, end_view, end_step)}')
|
||||||
log.debug(f'{start_view}({start_idx}), {end_view}({end_idx}) : {end_step} - {start_step} = {view2fin_time[start_view]}')
|
log.debug(f'{start_view}({start_idx}), {end_view}({end_idx}) : {end_step} - {start_step} = {view2fin_time[start_view]}')
|
||||||
|
|
||||||
if not plot:
|
if not plot:
|
||||||
|
@ -81,17 +93,22 @@ def compute_view_finalisation_times(df, conf, oprefix, simtype, tag="tag", plot=
|
||||||
plt.show()
|
plt.show()
|
||||||
plt.savefig(f'{oprefix}-view-finalisation-times.pdf', format="pdf", bbox_inches="tight")
|
plt.savefig(f'{oprefix}-view-finalisation-times.pdf', format="pdf", bbox_inches="tight")
|
||||||
|
|
||||||
|
|
||||||
|
# iterate over the different networks/overlay type and collect view finalisation times
|
||||||
def compute_view_times(path, oprefix, otype):
|
def compute_view_times(path, oprefix, otype):
|
||||||
nwsize2vfins = {}
|
nwsize2vfins = {}
|
||||||
#conf_fnames = next(walk(f'{path}/configs'), (None, None, []))[2]
|
#conf_fnames = next(walk(f'{path}/configs'), (None, None, []))[2]
|
||||||
conf_fnames = glob.glob(f'{path}/configs/*_{otype}.json')
|
conf_fnames = glob.glob(f'{path}/configs/*_{otype}.json')
|
||||||
|
print(conf_fnames, otype)
|
||||||
for conf in conf_fnames:
|
for conf in conf_fnames:
|
||||||
tag = os.path.splitext(os.path.basename(conf))[0]
|
tag = os.path.splitext(os.path.basename(conf))[0]
|
||||||
#cfile, dfile = f'{path}/configs/{conf}', f'{path}/output/{tag}.csv'
|
#cfile, dfile = f'{path}/configs/{conf}', f'{path}/output/{tag}.csv'
|
||||||
cfile, dfile = f'{conf}', f'{path}/output/{tag}.csv'
|
cfile, dfile = f'{conf}', f'{path}/output/{tag}.csv'
|
||||||
conf, df = read_json(cfile), read_csv(dfile)
|
conf, df = read_json(cfile), read_csv(dfile)
|
||||||
simtype = conf["stream_settings"]["path"].split("/")[1].split("_")[0]
|
# simtype = conf["stream_settings"]["path"].split("/")[1].split("_")[0]
|
||||||
|
simtype = conf["stream_settings"]["path"].split("_")[0].strip()
|
||||||
view2fin = compute_view_finalisation_times(df, conf, oprefix, simtype, tag, plot=False)
|
view2fin = compute_view_finalisation_times(df, conf, oprefix, simtype, tag, plot=False)
|
||||||
|
print(f'SIM:{simtype}', view2fin)
|
||||||
if not view2fin: # < 2 views
|
if not view2fin: # < 2 views
|
||||||
continue
|
continue
|
||||||
if simtype == "tree":
|
if simtype == "tree":
|
||||||
|
@ -114,6 +131,8 @@ def compute_view_times(path, oprefix, otype):
|
||||||
nwsize2vfins[num_nodes] = [(simtype, max_depth, view2fin, tag)]
|
nwsize2vfins[num_nodes] = [(simtype, max_depth, view2fin, tag)]
|
||||||
return nwsize2vfins
|
return nwsize2vfins
|
||||||
|
|
||||||
|
|
||||||
|
# plot the view times, add log plots for comparison
|
||||||
def plot_view_times(nwsize2vfins, simtype, oprefix, otype):
|
def plot_view_times(nwsize2vfins, simtype, oprefix, otype):
|
||||||
logbands = {}
|
logbands = {}
|
||||||
logbands[simtype] = {}
|
logbands[simtype] = {}
|
||||||
|
@ -166,6 +185,8 @@ def plot_view_times(nwsize2vfins, simtype, oprefix, otype):
|
||||||
plt.close()
|
plt.close()
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
# plot tree vs branch against the number of nodes; works only when #tree sims = # branch sims
|
||||||
def plot_tree_vs_branch(tree, branch, oprefix):
|
def plot_tree_vs_branch(tree, branch, oprefix):
|
||||||
|
|
||||||
print(tree, branch)
|
print(tree, branch)
|
||||||
|
@ -202,6 +223,7 @@ def plot_tree_vs_branch(tree, branch, oprefix):
|
||||||
|
|
||||||
app = typer.Typer()
|
app = typer.Typer()
|
||||||
|
|
||||||
|
|
||||||
@app.command()
|
@app.command()
|
||||||
def view(ctx: typer.Context,
|
def view(ctx: typer.Context,
|
||||||
data_file: Path = typer.Option("config.json",
|
data_file: Path = typer.Option("config.json",
|
||||||
|
@ -219,6 +241,7 @@ def view(ctx: typer.Context,
|
||||||
conf, df = read_json(config_file), read_csv(data_file)
|
conf, df = read_json(config_file), read_csv(data_file)
|
||||||
compute_view_finalisation_times(df, conf, oprefix, simtype, tag, plot=True)
|
compute_view_finalisation_times(df, conf, oprefix, simtype, tag, plot=True)
|
||||||
|
|
||||||
|
|
||||||
@app.command()
|
@app.command()
|
||||||
def views(ctx: typer.Context,
|
def views(ctx: typer.Context,
|
||||||
path: Path = typer.Option("../",
|
path: Path = typer.Option("../",
|
||||||
|
@ -241,8 +264,9 @@ def views(ctx: typer.Context,
|
||||||
|
|
||||||
plot_tree_vs_branch(tree, branch, oprefix)
|
plot_tree_vs_branch(tree, branch, oprefix)
|
||||||
|
|
||||||
|
|
||||||
@app.command()
|
@app.command()
|
||||||
def other_commands():
|
def test():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue