本文整理汇总了Python中olympia.reviewers.models.ReviewerScore.get_breakdown_since方法的典型用法代码示例。如果您正苦于以下问题:Python ReviewerScore.get_breakdown_since方法的具体用法?Python ReviewerScore.get_breakdown_since怎么用?Python ReviewerScore.get_breakdown_since使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类olympia.reviewers.models.ReviewerScore
的用法示例。
在下文中一共展示了ReviewerScore.get_breakdown_since方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: performance
# 需要导入模块: from olympia.reviewers.models import ReviewerScore [as 别名]
# 或者: from olympia.reviewers.models.ReviewerScore import get_breakdown_since [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)