def create_from_params(profile, func, of_key, through_key, by_key, stacked, accumulate, x_axis_label, y_axis_label, graph_title, graph_width=800): """Creates Flow graph according to the given parameters. Takes the input profile, converts it first to pandas.DataFrame. Then the data are grouped according to the 'by_key' and then grouped again for each 'through' key. For this atomic groups aggregation function is used. For each computed data, we output the area and points. Arguments: profile(dict): dictionary with measured data func(str): function that will be used for aggregation of the data of_key(str): key that specifies which fields of the resource entry will be used as data through_key(str): key that specifies fields of the resource that will be on the x axis by_key(str): key that specifies values for which graphs will be outputed stacked(bool): true if the values of the graphs should be stacked on each other -> this shows the overall values accumulate(bool): true if the values from previous x values should be accumulated x_axis_label(str): label on the x axis y_axis_label(str): label on the y axis graph_title(str): name of the graph graph_width(int): width of the created bokeh graph Returns: charts.Area: flow graph according to the params """ # Convert profile to pandas data grid data_frame = convert.resources_to_pandas_dataframe(profile) data_source = construct_data_source_from(data_frame, func, of_key, by_key, through_key, accumulate) # Obtain colours, which will be sorted in reverse key_colours = bokeh_helpers.get_unique_colours_for_( data_frame, by_key, sort_color_style=bokeh_helpers.ColourSort.Reverse) # Construct the area chart area_chart = charts.Area(data_source, stack=stacked, color=key_colours) # Configure graph and return it bokeh_helpers.configure_graph(area_chart, profile, func, graph_title, x_axis_label, y_axis_label, graph_width) configure_area_chart(area_chart, data_frame, data_source, through_key, stacked) return area_chart
def create_from_params(profile, of_key, per_key, x_axis_label, y_axis_label, graph_title, graph_width=800): """Creates Scatter plot graph according to the given parameters. Takes the input profile, convert it to pandas.DataFrame. Then the data according to 'of_key' parameter are used as values and are output depending on values of 'per_key'. Furthermore, models records are also plotted if the profile contains them. :param dict profile: dictionary with measured data :param str of_key: key that specifies which fields of the resource entry will be used as data :param str per_key: key that specifies fields of the resource that will be on the x axis :param str x_axis_label: label on the x axis :param str y_axis_label: label on the y axis :param str graph_title: name of the graph :param int graph_width: width of the created bokeh graph :returns uid, charts.Scatter: uid and scatter plot graph with models built according to the params """ for data_slice, models_slice in generate_plot_data_slices(profile): # Plot the points as a scatter plot scatter = charts.Scatter( data_slice, x=per_key, y=of_key, title=graph_title, xlabel=x_axis_label, ylabel=y_axis_label, tools='pan,wheel_zoom,box_zoom,zoom_in,zoom_out,crosshair,' 'reset,save') # Configure the graph properties # Create the graph title as a combination of default parameter, uid, method and # interval values (only if models are plotted) for easier identification this_graph_title = graph_title + '; uid: {0}'.format( data_slice.uid.values[0]) if models_slice: this_graph_title += ('; method: {0}; interval <{1}, {2}>'.format( models_slice[0]['method'], models_slice[0]['x_interval_start'], models_slice[0]['x_interval_end'])) bokeh_helpers.configure_graph(scatter, profile, 'count', this_graph_title, x_axis_label, y_axis_label, graph_width) # Plot all models scatter = draw_models(scatter, models_slice, profile) yield '{}'.format(data_slice.uid.values[0]), scatter
def create_from_params(profile, func, of_key, per_key, by_key, cummulation_type, x_axis_label, y_axis_label, graph_title, graph_width=800): """Creates Bar graph according to the given parameters. Takes the input profile, convert it to pandas.DataFrame. Then the data according to 'of_key' parameter are used as values and are output by aggregation function of 'func' depending on values of 'per_key'. Values are further stacked by 'by_key' key and cummulated according to the type. Arguments: profile(dict): dictionary with measured data func(str): function that will be used for aggregation of the data of_key(str): key that specifies which fields of the resource entry will be used as data per_key(str): key that specifies fields of the resource that will be on the x axis by_key(str): key that specifies grouping or stacking of the resources cummulation_type(str): type of the cummulation of the data (either stacked or grouped) x_axis_label(str): label on the x axis y_axis_label(str): label on the y axis graph_title(str): name of the graph graph_width(int): width of the created bokeh graph Returns: charts.Bar: bar graph according to the params """ # Convert profile to pandas data grid data_frame = convert.resources_to_pandas_dataframe(profile) # Create basic graph: if cummulation_type == 'stacked': bar_graph = create_stacked_bar_graph(data_frame, func, of_key, per_key, by_key) elif cummulation_type == 'grouped': bar_graph = create_grouped_bar_graph(data_frame, func, of_key, per_key, by_key) else: log.error("unknown cummulation type '{}'".format(cummulation_type)) # Call basic configuration of the graph bokeh_helpers.configure_graph(bar_graph, profile, func, graph_title, x_axis_label, y_axis_label, graph_width) return bar_graph