Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jupyter Notebook generation #74

Merged
merged 25 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
3adcb98
Notebook generated with --notebook my_nb.ipynb option
Simcornelis Apr 2, 2024
93036b2
Merge branch 'tbarbette:master' into master
Simcornelis Apr 16, 2024
8c3b36a
Extract graph choice & change to const
Simcornelis Apr 22, 2024
58169e6
Execute notebooks
Simcornelis Apr 22, 2024
029c5cc
Setup requirements & jinja2 template
Simcornelis Apr 22, 2024
02c88c6
Add decide_graph_type
tbarbette Apr 22, 2024
760ccba
Merge pull request #1 from tbarbette/simon
Simcornelis May 1, 2024
aea53d3
Cell tags for graph types
Simcornelis May 19, 2024
e8617f7
Multiple x and y test & no template config constants
Simcornelis Jun 17, 2024
a8f1996
Split grapher & change dependies
Simcornelis Jun 17, 2024
a3c5c21
Merge branch 'master' of https://github.com/tbarbette/npf
Simcornelis Jul 23, 2024
cc972d6
Fix some arguments of decide_graph_type call
Simcornelis Jul 25, 2024
603f80d
Support other graph types & series/legend var decision
Simcornelis Aug 1, 2024
f8f53c9
Advanced graphs & multi output variable iperf test
Simcornelis Aug 4, 2024
e9437ed
Merge branch 'master' of https://github.com/tbarbette/npf
Simcornelis Aug 4, 2024
be043d9
No lstrip & lowercase py files & start test fix
Simcornelis Aug 27, 2024
d263721
execution arguments nb, force, update, no exec
Simcornelis Aug 27, 2024
68e8e42
Merge branch 'master' of https://github.com/tbarbette/npf
Simcornelis Aug 27, 2024
aa5c9f8
fix integration tests
Simcornelis Aug 27, 2024
c5475ea
fix graph choice in notebook
Simcornelis Aug 28, 2024
686d043
graph import
Simcornelis Aug 28, 2024
5c41384
Update 04-iperf.npf
tbarbette Aug 28, 2024
779f1ad
force Graph.py to graph.py
Simcornelis Aug 28, 2024
673fcdf
custom template path and kernel options
Simcornelis Aug 28, 2024
0c86b1a
options for kernel name
Simcornelis Aug 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions npf/graph.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
from npf.types.dataset import convert_to_xyeb
from npf.variable import is_numeric, get_numeric
import numpy as np

class Graph:
"""
This is a structure holder for data to build a graph
"""
def __init__(self, grapher:'Grapher'):
self.grapher = grapher
self.subtitle = None
self.data_types = None

def statics(self):
return dict([(var,list(values)[0]) for var,values in self.vars_values.items() if len(values) == 1])

def dyns(self):
return [var for var,values in self.vars_values.items() if len(values) > 1]

#Convert the series into the XYEB format (see types.dataset)
def dataset(self, kind=None):
if not self.data_types:

self.data_types = convert_to_xyeb(
datasets = self.series,
run_list = self.vars_all,
key = self.key,
max_series=self.grapher.config('graph_max_series'),
do_x_sort=self.do_sort,
series_sort=self.grapher.config('graph_series_sort'),
options=self.grapher.options,
statics=self.statics(),
y_group=self.grapher.configdict('graph_y_group'),
color=[get_numeric(v) for v in self.grapher.configlist('graph_color')],
kind=kind
)

return self.data_types

# Divide all series by the first one, making a percentage of difference
@staticmethod
def series_prop(series, prop, exclusions = []):
if len(series) == 1:
raise Exception("Cannot make proportional series with only one serie !")
newseries = []
if not is_numeric(prop):
prop=1
if len(series[0]) < 3:
raise Exception("Malformed serie !")
base_results=series[0][2]
for i, (script, build, all_results) in enumerate(series[1:]):
new_results={}
for run,run_results in all_results.items():
if not run in base_results:
print(run,"FIXME is not in base")
continue

for result_type, results in run_results.items():
if not result_type in base_results[run]:
run_results[result_type] = None
print(result_type, "not in base for %s" % run)
continue
base = base_results[run][result_type]
if len(base) > len(results):
base = base[:len(results)]
elif len(results) > len(base):
results = results[:len(base)]
base = np.array(base)
results = np.array(results)
if result_type not in exclusions:
f = np.nonzero(base)
results = (results[f] / base[f] * float(abs(prop)) + (prop if prop < 0 else 0))
run_results[result_type] = results
new_results[run] = run_results
build._pretty_name = build._pretty_name + " / " + series[0][1]._pretty_name
newseries.append((script, build, new_results))
return newseries
40 changes: 40 additions & 0 deletions npf/graph_choice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from npf import npf

# types of graphs: bar, line, boxplot, simple_bar


def decide_graph_type(config, n_values, vars_values, key, result_type, ndyn, isubplot):
graph_type = "bar"
if ndyn == 0:
graph_type = "boxplot" if n_values == 1 else "simple_bar"
elif ndyn == 1 and n_values > 2 and npf.all_num(vars_values[key]):
graph_type = "line"
graph_types = config("graph_type", [])

if len(graph_types) > 0 and (type(graph_types[0]) is tuple or type(graph_types) is tuple):
if type(graph_types) is tuple:
graph_types = dict([graph_types])
else:
graph_types = dict(graph_types)
if result_type in graph_types:
graph_type = graph_types[result_type]
elif "default" in graph_types:
graph_type = graph_types["default"]
elif "result" in graph_types:
graph_type = graph_types["result"]
else:
graph_type = "line"

else:
if type(graph_types) is str:
graph_types = [graph_types]
graph_types.extend([graph_type, "line"])
graph_type = graph_types[isubplot if isubplot < len(
graph_types) else len(graph_types) - 1]

if ndyn == 0 and graph_type == "line":
print("WARNING: Cannot graph", graph_type,
"as a line without dynamic variables")
graph_type = "simple_bar"

return graph_type
Loading
Loading