Exemple #1
0
def generate_plot_data_slices(profile):
    """ Generates data slices for plotting resources and models. The resources are split by unique
        uids, models are sliced into parts by uid and interval.

    :param dict profile: loaded perun profile
    :returns generator: generator: resources and models slices of unique uid as pair
        (data_slice(pandas.DataFrame), uid_models(list))
    """
    # Get resources for scatter plot points and models for curves
    resource_table = convert.resources_to_pandas_dataframe(profile)
    models = list(map(itemgetter(1), query.all_models_of(profile)))
    # Get unique uids from profile, each uid (and optionally interval) will have separate graph
    uids = map(convert.flatten,
               query.unique_resource_values_of(profile, 'uid'))

    # Process each uid data
    for uid_slice, uid_models in slice_resources_by_uid(
            resource_table, models, uids):
        # Slice the uid models according to different intervals (each interval is plotted
        # separately as it improves readability)
        if uid_models:
            for interval_models in slice_models_by_interval(uid_models):
                yield uid_slice, interval_models
        else:
            # There are no models to plot
            yield uid_slice, []
Exemple #2
0
def get_filtered_best_models_of(profile, model_filter=filter_by_r_square):
    """Obtains the models from the given profile. In the first case the method obtains the
    best fitting models, it means, that it obtains the models which have the higher values
    of coefficient determination. In the case, that arguments model_type was given, method
    obtains model of that type. Method maps the individually metrics from obtained profile
    to map, which is returns to calling function. Models are chosen unique according to its UID.

    :param dict profile: dictionary of profile resources and stuff
    :param function model_filter: filter function for models
    :returns: map of unique identifier of computed models to their best models
    """
    best_model_map = {
        uid: BestModelRecord("", 0.0, 0.0, 0.0, 0, 0, 0.0)
        for uid in query.unique_model_values_of(profile, 'uid')
    }
    for _, model in query.all_models_of(profile):
        model_uid = model['uid']
        if model_filter(best_model_map, model):
            if model['model'] == 'quadratic':
                best_model_map[model_uid] = BestModelRecord(
                    model['model'],
                    model['r_square'],
                    model['coeffs'][0]['value'],
                    model['coeffs'][1]['value'],
                    model['coeffs'][2]['value'],
                    model['x_interval_start'],
                    model['x_interval_end'],
                )
            else:
                best_model_map[model_uid] = BestModelRecord(
                    model['model'], model['r_square'],
                    model['coeffs'][0]['value'], model['coeffs'][1]['value'],
                    0, model['x_interval_start'], model['x_interval_end'])

    return best_model_map
Exemple #3
0
def test_all_models_corrupted(query_profiles):
    """Test 'all_models_of' on corrupted profile.

    Expected IncorrectProfileFormatException.
    """
    # Acquire the query profile with corrupted global section
    corrupted_profile = profile_filter(query_profiles, 'corrupted-global.perf')
    assert corrupted_profile is not None

    # Get all models in profile that has corrupted structure
    with pytest.raises(exceptions.IncorrectProfileFormatException):
        list(query.all_models_of(corrupted_profile))
Exemple #4
0
def test_all_models(query_profiles):
    """Test 'all_models_of' on profile with models.

    Expected _MODELS_COUNT models.
    """
    # Acquire the models query profile
    models_profile = profile_filter(query_profiles, 'complexity-models.perf')
    assert models_profile is not None

    # Get all models in profile that contains them
    models = list(query.all_models_of(models_profile))
    assert len(models) == _MODELS_COUNT
Exemple #5
0
def test_all_models_empty(query_profiles):
    """Test 'all_models_of' on profile without models.

    Expected 0 models.
    """
    # Acquire the complexity query profile
    models_profile = profile_filter(query_profiles,
                                    'complexity-2017-08-25-19-19-16.perf')
    assert models_profile is not None

    # Get all models in profile that has none
    models = list(query.all_models_of(models_profile))
    assert not models
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])
Exemple #7
0
def get_best_models_of(profile):
    """Retrieves the best models for unique identifiers and their models

    :param dict profile: dictionary of profile resources and stuff
    :returns: map of unique identifier of computed models to their best models
    """
    best_model_map = {
        uid: ("", 0.0) for uid in query.unique_model_values_of(profile, 'uid')
    }
    for _, model in query.all_models_of(profile):
        model_uid = model['uid']
        if best_model_map[model_uid][1] < model['r_square']:
            best_model_map[model_uid] = (model['model'], model['r_square'])

    return best_model_map
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