Index: lnt/server/ui/templates/v4_graph.html =================================================================== --- lnt/server/ui/templates/v4_graph.html +++ lnt/server/ui/templates/v4_graph.html @@ -157,6 +157,11 @@
Mean() as Aggregation Function | ++ |
Hide Line Plot: | Index: lnt/server/ui/views.py =================================================================== --- lnt/server/ui/views.py +++ lnt/server/ui/views.py @@ -7,6 +7,7 @@ import json import flask +from flask import session from flask import abort from flask import current_app from flask import g @@ -505,9 +506,26 @@ from lnt.external.stats import stats as ext_stats ts = request.get_testsuite() + switch_min_mean_local = False + if 'switch_min_mean_session' not in session: + session['switch_min_mean_session'] = False # Parse the view options. options = {} + options['min_mean_checkbox'] = "min()" + if 'submit' in request.args: # user pressed a button + if 'switch_min_mean' in request.args: # user checked mean() checkbox + session['switch_min_mean_session'] = options['switch_min_mean'] = \ + bool(request.args.get('switch_min_mean')) + switch_min_mean_local = session['switch_min_mean_session'] + else: # mean() check box is not checked + session['switch_min_mean_session'] = options['switch_min_mean'] = \ + bool(request.args.get('switch_min_mean')) + switch_min_mean_local = session['switch_min_mean_session'] + else: # new page was loaded by clicking link, not submit button + options['switch_min_mean'] = switch_min_mean_local = \ + session['switch_min_mean_session'] + options['hide_lineplot'] = bool(request.args.get('hide_lineplot')) show_lineplot = not options['hide_lineplot'] options['show_mad'] = show_mad = bool(request.args.get('show_mad')) @@ -769,8 +787,12 @@ values = [v*normalize_by for v in data] aggregation_fn = min + + if switch_min_mean_local: + aggregation_fn = lnt.util.stats.agg_mean if field.bigger_is_better: aggregation_fn = max + agg_value, agg_index = \ aggregation_fn((value, index) for (index, value) in enumerate(values)) Index: lnt/util/stats.py =================================================================== --- lnt/util/stats.py +++ lnt/util/stats.py @@ -25,6 +25,19 @@ else: return None +# Aggregation function in views.py receives input via enumerate and produces a tuple +def agg_mean(pairs): + if not pairs: + return (None,None) + my_sum = 0.0 + counter = 0 + for item in pairs: + my_sum += item[0] + counter += 1 + if counter > 0: + return (my_sum/counter, 0) + return (None, None) + def median(l): if not l: Index: tests/server/ui/V4Pages.py =================================================================== --- tests/server/ui/V4Pages.py +++ tests/server/ui/V4Pages.py @@ -424,18 +424,21 @@ # Check some variations of the daily report work. check_code(client, '/v4/compile/daily_report/2014/6/5?day_start=16') check_code(client, '/v4/compile/daily_report/2014/6/4') - + check_redirect(client, '/v4/nts/regressions/new_from_graph/1/1/1/1', '/v4/nts/regressions/1') check_code(client, '/v4/nts/regressions/') check_code(client, '/v4/nts/regressions/?machine_filter=machine2') check_code(client, '/v4/nts/regressions/?machine_filter=machine0') check_code(client, '/v4/nts/regressions/1') - - check_json(client, '/v4/nts/regressions/1?json=True') - - + check_json(client, '/v4/nts/regressions/1?json=True') + # Make sure the new option does not break anything + check_code(client, '/db_default/v4/nts/graph?switch_min_mean=yes&plot.0=1.3.2&submit=Update') + check_json(client, 'db_default/v4/nts/graph?switch_min_mean=yes&plot.0=1.3.2&json=true&submit=Update') + check_code(client, '/db_default/v4/nts/graph?switch_min_mean=yes&plot.0=1.3.2') + check_json(client, 'db_default/v4/nts/graph?switch_min_mean=yes&plot.0=1.3.2&json=true') + if __name__ == '__main__': main() Index: tests/server/ui/statsTester.py =================================================================== --- /dev/null +++ tests/server/ui/statsTester.py @@ -0,0 +1,33 @@ +# Perform basic sanity checking of the V4 UI pages. +# +# create temporary instance +# Cleanup temporary directory in case one remained from a previous run - also +# see PR9904. +# RUN: rm -rf %t.instance +# RUN: python %{shared_inputs}/create_temp_instance.py \ +# RUN: %s %{shared_inputs}/SmallInstance %t.instance \ +# RUN: %S/Inputs/V4Pages_extra_records.sql +# +# RUN: python %s %t.instance + +import logging + +import lnt.util.stats as stats + +logging.basicConfig(level=logging.DEBUG) + +def test_agg_mean(values): + if values == None: + return stats.agg_mean(None) + agg_value, agg_index = stats.agg_mean((value, index) for (index, value) in enumerate(values)) + return (agg_value, agg_index) + +def main() : + test_list = [1,2,3,4,6] + assert(test_agg_mean(test_list) == (3.2,0)) + assert(test_agg_mean([]) == None, None) + assert(test_agg_mean(None)) + + +if __name__ == '__main__': + main() |