<s> import json <EOL> import numpy <EOL> import numpy . random <EOL> from datetime import datetime <EOL> from datetime import timedelta <EOL> from next . utils import utils <EOL> import matplotlib <EOL> matplotlib . use ( '<STR_LIT>' ) <EOL> MAX_SAMPLES_PER_PLOT = <NUM_LIT:100> <EOL> class AppDashboard ( object ) : <EOL> def __init__ ( self , db , ell ) : <EOL> self . db = db <EOL> self . ell = ell <EOL> def get_supported_stats ( self ) : <EOL> """<STR_LIT>""" <EOL> stat_list = [ ] <EOL> stat = { } <EOL> stat [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> stat [ '<STR_LIT:description>' ] = self . api_activity_histogram . __doc__ <EOL> stat [ '<STR_LIT>' ] = [ '<STR_LIT>' ] <EOL> stat_list . append ( stat ) <EOL> stat = { } <EOL> stat [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> stat [ '<STR_LIT:description>' ] = self . compute_duration_multiline_plot . __doc__ <EOL> stat [ '<STR_LIT>' ] = [ '<STR_LIT>' ] <EOL> stat_list . append ( stat ) <EOL> stat = { } <EOL> stat [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> stat [ '<STR_LIT:description>' ] = self . compute_duration_detailed_stacked_area_plot . __doc__ <EOL> stat [ '<STR_LIT>' ] = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> stat_list . append ( stat ) <EOL> stat = { } <EOL> stat [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> stat [ '<STR_LIT:description>' ] = self . response_time_histogram . __doc__ <EOL> stat [ '<STR_LIT>' ] = [ '<STR_LIT>' ] <EOL> stat_list . append ( stat ) <EOL> stat = { } <EOL> stat [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> stat [ '<STR_LIT:description>' ] = self . response_time_histogram . __doc__ <EOL> stat [ '<STR_LIT>' ] = [ '<STR_LIT>' ] <EOL> stat_list . append ( stat ) <EOL> return stat_list <EOL> def api_activity_histogram ( self , app_id , exp_uid , task ) : <EOL> """<STR_LIT>""" <EOL> list_of_log_dict , didSucceed , message = self . ell . get_logs_with_filter ( app_id + '<STR_LIT>' , { '<STR_LIT>' : exp_uid , '<STR_LIT>' : task } ) <EOL> from datetime import datetime <EOL> from datetime import timedelta <EOL> start_date_str , didSucceed , message = self . db . get ( '<STR_LIT>' , exp_uid , '<STR_LIT>' ) <EOL> start_date = utils . str2datetime ( start_date_str ) <EOL> numerical_timestamps = [ ( utils . str2datetime ( item [ '<STR_LIT>' ] ) - start_date ) . total_seconds ( ) for item in list_of_log_dict ] <EOL> import matplotlib . pyplot as plt <EOL> import mpld3 <EOL> fig , ax = plt . subplots ( subplot_kw = dict ( axisbg = '<STR_LIT>' ) , figsize = ( <NUM_LIT:12> , <NUM_LIT> ) ) <EOL> ax . hist ( numerical_timestamps , int ( <NUM_LIT:1> + <NUM_LIT:4> * numpy . sqrt ( len ( numerical_timestamps ) ) ) , alpha = <NUM_LIT:0.5> , color = '<STR_LIT>' ) <EOL> ax . set_frame_on ( False ) <EOL> ax . get_xaxis ( ) . set_ticks ( [ ] ) <EOL> ax . get_yaxis ( ) . set_ticks ( [ ] ) <EOL> ax . get_yaxis ( ) . set_visible ( False ) <EOL> ax . set_xlim ( <NUM_LIT:0> , max ( numerical_timestamps ) ) <EOL> plot_dict = mpld3 . fig_to_dict ( fig ) <EOL> return plot_dict <EOL> def compute_duration_multiline_plot ( self , app_id , exp_uid , task ) : <EOL> """<STR_LIT>""" <EOL> alg_list , didSucceed , message = self . db . get ( app_id + '<STR_LIT>' , exp_uid , '<STR_LIT>' ) <EOL> x_min = numpy . float ( '<STR_LIT>' ) <EOL> x_max = - numpy . float ( '<STR_LIT>' ) <EOL> y_min = numpy . float ( '<STR_LIT>' ) <EOL> y_max = - numpy . float ( '<STR_LIT>' ) <EOL> list_of_alg_dicts = [ ] <EOL> for algorithm in alg_list : <EOL> alg_id = algorithm [ '<STR_LIT>' ] <EOL> alg_uid = algorithm [ '<STR_LIT>' ] <EOL> alg_label = algorithm [ '<STR_LIT>' ] <EOL> list_of_log_dict , didSucceed , message = self . ell . get_logs_with_filter ( app_id + '<STR_LIT>' , { '<STR_LIT>' : alg_uid , '<STR_LIT>' : task } ) <EOL> list_of_log_dict = sorted ( list_of_log_dict , key = lambda item : utils . str2datetime ( item [ '<STR_LIT>' ] ) ) <EOL> x = [ ] <EOL> y = [ ] <EOL> t = [ ] <EOL> k = <NUM_LIT:0> <EOL> for item in list_of_log_dict : <EOL> k += <NUM_LIT:1> <EOL> x . append ( k ) <EOL> y . append ( item . get ( '<STR_LIT>' , <NUM_LIT:0.> ) + item . get ( '<STR_LIT>' , <NUM_LIT:0.> ) ) <EOL> t . append ( str ( item [ '<STR_LIT>' ] ) [ : - <NUM_LIT:3> ] ) <EOL> x = numpy . array ( x ) <EOL> y = numpy . array ( y ) <EOL> t = numpy . array ( t ) <EOL> num_items = len ( list_of_log_dict ) <EOL> multiplier = min ( num_items , MAX_SAMPLES_PER_PLOT ) <EOL> incr_inds = [ k * num_items / multiplier for k in range ( multiplier ) ] <EOL> max_inds = list ( numpy . argsort ( - y ) [ <NUM_LIT:0> : multiplier ] ) <EOL> final_inds = sorted ( set ( incr_inds + max_inds ) ) <EOL> x = list ( x [ final_inds ] ) <EOL> y = list ( y [ final_inds ] ) <EOL> t = list ( t [ final_inds ] ) <EOL> alg_dict = { } <EOL> alg_dict [ '<STR_LIT>' ] = alg_label <EOL> alg_dict [ '<STR_LIT:x>' ] = x <EOL> alg_dict [ '<STR_LIT:y>' ] = y <EOL> alg_dict [ '<STR_LIT:t>' ] = t <EOL> try : <EOL> x_min = min ( x_min , min ( x ) ) <EOL> x_max = max ( x_max , max ( x ) ) <EOL> y_min = min ( y_min , min ( y ) ) <EOL> y_max = max ( y_max , max ( y ) ) <EOL> except : <EOL> pass <EOL> list_of_alg_dicts . append ( alg_dict ) <EOL> return_dict = { } <EOL> return_dict [ '<STR_LIT:data>' ] = list_of_alg_dicts <EOL> return_dict [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> return_dict [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> return_dict [ '<STR_LIT>' ] = x_min <EOL> return_dict [ '<STR_LIT>' ] = x_max <EOL> return_dict [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> return_dict [ '<STR_LIT>' ] = y_min <EOL> return_dict [ '<STR_LIT>' ] = y_max <EOL> import matplotlib . pyplot as plt <EOL> import mpld3 <EOL> fig , ax = plt . subplots ( subplot_kw = dict ( axisbg = '<STR_LIT>' ) ) <EOL> for alg_dict in list_of_alg_dicts : <EOL> ax . plot ( alg_dict [ '<STR_LIT:x>' ] , alg_dict [ '<STR_LIT:y>' ] , label = alg_dict [ '<STR_LIT>' ] ) <EOL> ax . set_xlabel ( '<STR_LIT>' ) <EOL> ax . set_ylabel ( '<STR_LIT>' ) <EOL> ax . set_xlim ( [ x_min , x_max ] ) <EOL> ax . set_ylim ( [ y_min , y_max ] ) <EOL> ax . grid ( color = '<STR_LIT>' , linestyle = '<STR_LIT>' ) <EOL> ax . set_title ( task , size = <NUM_LIT> ) <EOL> legend = ax . legend ( loc = <NUM_LIT:2> , ncol = <NUM_LIT:3> , mode = "<STR_LIT>" ) <EOL> for label in legend . get_texts ( ) : <EOL> label . set_fontsize ( '<STR_LIT>' ) <EOL> plot_dict = mpld3 . fig_to_dict ( fig ) <EOL> return plot_dict <EOL> def compute_duration_detailed_stacked_area_plot ( self , app_id , exp_uid , task , alg_label , detailedDB = False ) : <EOL> """<STR_LIT>""" <EOL> alg_list , didSucceed , message = self . db . get ( app_id + '<STR_LIT>' , exp_uid , '<STR_LIT>' ) <EOL> for algorithm in alg_list : <EOL> if algorithm [ '<STR_LIT>' ] == alg_label : <EOL> alg_id = algorithm [ '<STR_LIT>' ] <EOL> alg_uid = algorithm [ '<STR_LIT>' ] <EOL> list_of_log_dict , didSucceed , message = self . ell . get_logs_with_filter ( app_id + '<STR_LIT>' , { '<STR_LIT>' : alg_uid , '<STR_LIT>' : task } ) <EOL> list_of_log_dict = sorted ( list_of_log_dict , key = lambda item : utils . str2datetime ( item [ '<STR_LIT>' ] ) ) <EOL> y = [ ] <EOL> for item in list_of_log_dict : <EOL> y . append ( item . get ( '<STR_LIT>' , <NUM_LIT:0.> ) + item . get ( '<STR_LIT>' , <NUM_LIT:0.> ) ) <EOL> y = numpy . array ( y ) <EOL> num_items = len ( list_of_log_dict ) <EOL> multiplier = min ( num_items , MAX_SAMPLES_PER_PLOT ) <EOL> incr_inds = [ k * num_items / multiplier for k in range ( multiplier ) ] <EOL> max_inds = list ( numpy . argsort ( - y ) [ <NUM_LIT:0> : multiplier ] ) <EOL> final_inds = sorted ( set ( incr_inds + max_inds ) ) <EOL> x = [ ] <EOL> t = [ ] <EOL> enqueued = [ ] <EOL> admin = [ ] <EOL> dbOverhead = [ ] <EOL> dbGet = [ ] <EOL> dbSet = [ ] <EOL> compute = [ ] <EOL> max_y_value = <NUM_LIT:0.> <EOL> min_y_value = float ( '<STR_LIT>' ) <EOL> for idx in final_inds : <EOL> item = list_of_log_dict [ idx ] <EOL> x . append ( idx + <NUM_LIT:1> ) <EOL> t . append ( str ( item . get ( '<STR_LIT>' , '<STR_LIT>' ) ) ) <EOL> _alg_duration = item . get ( '<STR_LIT>' , <NUM_LIT:0.> ) <EOL> _alg_duration_dbGet = item . get ( '<STR_LIT>' , <NUM_LIT:0.> ) <EOL> _alg_duration_dbSet = item . get ( '<STR_LIT>' , <NUM_LIT:0.> ) <EOL> _duration_enqueued = item . get ( '<STR_LIT>' , <NUM_LIT:0.> ) <EOL> _app_duration = item . get ( '<STR_LIT>' , <NUM_LIT:0.> ) <EOL> if ( _app_duration + _duration_enqueued ) > max_y_value : <EOL> max_y_value = _app_duration + _duration_enqueued <EOL> if ( _app_duration + _duration_enqueued ) < min_y_value : <EOL> min_y_value = _app_duration + _duration_enqueued <EOL> enqueued . append ( _duration_enqueued ) <EOL> admin . append ( _app_duration - _alg_duration ) <EOL> dbSet . append ( _alg_duration_dbSet ) <EOL> dbGet . append ( _alg_duration_dbGet ) <EOL> compute . append ( _alg_duration - _alg_duration_dbSet - _alg_duration_dbGet ) <EOL> try : <EOL> min_x = min ( x ) <EOL> max_x = max ( x ) <EOL> except : <EOL> min_x = <NUM_LIT:0.> <EOL> max_x = <NUM_LIT:0.> <EOL> import matplotlib . pyplot as plt <EOL> import mpld3 <EOL> fig , ax = plt . subplots ( subplot_kw = dict ( axisbg = '<STR_LIT>' ) ) <EOL> stack_coll = ax . stackplot ( x , compute , dbGet , dbSet , admin , enqueued , alpha = <NUM_LIT> ) <EOL> ax . set_xlabel ( '<STR_LIT>' ) <EOL> ax . set_ylabel ( '<STR_LIT>' ) <EOL> ax . set_xlim ( [ min_x , max_x ] ) <EOL> ax . set_ylim ( [ <NUM_LIT:0.> , max_y_value ] ) <EOL> ax . grid ( color = '<STR_LIT>' , linestyle = '<STR_LIT>' ) <EOL> ax . set_title ( alg_label + '<STR_LIT>' + task , size = <NUM_LIT> ) <EOL> proxy_rects = [ plt . Rectangle ( ( <NUM_LIT:0> , <NUM_LIT:0> ) , <NUM_LIT:1> , <NUM_LIT:1> , alpha = <NUM_LIT> , fc = pc . get_facecolor ( ) [ <NUM_LIT:0> ] ) for pc in stack_coll ] <EOL> legend = ax . legend ( proxy_rects , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , loc = <NUM_LIT:2> , ncol = <NUM_LIT:3> , mode = "<STR_LIT>" ) <EOL> for label in legend . get_texts ( ) : <EOL> label . set_fontsize ( '<STR_LIT>' ) <EOL> plot_dict = mpld3 . fig_to_dict ( fig ) <EOL> return plot_dict <EOL> def response_time_histogram ( self , app_id , exp_uid , alg_label ) : <EOL> """<STR_LIT>""" <EOL> alg_list , didSucceed , message = self . db . get ( app_id + '<STR_LIT>' , exp_uid , '<STR_LIT>' ) <EOL> for algorithm in alg_list : <EOL> if algorithm [ '<STR_LIT>' ] == alg_label : <EOL> alg_id = algorithm [ '<STR_LIT>' ] <EOL> alg_uid = algorithm [ '<STR_LIT>' ] <EOL> list_of_query_dict , didSucceed , message = self . db . get_docs_with_filter ( app_id + '<STR_LIT>' , { '<STR_LIT>' : exp_uid , '<STR_LIT>' : alg_uid } ) <EOL> t = [ ] <EOL> for item in list_of_query_dict : <EOL> try : <EOL> t . append ( item [ '<STR_LIT>' ] ) <EOL> except : <EOL> pass <EOL> import matplotlib . pyplot as plt <EOL> import mpld3 <EOL> fig , ax = plt . subplots ( subplot_kw = dict ( axisbg = '<STR_LIT>' ) ) <EOL> ax . hist ( t , MAX_SAMPLES_PER_PLOT , range = ( <NUM_LIT:0> , <NUM_LIT:30> ) , alpha = <NUM_LIT:0.5> , color = '<STR_LIT>' ) <EOL> ax . set_xlim ( <NUM_LIT:0> , <NUM_LIT:30> ) <EOL> ax . set_axis_off ( ) <EOL> ax . set_xlabel ( '<STR_LIT>' ) <EOL> ax . set_ylabel ( '<STR_LIT>' ) <EOL> ax . set_title ( alg_label + "<STR_LIT>" , size = <NUM_LIT> ) <EOL> plot_dict = mpld3 . fig_to_dict ( fig ) <EOL> return plot_dict <EOL> def network_delay_histogram ( self , app_id , exp_uid , alg_label ) : <EOL> """<STR_LIT>""" <EOL> alg_list , didSucceed , message = self . db . get ( app_id + '<STR_LIT>' , exp_uid , '<STR_LIT>' ) <EOL> for algorithm in alg_list : <EOL> if algorithm [ '<STR_LIT>' ] == alg_label : <EOL> alg_id = algorithm [ '<STR_LIT>' ] <EOL> alg_uid = algorithm [ '<STR_LIT>' ] <EOL> list_of_query_dict , didSucceed , message = self . db . get_docs_with_filter ( app_id + '<STR_LIT>' , { '<STR_LIT>' : exp_uid , '<STR_LIT>' : alg_uid } ) <EOL> t = [ ] <EOL> for item in list_of_query_dict : <EOL> try : <EOL> t . append ( item [ '<STR_LIT>' ] ) <EOL> except : <EOL> pass <EOL> import matplotlib . pyplot as plt <EOL> import mpld3 <EOL> fig , ax = plt . subplots ( subplot_kw = dict ( axisbg = '<STR_LIT>' ) ) <EOL> ax . hist ( t , MAX_SAMPLES_PER_PLOT , range = ( <NUM_LIT:0> , <NUM_LIT:5> ) , alpha = <NUM_LIT:0.5> , color = '<STR_LIT>' ) <EOL> ax . set_xlim ( <NUM_LIT:0> , <NUM_LIT:5> ) <EOL> ax . set_axis_off ( ) <EOL> ax . set_xlabel ( '<STR_LIT>' ) <EOL> ax . set_ylabel ( '<STR_LIT>' ) <EOL> ax . set_title ( alg_label + "<STR_LIT>" , size = <NUM_LIT> ) <EOL> plot_dict = mpld3 . fig_to_dict ( fig ) <EOL> return plot_dict </s>
