<s> import collections <EOL> import json <EOL> from rally . common import objects <EOL> from rally . common . plugin import plugin <EOL> from rally . task . processing import charts <EOL> from rally . ui import utils as ui_utils <EOL> def _process_scenario ( data , pos ) : <EOL> main_area = charts . MainStackedAreaChart ( data [ "<STR_LIT:info>" ] ) <EOL> main_hist = charts . MainHistogramChart ( data [ "<STR_LIT:info>" ] ) <EOL> main_stat = charts . MainStatsTable ( data [ "<STR_LIT:info>" ] ) <EOL> load_profile = charts . LoadProfileChart ( data [ "<STR_LIT:info>" ] ) <EOL> atomic_pie = charts . AtomicAvgChart ( data [ "<STR_LIT:info>" ] ) <EOL> atomic_area = charts . AtomicStackedAreaChart ( data [ "<STR_LIT:info>" ] ) <EOL> atomic_hist = charts . AtomicHistogramChart ( data [ "<STR_LIT:info>" ] ) <EOL> errors = [ ] <EOL> output_errors = [ ] <EOL> additive_output_charts = [ ] <EOL> complete_output = [ ] <EOL> for idx , itr in enumerate ( data [ "<STR_LIT>" ] ) : <EOL> if itr [ "<STR_LIT:error>" ] : <EOL> typ , msg , trace = itr [ "<STR_LIT:error>" ] <EOL> errors . append ( { "<STR_LIT>" : idx , <EOL> "<STR_LIT:type>" : typ , "<STR_LIT:message>" : msg , "<STR_LIT>" : trace } ) <EOL> for i , additive in enumerate ( itr [ "<STR_LIT>" ] [ "<STR_LIT>" ] ) : <EOL> try : <EOL> additive_output_charts [ i ] . add_iteration ( additive [ "<STR_LIT:data>" ] ) <EOL> except IndexError : <EOL> chart_cls = plugin . Plugin . get ( additive [ "<STR_LIT>" ] ) <EOL> chart = chart_cls ( <EOL> data [ "<STR_LIT:info>" ] , title = additive [ "<STR_LIT:title>" ] , <EOL> description = additive . get ( "<STR_LIT:description>" , "<STR_LIT>" ) , <EOL> label = additive . get ( "<STR_LIT:label>" , "<STR_LIT>" ) , <EOL> axis_label = additive . get ( "<STR_LIT>" , <EOL> "<STR_LIT>" ) ) <EOL> chart . add_iteration ( additive [ "<STR_LIT:data>" ] ) <EOL> additive_output_charts . append ( chart ) <EOL> complete_charts = [ ] <EOL> for complete in itr [ "<STR_LIT>" ] [ "<STR_LIT>" ] : <EOL> complete_chart = dict ( complete ) <EOL> chart_cls = plugin . Plugin . get ( complete_chart . pop ( "<STR_LIT>" ) ) <EOL> complete_chart [ "<STR_LIT>" ] = chart_cls . widget <EOL> complete_charts . append ( complete_chart ) <EOL> complete_output . append ( complete_charts ) <EOL> for chart in ( main_area , main_hist , main_stat , load_profile , <EOL> atomic_pie , atomic_area , atomic_hist ) : <EOL> chart . add_iteration ( itr ) <EOL> kw = data [ "<STR_LIT:key>" ] [ "<STR_LIT>" ] <EOL> cls , method = data [ "<STR_LIT:key>" ] [ "<STR_LIT:name>" ] . split ( "<STR_LIT:.>" ) <EOL> additive_output = [ chart . render ( ) for chart in additive_output_charts ] <EOL> iterations_count = data [ "<STR_LIT:info>" ] [ "<STR_LIT>" ] <EOL> return { <EOL> "<STR_LIT>" : cls , <EOL> "<STR_LIT>" : method , <EOL> "<STR_LIT>" : str ( pos ) , <EOL> "<STR_LIT:name>" : method + ( pos and "<STR_LIT>" % ( pos + <NUM_LIT:1> ) or "<STR_LIT>" ) , <EOL> "<STR_LIT>" : kw [ "<STR_LIT>" ] [ "<STR_LIT:type>" ] , <EOL> "<STR_LIT>" : json . dumps ( { data [ "<STR_LIT:key>" ] [ "<STR_LIT:name>" ] : [ kw ] } , indent = <NUM_LIT:2> ) , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : main_area . render ( ) , <EOL> "<STR_LIT>" : [ ( "<STR_LIT:success>" , ( data [ "<STR_LIT:info>" ] [ "<STR_LIT>" ] <EOL> - len ( errors ) ) ) , <EOL> ( "<STR_LIT>" , len ( errors ) ) ] , <EOL> "<STR_LIT>" : main_hist . render ( ) } , <EOL> "<STR_LIT>" : load_profile . render ( ) , <EOL> "<STR_LIT>" : { "<STR_LIT>" : atomic_hist . render ( ) , <EOL> "<STR_LIT>" : atomic_area . render ( ) , <EOL> "<STR_LIT>" : atomic_pie . render ( ) } , <EOL> "<STR_LIT>" : main_stat . render ( ) , <EOL> "<STR_LIT>" : additive_output , <EOL> "<STR_LIT>" : complete_output , <EOL> "<STR_LIT>" : output_errors , <EOL> "<STR_LIT>" : errors , <EOL> "<STR_LIT>" : data [ "<STR_LIT:info>" ] [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : data [ "<STR_LIT:info>" ] [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : data [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : all ( [ s [ "<STR_LIT:success>" ] for s in data [ "<STR_LIT>" ] ] ) , <EOL> "<STR_LIT>" : iterations_count , <EOL> } <EOL> def _process_tasks ( tasks_results ) : <EOL> tasks = [ ] <EOL> source_dict = collections . defaultdict ( list ) <EOL> position = collections . defaultdict ( lambda : - <NUM_LIT:1> ) <EOL> for scenario in tasks_results : <EOL> name = scenario [ "<STR_LIT:key>" ] [ "<STR_LIT:name>" ] <EOL> position [ name ] += <NUM_LIT:1> <EOL> source_dict [ name ] . append ( scenario [ "<STR_LIT:key>" ] [ "<STR_LIT>" ] ) <EOL> tasks . append ( _process_scenario ( scenario , position [ name ] ) ) <EOL> source = json . dumps ( source_dict , indent = <NUM_LIT:2> , sort_keys = True ) <EOL> return source , sorted ( tasks , key = lambda r : ( r [ "<STR_LIT>" ] , r [ "<STR_LIT>" ] , <EOL> int ( r [ "<STR_LIT>" ] ) ) ) <EOL> def _extend_results ( results ) : <EOL> """<STR_LIT>""" <EOL> extended_results = [ ] <EOL> for result in results : <EOL> generic = { "<STR_LIT:id>" : None , <EOL> "<STR_LIT>" : None , <EOL> "<STR_LIT:key>" : result [ "<STR_LIT:key>" ] , <EOL> "<STR_LIT:data>" : { "<STR_LIT>" : result [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : result [ "<STR_LIT:result>" ] , <EOL> "<STR_LIT>" : result [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : result [ "<STR_LIT>" ] } , <EOL> "<STR_LIT>" : None , <EOL> "<STR_LIT>" : None } <EOL> extended_results . extend ( <EOL> objects . Task . extend_results ( [ generic ] ) ) <EOL> return extended_results <EOL> def plot ( tasks_results , include_libs = False ) : <EOL> extended_results = _extend_results ( tasks_results ) <EOL> template = ui_utils . get_template ( "<STR_LIT>" ) <EOL> source , data = _process_tasks ( extended_results ) <EOL> return template . render ( source = json . dumps ( source ) , data = json . dumps ( data ) , <EOL> include_libs = include_libs ) </s>
