def calculate(self, start=localdate(), end=None, **kwargs): scores = self.filter_users( self.tp_score_model.objects.filter(date__gte=(localdate() - timedelta(days=30))), kwargs.get("users")) return scores.order_by("user").values_list("user").annotate( score=Sum("score"))
def save_subs(self, subs): subs = list(subs) if not subs: return self.unit.submission_set.bulk_create(subs) update_scores.send( self.unit.store.__class__, instance=self.unit.store, users=[sub.submitter_id for sub in subs], date=localdate(self.unit.mtime))
def handle_submission_added(**kwargs): submission = kwargs["instance"] is_system_user = ( submission.submitter == get_user_model().objects.get_system_user()) if is_system_user: return update_scores.send(submission.unit.store.__class__, instance=submission.unit.store, users=[submission.submitter_id], date=localdate(submission.creation_time))
def score_event(self, event, calculated_scores): if event.action not in self.scoring: return scores = self.scoring[event.action](event).get_score() if not scores or not any(x > 0 for x in scores.values()): return event_date = localdate(event.timestamp) calculated_scores[event_date] = (calculated_scores.get(event_date, {})) calculated_scores[event_date][event.user.id] = ( calculated_scores[event_date].get(event.user.id, {})) for k, score in scores.items(): if not score: continue calculated_scores[event_date][event.user.id][k] = ( calculated_scores[event_date][event.user.id].get(k, 0) + score)
def handle_suggestion_change(**kwargs): suggestion = kwargs["instance"] is_system_user = ( (suggestion.is_pending and (suggestion.user_id == get_user_model().objects.get_system_user().id)) or (not suggestion.is_pending and (suggestion.reviewer_id == get_user_model().objects.get_system_user().id))) if is_system_user: return change_date = (suggestion.review_time if not suggestion.is_pending else suggestion.creation_time) update_scores.send(suggestion.unit.store.__class__, instance=suggestion.unit.store, users=[ suggestion.user_id if suggestion.is_pending else suggestion.reviewer_id ], date=localdate(change_date))
def get_daterange(self, days): now = localdate() return now - timedelta(days), now
def cache_key(self): return ("%s.%s.%s" % (self.context.id, localdate(), self.revision))
def cache_key(self): return ("%s/%s.%s.%s" % (self.context.language.code, self.context.project.code, localdate(), self.revision))
def cache_key(self): return ("%s.%s" % (localdate(), self.revision))