Пример #1
0
def _nary_dict_update(dicts, **kwargs):
    """Implementation of n-argument ``dict.update``,
    with flags controlling the exact strategy.
    """
    copy = kwargs['copy']
    res = dicts[0].copy() if copy else dicts[0]
    if len(dicts) == 1:
        return res

    # decide what strategy to use when updating a dictionary
    # with the values from another: {(non)recursive} x {(non)overwriting}
    deep = kwargs['deep']
    overwrite = kwargs['overwrite']
    if deep:
        dict_update = curry(_recursive_dict_update, overwrite=overwrite)
    else:
        if overwrite:
            dict_update = res.__class__.update
        else:

            def dict_update(dict_, other):
                for k, v in iteritems(other):
                    dict_.setdefault(k, v)

    for d in dicts[1:]:
        dict_update(res, d)
    return res
Пример #2
0
    def _create_multitagging_metaclass(self, *tags, **kwargs):
        """Create a metaclass that applies multiple tags with given name
        to every class it participates in creation of.
        """
        base = kwargs.pop('base', __unit__.ObjectMetaclass)
        tagging_metaclasses = map(
            curry(self._create_tagging_metaclass, base=base), tags)

        # sadly, the following is syntax error:
        #
        #     class Meta(*tagging_metaclasses):
        #         pass
        return type('Meta', tuple(tagging_metaclasses), {})
Пример #3
0
    def _create_multitagging_metaclass(self, *tags, **kwargs):
        """Create a metaclass that applies multiple tags with given name
        to every class it participates in creation of.
        """
        base = kwargs.pop('base', __unit__.ObjectMetaclass)
        tagging_metaclasses = map(
            curry(self._create_tagging_metaclass, base=base), tags)

        # sadly, the following is syntax error:
        #
        #     class Meta(*tagging_metaclasses):
        #         pass
        return type('Meta', tuple(tagging_metaclasses), {})
Пример #4
0
def approximate_coding_sessions(clustered_commits, approx_algo):
    """Approximates the coding sessions that resulted in given clustered commits.

    :param clustered_commits: Dictionary mapping contributor names
                              to lists of Commit clusters
    :param approx_algo: Name of approximation algorithm

    :return: Dictionary mapping contributor names to lists of Session tuples
    """
    approx_func = globals().get(approx_algo + '_approximation')
    if not approx_func:
        raise ValueError("Unknown approximation '%s'" % approx_algo)

    return dicts.mapvalues(curry(map, approx_func), clustered_commits)
Пример #5
0
def approximate_coding_sessions(clustered_commits, approx_algo):
    """Approximates the coding sessions that resulted in given clustered commits.

    :param clustered_commits: Dictionary mapping contributor names
                              to lists of Commit clusters
    :param approx_algo: Name of approximation algorithm

    :return: Dictionary mapping contributor names to lists of Session tuples
    """
    approx_func = globals().get(approx_algo + '_approximation')
    if not approx_func:
        raise ValueError("Unknown approximation '%s'" % approx_algo)

    return dicts.mapvalues(curry(map, approx_func), clustered_commits)
Пример #6
0
def cluster_commits(grouped_commits, cluster_algo, epsilon):
    """Clusters commits for every contributor in given dictionary.

    :param grouped_commits: Dictionary mapping contributor names
                            to lists of Commit tuples
    :param cluster_algo: Name of clustering algorithm
    :param epsilon: Temporal distance for the epsilon-neighborhood

    :return: Dictionary mapping author names to lists of coding sessions
    """
    cluster_func = globals().get(cluster_algo + '_clustering')
    if not cluster_func:
        raise ValueError("Unknown clustering algorithm '%s'" % cluster_algo)

    return dicts.mapvalues(curry(cluster_func, epsilon=epsilon),
                           grouped_commits)
Пример #7
0
def cluster_commits(grouped_commits, cluster_algo, epsilon):
    """Clusters commits for every contributor in given dictionary.

    :param grouped_commits: Dictionary mapping contributor names
                            to lists of Commit tuples
    :param cluster_algo: Name of clustering algorithm
    :param epsilon: Temporal distance for the epsilon-neighborhood

    :return: Dictionary mapping author names to lists of coding sessions
    """
    cluster_func = globals().get(cluster_algo + '_clustering')
    if not cluster_func:
        raise ValueError("Unknown clustering algorithm '%s'" % cluster_algo)

    return dicts.mapvalues(curry(cluster_func, epsilon=epsilon),
                           grouped_commits)