Beispiel #1
0
def get_stats_dict(request, user):
    now = datetime.now()
    last12hours = timeutils.getlast12hours(now)
    last7days = timeutils.getlast7days(now)
    last30days = timeutils.getlast30days(now)
    last12months = timeutils.getlast12months(now)
    raw_last12hours_commit = StatsManager.list_user_stats(user.id, 'hour', datetime.fromtimestamp(last12hours[-1]), datetime.fromtimestamp(last12hours[0]))
    last12hours_commit = dict([(time.mktime(x.date.timetuple()), int(x.count)) for x in raw_last12hours_commit])
    raw_last30days_commit = StatsManager.list_user_stats(user.id, 'day', datetime.fromtimestamp(last30days[-1]), datetime.fromtimestamp(last30days[0]))
    last30days_commit = dict([(time.mktime(x.date.timetuple()), int(x.count)) for x in raw_last30days_commit])
    last7days_commit = {}
    for x in last7days:
        if x in last30days_commit:
            last7days_commit[x] = last30days_commit[x]
    raw_last12months_commit = StatsManager.list_user_stats(user.id, 'month', datetime.fromtimestamp(last12months[-1]), datetime.fromtimestamp(last12months[0]))
    last12months_commit = dict([(time.mktime(x.date.timetuple()), int(x.count)) for x in raw_last12months_commit])

    round_week = timeutils.get_round_week(now)
    round_month = timeutils.get_round_month(now)
    round_year = timeutils.get_round_year(now)

    raw_per_last_week_commits = StatsManager.list_user_repo_stats(user.id, 'week', round_week)
    raw_per_last_month_commits = StatsManager.list_user_repo_stats(user.id, 'month', round_month)
    raw_per_last_year_commits = StatsManager.list_user_repo_stats(user.id, 'year', round_year)

    raw_week_repo_ids = [x.repo_id for x in raw_per_last_week_commits]
    raw_month_repo_ids = [x.repo_id for x in raw_per_last_month_commits]
    raw_year_repo_ids = [x.repo_id for x in raw_per_last_year_commits]
    uniq_repo_ids = list(set(raw_week_repo_ids + raw_month_repo_ids + raw_year_repo_ids))
    repo_dict = RepoManager.merge_repo_map(uniq_repo_ids)

    is_yourself = False
    if request.user.is_authenticated() and user.id == request.user.id:
        is_yourself = True

    per_repo_week_commits = _list_repo_count_dict(raw_per_last_week_commits, repo_dict, is_yourself)
    per_repo_month_commits = _list_repo_count_dict(raw_per_last_month_commits, repo_dict, is_yourself)
    per_repo_year_commits = _list_repo_count_dict(raw_per_last_year_commits, repo_dict, is_yourself)
    round_week_tip = u'%s 以来参与项目' % round_week.strftime('%y/%m/%d')
    round_month_tip = u'%s 以来参与项目' %  round_month.strftime('%y/%m/%d')
    round_year_tip = u'%s 以来参与项目' %  round_year.strftime('%y/%m/%d')
    per_repo_commits = []
    if len(per_repo_week_commits) > 0:
        per_repo_commits.append({'commits': per_repo_week_commits, 'tip': round_week_tip})
    if len(per_repo_month_commits) > 0:
        per_repo_commits.append({'commits': per_repo_month_commits, 'tip': round_month_tip})
    if len(per_repo_year_commits) > 0:
        per_repo_commits.append({'commits': per_repo_year_commits, 'tip': round_year_tip})

    stats_dict = {'last12hours': last12hours, 'last7days': last7days, 'last30days': last30days, 'last12months': last12months, 'last12hours_commit': last12hours_commit, 'last7days_commit': last7days_commit, 'last30days_commit': last30days_commit, 'last12months_commit': last12months_commit, 'per_repo_commits': per_repo_commits}
    return stats_dict
