From b6bddbfae22b63f9ce4b008c11cc88df8b8f0c24 Mon Sep 17 00:00:00 2001 From: elsid Date: Wed, 23 Feb 2022 01:56:55 +0100 Subject: [PATCH 1/2] Support regexp_match for hist_threshold and hist --- scripts/osg_stats.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/scripts/osg_stats.py b/scripts/osg_stats.py index 275e70dcff..d74df94a5c 100755 --- a/scripts/osg_stats.py +++ b/scripts/osg_stats.py @@ -19,7 +19,8 @@ import re @click.option('--print_keys', is_flag=True, help='Print a list of all present keys in the input file.') @click.option('--regexp_match', is_flag=True, - help='Use all metric that match given key. Can be used with stats and timeseries.') + help='Use all metric that match given key. ' + 'Can be used with stats, timeseries, commulative_timeseries, hist, hist_threshold') @click.option('--timeseries', type=str, multiple=True, help='Show a graph for given metric over time.') @click.option('--commulative_timeseries', type=str, multiple=True, @@ -72,14 +73,18 @@ def main(print_keys, regexp_match, timeseries, hist, hist_ratio, stdev_hist, plo if print_keys: for v in keys: print(v) + def matching_keys(patterns): + if regexp_match: + return [key for pattern in patterns for key in keys if re.search(pattern, key)] + return keys if timeseries: - draw_timeseries(sources=frames, keys=matching_keys(keys, timeseries, regexp_match), add_sum=timeseries_sum, + draw_timeseries(sources=frames, keys=matching_keys(timeseries), add_sum=timeseries_sum, begin_frame=begin_frame, end_frame=end_frame) if commulative_timeseries: - draw_commulative_timeseries(sources=frames, keys=matching_keys(keys, commulative_timeseries, regexp_match), add_sum=commulative_timeseries_sum, + draw_commulative_timeseries(sources=frames, keys=matching_keys(commulative_timeseries), add_sum=commulative_timeseries_sum, begin_frame=begin_frame, end_frame=end_frame) if hist: - draw_hists(sources=frames, keys=hist) + draw_hists(sources=frames, keys=matching_keys(hist)) if hist_ratio: draw_hist_ratio(sources=frames, pairs=hist_ratio) if stdev_hist: @@ -87,9 +92,9 @@ def main(print_keys, regexp_match, timeseries, hist, hist_ratio, stdev_hist, plo if plot: draw_plots(sources=frames, plots=plot) if stats: - print_stats(sources=frames, keys=matching_keys(keys, stats, regexp_match), stats_sum=stats_sum, precision=precision) + print_stats(sources=frames, keys=matching_keys(stats), stats_sum=stats_sum, precision=precision) if hist_threshold: - draw_hist_threshold(sources=frames, keys=hist_threshold, begin_frame=begin_frame, + draw_hist_threshold(sources=frames, keys=matching_keys(hist_threshold), begin_frame=begin_frame, threshold_name=threshold_name, threshold_value=threshold_value) matplotlib.pyplot.show() @@ -145,12 +150,6 @@ def collect_unique_keys(sources): return sorted(result) -def matching_keys(keys, patterns, regexp_match): - if regexp_match: - return { key for pattern in patterns for key in keys if re.search(pattern, key) } - return keys - - def draw_timeseries(sources, keys, add_sum, begin_frame, end_frame): fig, ax = matplotlib.pyplot.subplots() x = numpy.array(range(begin_frame, end_frame)) From 5f71afa274a896a568b206593906dbefad48df86 Mon Sep 17 00:00:00 2001 From: elsid Date: Wed, 23 Feb 2022 01:57:37 +0100 Subject: [PATCH 2/2] Fix matlab deprecation warning scripts/osg_stats.py:163: MatplotlibDeprecationWarning: The set_window_title function was deprecated in Matplotlib 3.4 and will be removed two minor releases later. Use manager.set_window_title or GUI-specific methods instead. fig.canvas.set_window_title('timeseries') --- scripts/osg_stats.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/osg_stats.py b/scripts/osg_stats.py index d74df94a5c..cc4314cd04 100755 --- a/scripts/osg_stats.py +++ b/scripts/osg_stats.py @@ -160,7 +160,7 @@ def draw_timeseries(sources, keys, add_sum, begin_frame, end_frame): ax.plot(x, numpy.sum(list(frames[k] for k in keys), axis=0), label=f'sum:{name}') ax.grid(True) ax.legend() - fig.canvas.set_window_title('timeseries') + fig.canvas.manager.set_window_title('timeseries') def draw_commulative_timeseries(sources, keys, add_sum, begin_frame, end_frame): @@ -173,7 +173,7 @@ def draw_commulative_timeseries(sources, keys, add_sum, begin_frame, end_frame): ax.plot(x, numpy.cumsum(numpy.sum(list(frames[k] for k in keys), axis=0)), label=f'sum:{name}') ax.grid(True) ax.legend() - fig.canvas.set_window_title('commulative_timeseries') + fig.canvas.manager.set_window_title('commulative_timeseries') def draw_hists(sources, keys): @@ -189,7 +189,7 @@ def draw_hists(sources, keys): ax.set_xticks(bins) ax.grid(True) ax.legend() - fig.canvas.set_window_title('hists') + fig.canvas.manager.set_window_title('hists') def draw_hist_ratio(sources, pairs): @@ -205,7 +205,7 @@ def draw_hist_ratio(sources, pairs): ax.set_xticks(bins) ax.grid(True) ax.legend() - fig.canvas.set_window_title('hists_ratio') + fig.canvas.manager.set_window_title('hists_ratio') def draw_stdev_hists(sources, stdev_hists): @@ -224,7 +224,7 @@ def draw_stdev_hists(sources, stdev_hists): ax.set_xticks(bins) ax.grid(True) ax.legend() - fig.canvas.set_window_title('stdev_hists') + fig.canvas.manager.set_window_title('stdev_hists') def draw_plots(sources, plots): @@ -249,7 +249,7 @@ def draw_plots(sources, plots): ) ax.grid(True) ax.legend() - fig.canvas.set_window_title('plots') + fig.canvas.manager.set_window_title('plots') def print_stats(sources, keys, stats_sum, precision): @@ -285,7 +285,7 @@ def draw_hist_threshold(sources, keys, begin_frame, threshold_name, threshold_va ax.xaxis.set_major_formatter(matplotlib.pyplot.FixedFormatter(numbers)) ax.grid(True) ax.legend() - fig.canvas.set_window_title(f'hist_threshold:{name}') + fig.canvas.manager.set_window_title(f'hist_threshold:{name}') def filter_not_none(values):