当前位置: 首页>>代码示例>>Python>>正文


Python ReviewerScore.get_breakdown方法代码示例

本文整理汇总了Python中olympia.reviewers.models.ReviewerScore.get_breakdown方法的典型用法代码示例。如果您正苦于以下问题:Python ReviewerScore.get_breakdown方法的具体用法?Python ReviewerScore.get_breakdown怎么用?Python ReviewerScore.get_breakdown使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在olympia.reviewers.models.ReviewerScore的用法示例。


在下文中一共展示了ReviewerScore.get_breakdown方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: performance

# 需要导入模块: from olympia.reviewers.models import ReviewerScore [as 别名]
# 或者: from olympia.reviewers.models.ReviewerScore import get_breakdown [as 别名]
def performance(request, user_id=False):
    user = request.user
    reviewers = _recent_reviewers()

    is_admin = acl.action_allowed(request, amo.permissions.REVIEWS_ADMIN)

    if is_admin and user_id:
        try:
            user = UserProfile.objects.get(pk=user_id)
        except UserProfile.DoesNotExist:
            pass  # Use request.user from above.

    monthly_data = _performance_by_month(user.id)
    performance_total = _performance_total(monthly_data)

    # Incentive point breakdown.
    today = date.today()
    month_ago = today - timedelta(days=30)
    year_ago = today - timedelta(days=365)
    point_total = ReviewerScore.get_total(user)
    totals = ReviewerScore.get_breakdown(user)
    months = ReviewerScore.get_breakdown_since(user, month_ago)
    years = ReviewerScore.get_breakdown_since(user, year_ago)

    def _sum(iter, types, exclude=False):
        """Sum the `total` property for items in `iter` that have an `atype`
        that is included in `types` when `exclude` is False (default) or not in
        `types` when `exclude` is True."""
        return sum(s.total
                   for s in iter
                   if (s.atype in types) == (not exclude))

    breakdown = {
        'month': {
            'addons': _sum(months, amo.GROUP_TYPE_ADDON),
            'themes': _sum(months, amo.GROUP_TYPE_THEME),
            'other': _sum(months, amo.GROUP_TYPE_ADDON + amo.GROUP_TYPE_THEME,
                          exclude=True)
        },
        'year': {
            'addons': _sum(years, amo.GROUP_TYPE_ADDON),
            'themes': _sum(years, amo.GROUP_TYPE_THEME),
            'other': _sum(years, amo.GROUP_TYPE_ADDON + amo.GROUP_TYPE_THEME,
                          exclude=True)
        },
        'total': {
            'addons': _sum(totals, amo.GROUP_TYPE_ADDON),
            'themes': _sum(totals, amo.GROUP_TYPE_THEME),
            'other': _sum(totals, amo.GROUP_TYPE_ADDON + amo.GROUP_TYPE_THEME,
                          exclude=True)
        }
    }

    data = context(request,
                   monthly_data=json.dumps(monthly_data),
                   performance_month=performance_total['month'],
                   performance_year=performance_total['year'],
                   breakdown=breakdown, point_total=point_total,
                   reviewers=reviewers, current_user=user, is_admin=is_admin,
                   is_user=(request.user.id == user.id))

    return render(request, 'reviewers/performance.html', data)
开发者ID:piyushmittal25,项目名称:addons-server,代码行数:64,代码来源:views.py


注:本文中的olympia.reviewers.models.ReviewerScore.get_breakdown方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。