def get_repository_quality(rid, **kwargs):
    try:
        repo_ctx, devs = app.request_view('repository-developers', rid=rid, **kwargs)
        devs = map(lambda x: x['id'], devs)
        devs_quality = map(lambda x: calculate_member_quality(x, **kwargs), devs)

        context = repo_ctx
        if devs_quality:
            context = devs_quality[0][0]
        res = [sum(_)/len(_) for _ in zip(*map(lambda x: x[1], devs_quality))]
        return context, res
    except (EnvironmentError, AttributeError) as e:
        raise APIError(e.message)
def calculate_member_quality(uid, **kwargs):
    def __process_row():
        return [__calc_quality(s, rm) for s, rm in zip(sr, rm_activity)]

    try:
        repo_ctx, repositories = app.request_view('member-repositories', uid=uid, **kwargs)
        repositories = map(lambda x: x['id'], repositories)
        repo_success_rate = map(lambda x: app.request_metric('sum-repository-success-rate', rid=x, **kwargs),
                                repositories)

        context = repo_success_rate[0][0]
        repo_success_rate = map(lambda x: x[1], repo_success_rate)
        repo_member_activity = map(
            lambda x: app.request_metric('sum-member-activity-in-repository', uid=uid, rid=x, **kwargs)[1],
            repositories)

        res = [__process_row() for sr, rm_activity in zip(repo_success_rate, repo_member_activity)]
        res = [sum(t) / len(t) for t in zip(*res)]
        return context, res
    except (EnvironmentError, AttributeError) as e:
        raise APIError(e.message)