Beispiel #2
0
def user(request, user_name):
    title = u'%s / 概括' % user_name
    gsuser = GsuserManager.get_user_by_name(user_name)
    if gsuser is None:
        raise Http404
    gsuserprofile = GsuserManager.get_userprofile_by_id(gsuser.id)
    if gsuserprofile.is_team_account == 1 and TeamManager.is_teamMember(
            gsuser.id, request.user.id):
        return HttpResponseRedirect('/%s/-/dashboard/' % user_name)
    recommendsForm = RecommendsForm()
    repos = []
    if gsuser.id == request.user.id:
        repos = RepoManager.list_repo_by_userId(gsuser.id, 0, 100)
    else:
        repos = RepoManager.list_unprivate_repo_by_userId(gsuser.id, 0, 100)

    now = datetime.now()
    last30days = timeutils.getlast30days(now)
    last30days_commit = get_last30days_commit(gsuser)

    feedAction = FeedAction()

    raw_watch_repos = feedAction.get_watch_repos(gsuser.id, 0, 10)
    watch_repo_ids = [int(x[0]) for x in raw_watch_repos]
    watch_repos_map = RepoManager.merge_repo_map(watch_repo_ids)
    watch_repos = [
        watch_repos_map[x] for x in watch_repo_ids if x in watch_repos_map
    ]

    pri_user_feeds = feedAction.get_pri_user_feeds(gsuser.id, 0, 10)
    pub_user_feeds = feedAction.get_pub_user_feeds(gsuser.id, 0, 10)
    feeds_as_json = get_feeds_as_json(request, pri_user_feeds, pub_user_feeds)

    star_repos = RepoManager.list_star_repo(gsuser.id, 0, 20)

    response_dictionary = {
        'mainnav': 'user',
        'title': title,
        'recommendsForm': recommendsForm,
        'repos': repos,
        'watch_repos': watch_repos,
        'star_repos': star_repos,
        'last30days': last30days,
        'last30days_commit': last30days_commit,
        'feeds_as_json': feeds_as_json
    }
    response_dictionary.update(
        get_common_user_dict(request, gsuser, gsuserprofile))
    return render_to_response('user/user.html',
                              response_dictionary,
                              context_instance=RequestContext(request))
Beispiel #3
0
def user(request, user_name):
    title = u'%s / 概括' % user_name
    gsuser = GsuserManager.get_user_by_name(user_name)
    if gsuser is None:
        raise Http404
    gsuserprofile = GsuserManager.get_userprofile_by_id(gsuser.id)
    if gsuserprofile.is_team_account == 1 and TeamManager.is_teamMember(gsuser.id, request.user.id):
        return HttpResponseRedirect('/%s/-/dashboard/' % user_name)
    recommendsForm = RecommendsForm()
    repos = []
    if gsuser.id == request.user.id:
        repos = RepoManager.list_repo_by_userId(gsuser.id, 0, 100)
    else:
        repos = RepoManager.list_unprivate_repo_by_userId(gsuser.id, 0, 100)

    now = datetime.now()
    last30days = timeutils.getlast30days(now)
    last30days_commit = get_last30days_commit(gsuser)

    feedAction = FeedAction()

    raw_watch_repos = feedAction.get_watch_repos(gsuser.id, 0, 10)
    watch_repo_ids = [int(x[0]) for x in raw_watch_repos]
    watch_repos_map = RepoManager.merge_repo_map(watch_repo_ids)
    watch_repos = [watch_repos_map[x] for x in watch_repo_ids if x in watch_repos_map]

    pri_user_feeds = feedAction.get_pri_user_feeds(gsuser.id, 0, 10)
    pub_user_feeds = feedAction.get_pub_user_feeds(gsuser.id, 0, 10)
    feeds_as_json = get_feeds_as_json(request, pri_user_feeds, pub_user_feeds)

    star_repos = RepoManager.list_star_repo(gsuser.id, 0, 20)

    response_dictionary = {'mainnav': 'user', 'title': title, 'recommendsForm': recommendsForm, 'repos': repos, 'watch_repos': watch_repos, 'star_repos': star_repos, 'last30days': last30days, 'last30days_commit': last30days_commit, 'feeds_as_json': feeds_as_json}
    response_dictionary.update(get_common_user_dict(request, gsuser, gsuserprofile))
    return render_to_response('user/user.html',
                          response_dictionary,
                          context_instance=RequestContext(request))
