本文整理匯總了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)