Exemplo n.º 1
0
def get_single_profile_info(pcs, minor_version, profile_source):
    """Function for loading single performance profile info
    :param PCS pcs: object with performance control system wrapper
    :param str minor_version: commit to which the profiles belongs
    :param str profile_source: name of the performance profile
    :return: dictionary containing performance profile info
    """

    try:
        profiles_objs = commands.get_minor_version_profiles(pcs, minor_version);
        for num, profile_obj in enumerate(profiles_objs):
            if (profile_obj.source == profile_source):
                perf_profile = profile.load_profile_from_file(profile_obj.realpath, is_raw_profile=False)
                options = [o for o in query.all_resource_fields_of(perf_profile)]
                numerical = [o for o in query.all_numerical_resource_fields_of(perf_profile)]
                dataframe = convert.resources_to_pandas_dataframe(perf_profile)

                for option in options:
                    dataframe = dataframe[pandas.notnull(dataframe[option])]
                
                dataframe = dataframe.astype(str)
                resource_values = dataframe.to_dict(orient='records')

                formatted = formatter.format_single_profile_info(profile_obj, minor_version, options, numerical, resource_values)

                return formatted, json.dumps({'profile' : formatted})

        profiles_objs = commands.get_untracked_profiles(pcs);
        for num, profile_obj in enumerate(profiles_objs):
            if (profile_obj.source == profile_source):
                perf_profile = profile.load_profile_from_file(profile_obj.realpath, is_raw_profile=True)
                options = [o for o in query.all_resource_fields_of(perf_profile)]
                numerical = [o for o in query.all_numerical_resource_fields_of(perf_profile)]
                dataframe = convert.resources_to_pandas_dataframe(perf_profile)
                
                for option in options:
                    dataframe = dataframe[pandas.notnull(dataframe[option])]

                dataframe = dataframe.astype(str)
                resource_values = dataframe.to_dict(orient='records')

                formatted = formatter.format_single_profile_info(profile_obj, minor_version, options, numerical, resource_values)
                
                return formatted, json.dumps({'profile' : formatted})

        return create_response('Something went wrong', 404)

    except Exception as e:
        eprint(e)
        return create_response(e, 404)
Exemplo n.º 2
0
def is_key_aggregatable_by(profile, func, key, keyname):
    """Check if the key can be aggregated by the function.

    Everything is countable and hence 'count' and 'nunique' (number of unique values) are
    valid aggregation functions for everything. Otherwise (e.g. sum, mean), we need numerical
    values.

    :param dict profile: profile that will be used against in the validation
    :param function func: function used for aggregation of the data
    :param str key: key that will be aggregated in the graph
    :param str keyname: name of the validated key
    :returns bool: true if the key is aggregatable by the function
    :raises InvalidParameterException: if the of_key does not support the given function
    """
    # Everything is countable ;)
    if func in ('count', 'nunique'):
        return True

    # Get all valid numeric keys and validate
    valid_keys = set(query.all_numerical_resource_fields_of(profile))
    if key not in valid_keys:
        choices = "(choose either count/nunique as aggregation function;"
        choices += " or from the following keys: {})".format(
            ", ".join(map(str, valid_keys))
        )
        raise InvalidParameterException(keyname, key, choices)
    return True
Exemplo n.º 3
0
def process_continuous_key(ctx, _, value):
    """Helper function for processing the continuous key for the param.

    Continuous keys are used in the continuous graphs (do'h!) on the x axis, i.e. they have to be
    numeric. We check all of the keys in the resources.

    Arguments:
        ctx(click.Context): called context of the process
        _(click.Option): called parameter
        value(object): given value for the option param

    Returns:
        object: value or raises bad parameter

    Raises:
        click.BadParameter: if the value is invalid for the profile
    """
    if value == 'snapshots':
        return value

    # Get all of the numerical keys
    valid_numeric_keys = set(
        query.all_numerical_resource_fields_of(ctx.parent.params['profile']))
    if value not in valid_numeric_keys:
        raise click.BadParameter("invalid choice: {}. (choose from {})".format(
            value,
            ", ".join(str(vnk) for vnk in valid_numeric_keys) + ", snapshots"))
    return value