Beispiel #4
0
def get_stats_dict(request, user):
    now = datetime.now()
    last12hours = timeutils.getlast12hours(now)
    last7days = timeutils.getlast7days(now)
    last30days = timeutils.getlast30days(now)
    last12months = timeutils.getlast12months(now)
    raw_last12hours_commit = StatsManager.list_user_stats(
        user.id, 'hour', datetime.fromtimestamp(last12hours[-1]),
        datetime.fromtimestamp(last12hours[0]))
    last12hours_commit = dict([(time.mktime(x.date.timetuple()), int(x.count))
                               for x in raw_last12hours_commit])
    raw_last30days_commit = StatsManager.list_user_stats(
        user.id, 'day', datetime.fromtimestamp(last30days[-1]),
        datetime.fromtimestamp(last30days[0]))
    last30days_commit = dict([(time.mktime(x.date.timetuple()), int(x.count))
                              for x in raw_last30days_commit])
    last7days_commit = {}
    for x in last7days:
        if x in last30days_commit:
            last7days_commit[x] = last30days_commit[x]
    raw_last12months_commit = StatsManager.list_user_stats(
        user.id, 'month', datetime.fromtimestamp(last12months[-1]),
        datetime.fromtimestamp(last12months[0]))
    last12months_commit = dict([(time.mktime(x.date.timetuple()), int(x.count))
                                for x in raw_last12months_commit])

    round_week = timeutils.get_round_week(now)
    round_month = timeutils.get_round_month(now)
    round_year = timeutils.get_round_year(now)

    raw_per_last_week_commits = StatsManager.list_user_repo_stats(
        user.id, 'week', round_week)
    raw_per_last_month_commits = StatsManager.list_user_repo_stats(
        user.id, 'month', round_month)
    raw_per_last_year_commits = StatsManager.list_user_repo_stats(
        user.id, 'year', round_year)

    raw_week_repo_ids = [x.repo_id for x in raw_per_last_week_commits]
    raw_month_repo_ids = [x.repo_id for x in raw_per_last_month_commits]
    raw_year_repo_ids = [x.repo_id for x in raw_per_last_year_commits]
    uniq_repo_ids = list(
        set(raw_week_repo_ids + raw_month_repo_ids + raw_year_repo_ids))
    repo_dict = RepoManager.merge_repo_map(uniq_repo_ids)

    is_yourself = False
    if request.user.is_authenticated() and user.id == request.user.id:
        is_yourself = True

    per_repo_week_commits = _list_repo_count_dict(raw_per_last_week_commits,
                                                  repo_dict, is_yourself)
    per_repo_month_commits = _list_repo_count_dict(raw_per_last_month_commits,
                                                   repo_dict, is_yourself)
    per_repo_year_commits = _list_repo_count_dict(raw_per_last_year_commits,
                                                  repo_dict, is_yourself)
    round_week_tip = u'%s 以来参与项目' % round_week.strftime('%y/%m/%d')
    round_month_tip = u'%s 以来参与项目' % round_month.strftime('%y/%m/%d')
    round_year_tip = u'%s 以来参与项目' % round_year.strftime('%y/%m/%d')
    per_repo_commits = []
    if len(per_repo_week_commits) > 0:
        per_repo_commits.append({
            'commits': per_repo_week_commits,
            'tip': round_week_tip
        })
    if len(per_repo_month_commits) > 0:
        per_repo_commits.append({
            'commits': per_repo_month_commits,
            'tip': round_month_tip
        })
    if len(per_repo_year_commits) > 0:
        per_repo_commits.append({
            'commits': per_repo_year_commits,
            'tip': round_year_tip
        })

    stats_dict = {
        'last12hours': last12hours,
        'last7days': last7days,
        'last30days': last30days,
        'last12months': last12months,
        'last12hours_commit': last12hours_commit,
        'last7days_commit': last7days_commit,
        'last30days_commit': last30days_commit,
        'last12months_commit': last12months_commit,
        'per_repo_commits': per_repo_commits
    }
    return stats_dict