def get_data(filter): try: sc = results.get_scalars(filter, include_attrs=True) iv = results.get_itervars(filter) ra = results.get_runattrs(filter) except ValueError as e: plot.set_warning("Error while querying results: " + str(e)) exit(1) df = pd.concat([sc, iv, ra]) df["value"] = pd.to_numeric(df["value"], errors="ignore") df = pd.pivot_table(df, columns="name", index="runID", dropna=False, aggfunc=aggfunc) return df
from omnetpp.scave import results, chart, utils, plot # get chart properties props = chart.get_properties() utils.preconfigure_plot(props) # collect parameters for query filter_expression = props["filter"] # query vector data into a data frame try: df = results.get_histograms(filter_expression, include_attrs=True, include_itervars=True) except ValueError as e: plot.set_warning("Error while querying results: " + str(e)) exit(1) if df.empty: plot.set_warning("The result filter returned no data.") exit(1) # plot utils.plot_histograms(df, props) utils.postconfigure_plot(props) utils.export_image_if_needed(props) utils.export_data_if_needed(df, props)
props = chart.get_properties() utils.preconfigure_plot(props) stats = results.get_statistics(props["filter"], include_attrs=True, include_runattrs=True, include_itervars=True) hists = results.get_histograms(props["filter"], include_attrs=True, include_runattrs=True, include_itervars=True) df = pd.concat([stats, hists], sort=False) if df.empty: plot.set_warning("The result filter returned no data.") exit(1) title, legend = utils.extract_label_columns(df) df.sort_values(by=[l for i, l in legend], axis='index', inplace=True) ax = plt.gca() # This is how much of the standard deviation will give the 25th and 75th # percentiles, assuming normal distribution. # >>> math.sqrt(2) * scipy.special.erfinv(0.5) coeff = 0.6744897501960817 boxes = [(r.min, r.mean - r.stddev * coeff, r.mean, r.mean + r.stddev * coeff, r.max) for r in df.itertuples(index=False) if r.count > 0]
props = chart.get_properties() utils.preconfigure_plot(props) # collect parameters for query filter_expression = props["filter"] xaxis_itervar = props["xaxis_itervar"] iso_itervars = utils.split(props["iso_itervar"]) # query data into a data frame try: df = results.get_scalars(filter_expression, include_runattrs=True, include_attrs=True, include_itervars=True) except ValueError as e: plot.set_warning("Error while querying results: " + str(e)) exit(1) if df.empty: plot.set_warning("The result filter returned no data.") exit(1) if not xaxis_itervar and not iso_itervars: print( "The 'Itervar for X Axis' and 'Itervar for iso line' options were not set in the dialog, inferring them from the data.." ) xaxis_itervar, iso_itervar = utils.pick_two_columns(df) iso_itervars = [iso_itervar] if iso_itervar else [] print("X axis: " + xaxis_itervar + " iso lines: " + ",".join(iso_itervars)) if xaxis_itervar:
def assert_columns_exist(df, cols): for c in cols: if c not in df: plot.set_warning("Expected column missing from DataFrame: " + c) exit(1)
filter_expression = props["filter"] xaxis_itervar = props["xaxis_itervar"] iso_itervar = props["iso_itervar"] # query data into a data frame df = results.get_scalars(filter_expression, include_attrs=True, include_itervars=True) if not xaxis_itervar and not iso_itervar: print( "The X Axis and Iso Line options were not set in the dialog, inferring them from the data.." ) xaxis_itervar, iso_itervar = utils.pick_two_columns(df) if not iso_itervar or not iso_itervar: plot.set_warning( "Please set the X Axis and Iso Lines options in the dialog!") exit(1) df[xaxis_itervar] = pd.to_numeric(df[xaxis_itervar], errors="ignore") df[iso_itervar] = pd.to_numeric(df[iso_itervar], errors="ignore") if df.empty: plot.set_warning("Select scalars for the Y axis in the Properties dialog") exit(1) unique_names = df["name"].unique() if len(unique_names) != 1: plot.set_warning("Scalar names should be unique") exit(1)
# get chart properties props = chart.get_properties() utils.preconfigure_plot(props) # collect parameters for query filter_expression = props["filter"] # query scalar data into dataframe try: df = results.get_scalars(filter_expression, include_attrs=True, include_itervars=True, include_runattrs=True) except ValueError as e: plot.set_warning("Error while querying results: " + str(e)) exit(1) if df.empty: plot.set_warning("The result filter returned no data.") exit(1) groups = props["groups"].split(",") series = props["series"].split(",") if not groups[0] and not series[0]: print( "The Groups and Series options were not set in the dialog, inferring them from the data." ) g, s = ("module", "name") if len(df) == 1 else utils.pick_two_columns(df) groups, series = [g], [s]
# get chart properties props = chart.get_properties() utils.preconfigure_plot(props) # collect parameters for query filter_expression = props["filter"] # query scalar data into dataframe df = results.get_scalars(filter_expression, include_attrs=True, include_itervars=True, include_runattrs=True) if df.empty: plot.set_warning("The result filter returned no data.") exit(1) groups = props["groups"].split(",") series = props["series"].split(",") if not groups[0] and not series[0]: print( "The Groups and Series options were not set in the dialog, inferring them from the data." ) g, s = ("module", "name") if len(df) == 1 else utils.pick_two_columns(df) if not g or not s: plot.set_warning( "Please set the Groups and Series options in the dialog!") exit(1) groups, series = [g], [s]
props = chart.get_properties() utils.preconfigure_plot(props) # collect parameters for query filter_expression = props["filter"] xaxis_itervar = props["xaxis_itervar"] iso_itervar = props["iso_itervar"] # query data into a data frame df = results.get_scalars(filter_expression, include_runattrs=True, include_attrs=True, include_itervars=True) if df.empty: plot.set_warning("The result filter returned no data.") exit(1) if not xaxis_itervar and not iso_itervar: print( "The X Axis and Iso Line options were not set in the dialog, inferring them from the data.." ) xaxis_itervar, iso_itervar = utils.pick_two_columns(df) if not iso_itervar or not iso_itervar: plot.set_warning( "Please set the X Axis and Iso Lines options in the dialog!") exit(1) utils.assert_columns_exist(df, [xaxis_itervar, iso_itervar]) df[xaxis_itervar] = pd.to_numeric(df[xaxis_itervar], errors="ignore")
# get chart properties props = chart.get_properties() utils.preconfigure_plot(props) # collect parameters for query filter_expression = props["filter"] xaxis_itervar = props["xaxis_itervar"] yaxis_itervar = props["yaxis_itervar"] # query data into a data frame df = results.get_scalars(filter_expression, include_attrs=True, include_itervars=True) if df.empty: plot.set_warning("The result filter returned no data.") exit(1) if not xaxis_itervar and not yaxis_itervar: print( "The X Axis and Y Axis options were not set in the dialog, inferring them from the data.." ) xaxis_itervar, yaxis_itervar = utils.pick_two_columns(df) if not xaxis_itervar or not yaxis_itervar: plot.set_warning( "Please set the X Axis and Y Axis options in the dialog!") exit(1) utils.assert_columns_exist(df, [xaxis_itervar, yaxis_itervar]) df[xaxis_itervar] = pd.to_numeric(df[xaxis_itervar], errors="ignore")
# get chart properties props = chart.get_properties() utils.preconfigure_plot(props) # collect parameters for query filter_expression = props["filter"] # query scalar data into dataframe try: df = results.get_scalars(filter_expression, include_attrs=True, include_itervars=True, include_runattrs=True) except ValueError as e: plot.set_warning("Error while querying results: " + str(e)) exit(1) if df.empty: plot.set_warning("The result filter returned no data.") exit(1) # determine "groups" and "series" for pivoting, and check them groups = utils.split(props["groups"]) series = utils.split(props["series"]) if not groups and not series: print( "The Groups and Series options were not set in the dialog, inferring them from the data." ) g, s = ("module", "name") if len(df) == 1 else utils.pick_two_columns(df)
# get chart properties props = chart.get_properties() utils.preconfigure_plot(props) # collect parameters for query filter_expression = props["filter"] xaxis_itervar = props["xaxis_itervar"] yaxis_itervar = props["yaxis_itervar"] # query data into a data frame try: df = results.get_scalars(filter_expression, include_attrs=True, include_itervars=True) except ValueError as e: plot.set_warning("Error while querying results: " + str(e)) exit(1) if df.empty: plot.set_warning("The result filter returned no data.") exit(1) if not xaxis_itervar and not yaxis_itervar: print( "The X Axis and Y Axis options were not set in the dialog, inferring them from the data.." ) xaxis_itervar, yaxis_itervar = utils.pick_two_columns(df) if not xaxis_itervar or not yaxis_itervar: plot.set_warning( "Please set both the X Axis and Y Axis options in the dialog - or neither, for automatic selection!" )
filter_expression = props["filter"] xaxis_itervar = props["xaxis_itervar"] yaxis_itervar = props["yaxis_itervar"] # query data into a data frame df = results.get_scalars(filter_expression, include_attrs=True, include_itervars=True) if not xaxis_itervar and not yaxis_itervar: print( "The X Axis and Y Axis options were not set in the dialog, inferring them from the data.." ) xaxis_itervar, yaxis_itervar = utils.pick_two_columns(df) if not xaxis_itervar or not yaxis_itervar: plot.set_warning( "Please set the X Axis and Y Axis options in the dialog!") exit(1) df[xaxis_itervar] = pd.to_numeric(df[xaxis_itervar], errors="ignore") df[yaxis_itervar] = pd.to_numeric(df[yaxis_itervar], errors="ignore") title_col, legend_cols = utils.extract_label_columns(df) title = str(list(df[title_col])[0]) if title_col else None unique_names = df["name"].unique() if len(unique_names) != 1: plot.set_warning("Scalar names should be unique") exit(1)
# query scalar data into dataframe df = results.get_scalars(filter_expression, include_attrs=True, include_itervars=True, include_runattrs=True) groups = props["groups"].split(",") series = props["series"].split(",") if not groups[0] and not series[0]: print( "The Groups and Series options were not set in the dialog, inferring them from the data." ) g, s = utils.pick_two_columns(df) if not g or not s: plot.set_warning( "Please set the Groups and Series options in the dialog!") exit(1) groups, series = [g], [s] for c in groups + series: df[c] = pd.to_numeric(df[c], errors="ignore") df.sort_values(by=groups + series, axis='index', inplace=True) names = utils.get_names_for_title(df, props) df = pd.pivot_table(df, index=groups, columns=series, values='value') utils.plot_bars(df, props, names) utils.postconfigure_plot(props)