Ejemplo n.º 1
0
def get_member_longest_streak(mid, **kwargs):
    begin = kwargs.get('begin')
    end = kwargs.get('end')

    if begin is None:
        begin = 0
    if end is None:
        end = calendar.timegm(datetime.utcnow().timetuple())

    committer_id = store.get_member_id(mid)
    ts_commits = [ts for (_, ts) in
                  store.db.zrangebyscore('metrics:total-member-commits:{}'.format(committer_id), begin, end,
                                         withscores=True)]

    if ts_commits:
        current_ts = ts_commits.pop(0)
        streak = 1
        max_streak = 1
        for ts in ts_commits:
            if abs(ts - current_ts - 86400) < 1:
                streak += 1
                max_streak = max(streak, max_streak)
            else:
                streak = 1
            current_ts = ts
        return {'begin': begin, 'end': end}, [max_streak]
    else:
        return {}, [0]
Ejemplo n.º 2
0
def get_total_member_repositories(mid, **kwargs):
    if kwargs['begin'] is None:
        kwargs['begin'] = 0
    if kwargs['end'] is None:
        kwargs['end'] = calendar.timegm(datetime.utcnow().timetuple())

    committer_id = store.get_member_id(mid)
    if committer_id is None:
        return []
    commits = store.get_commits(kwargs['begin'], kwargs['end'], uid=committer_id)
    return {}, [len(list(store.get_repo_uris(*store.get_commits_repos(commits))))]
Ejemplo n.º 3
0
def get_member_activity_in_repository(rid, mid, **kwargs):
    committer_id = store.get_member_id(mid)
    context, member_res = aggregate(store, 'metrics:total-repo-member-commits:{}:{}'.format(rid, committer_id),
                                    kwargs['begin'],
                                    kwargs['end'],
                                    kwargs['max'])
    kwargs['begin'] = int(context['begin'])
    kwargs['end'] = int(context['end'])
    kwargs['max'] = len(member_res)
    try:
        _, repo_res = aggregate(store, 'metrics:total-repo-commits:{}'.format(rid), kwargs['begin'],
                                kwargs['end'],
                                kwargs['max'])
        activity = [float(m) / float(g) if g else 0 for m, g in zip(member_res, repo_res)]
        return context, activity
    except (EnvironmentError, AttributeError) as e:
        raise APIError(e.message)
Ejemplo n.º 4
0
def get_member_activity(mid, **kwargs):
    committer_id = store.get_member_id(mid)
    if kwargs['begin'] is None and kwargs['end'] is None:
        begin, end = store.get_developer_frame(committer_id)
        kwargs['begin'] = begin
        kwargs['end'] = end
    context, member_res = aggregate(store, 'metrics:total-member-commits:{}'.format(committer_id), kwargs['begin'],
                                    kwargs['end'],
                                    kwargs['max'])
    # Align query params with the local context just obtained
    kwargs['begin'] = int(context['begin'])
    kwargs['end'] = int(context['end'])
    kwargs['max'] = len(member_res)
    try:
        _, global_res = aggregate(store, 'metrics:total-commits', kwargs['begin'],
                                  kwargs['end'],
                                  kwargs['max'])
        activity = [float(m) / float(g) if g else 0 for m, g in zip(member_res, global_res)]
        return context, activity
    except (EnvironmentError, AttributeError) as e:
        raise APIError(e.message)
Ejemplo n.º 5
0
def get_member_repositories(mid, **kwargs):
    committer_id = store.get_member_id(mid)
    if committer_id is None:
        return []
    commits = store.get_commits(kwargs['begin'], kwargs['end'], uid=committer_id)
    return list(store.get_repo_uris(*store.get_commits_repos(commits)))
Ejemplo n.º 6
0
def get_avg_member_commits(mid, **kwargs):
    committer_id = store.get_member_id(mid)
    return aggregate(store, 'metrics:total-member-commits:{}'.format(committer_id), kwargs['begin'], kwargs['end'],
                     kwargs['max'], aggr=avg, extend=True)
Ejemplo n.º 7
0
def get_total_repo_member_commits(rid, mid, **kwargs):
    committer_id = store.get_member_id(mid)
    return aggregate(store, 'metrics:total-repo-member-commits:{}:{}'.format(rid, committer_id), kwargs['begin'],
                     kwargs['end'],
                     kwargs['max'])