예제 #1
0
def test_coefficients_to_points_corrupted_model(postprocess_profiles):
    """ Test conversion from models coefficients to points on a profile with invalid model.

    Expecting to catch InvalidModelException exception.
    """
    # Acquire the corrupted models query profile with invalid model
    models_profile = profile_filter(postprocess_profiles,
                                    'complexity-models-corrupted-model.perf')
    assert models_profile is not None

    # Get all models and perform the conversion on all of them
    models = list(query.all_models_of(models_profile))
    with pytest.raises(exceptions.InvalidModelException):
        for model in models:
            convert.plot_data_from_coefficients_of(model[1])
예제 #2
0
파일: factory.py 프로젝트: xlisci02/perun
def create_parametric_model(graph, model, colour):
    """
    Rendering the parametric models according to its coefficients.

    :param charts.Graph graph: the scatter plot to render new models
    :param model: the parametric model to be render to the graph
    :param colour: the color of the current model to distinguish in the case of several models in the graph
    :return charts.Graph: the modified graph with new model curves
    """
    # Convert the coefficients to points that can be plotted
    model = convert.plot_data_from_coefficients_of(model)
    # Create legend for the plotted model
    coeffs = ', '.join('{}={:f}'.format(c['name'], c['value'])
                       for c in model['coeffs'])
    legend = '{0}: {1}, r^2={2:f}'.format(model['model'], coeffs,
                                          model['r_square'])
    # Plot the model
    graph.line(x=model['plot_x'],
               y=model['plot_y'],
               line_color='#000000',
               line_width=7.5,
               legend=legend)
    graph.line(x=model['plot_x'],
               y=model['plot_y'],
               line_color=colour,
               line_width=3.5,
               legend=legend)
    return graph
예제 #3
0
def test_coefficients_to_points_correct(postprocess_profiles):
    """ Test correct conversion from models coefficients to points that can be used for plotting.

    Expecting no errors and updated dictionary
    """
    # Acquire the models query profile
    models_profile = profile_filter(postprocess_profiles,
                                    'complexity-models.perf')
    assert models_profile is not None

    # Get all models and perform the conversion on all of them
    # TODO: add more advanced checks
    models = list(query.all_models_of(models_profile))
    for model in models:
        data = convert.plot_data_from_coefficients_of(model[1])
        assert 'plot_x' in data
        assert 'plot_y' in data
예제 #4
0
def draw_models(graph, models):
    """ Add models renderers to the graph.

    Arguments:
        graph(charts.Graph): the scatter plot without models
        models(list): list of models to plot

    Returns:
        charts.Graph: the modified graph with model curves renderers
    """
    # Get unique colors for the model curves
    colour_palette = palettes.viridis(len(models))
    for idx, model in enumerate(models):
        # Convert the coefficients to points that can be plotted
        model = convert.plot_data_from_coefficients_of(model)
        # Create legend for the plotted model
        coeffs = ', '.join('{}={:f}'.format(c['name'], c['value']) for c in model['coeffs'])
        legend = '{0}: {1}, r^2={2:f}'.format(model['model'], coeffs, model['r_square'])
        # Plot the model
        graph.line(x=model['plot_x'], y=model['plot_y'],
                   line_color=colour_palette[idx], line_width=2.5, legend=legend)
    return graph