def test_mark_user_as_seen_in_group(self, write_points): before = timezone.now() self.assertLess(self.membership.lastseen_at, before) self.client.force_login(user=self.user) response = self.client.post('/api/groups/{}/mark_user_active/'.format( self.group.id), format='json') self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) self.membership.refresh_from_db() self.assertGreater(self.membership.lastseen_at, before) self.assertEqual(self.membership.inactive_at, None) self.assertEqual(self.membership.removal_notification_at, None) expected_stats = [ call([{ 'measurement': 'karrot.events', 'tags': group_tags(self.group), 'fields': { 'group_member_returned': 1, 'group_member_returned_seconds_since_marked_for_removal': 60 * 60 * 2, }, }]), call([{ 'measurement': 'karrot.events', 'tags': group_tags(self.group), 'fields': { 'group_activity': 1, }, }]), ] self.assertEqual(write_points.call_args_list, expected_stats)
def notification_tags(notification): tags = { 'notification_type': notification.type, } group = Group.objects.get(id=notification.context['group']) tags.update(group_tags(group)) return tags
def invitation_created(invitation): write_points([{ 'measurement': 'karrot.events', 'tags': group_tags(invitation.group), 'fields': { 'invitation_created': 1 }, }])
def activity_tags(activity): tags = group_tags(activity.place.group) tags.update({ 'place': str(activity.place.id), 'type': str(activity.activity_type.id), 'type_name': activity.activity_type.name, }) return tags
def pickup_notification_email(group, **kwargs): write_points([{ 'measurement': 'karrot.email.pickup_notification', 'tags': group_tags(group), 'fields': { 'value': 1, **kwargs }, }])
def conversation_tags(conversation): type = conversation.type() group = conversation.group tags = group_tags(group) if group else {} if type is not None: tags['type'] = type else: tags['type'] = 'unknown' return tags
def get_issue_stats(group): fields = { 'count_total': group.issues.count(), 'count_ongoing': group.issues.ongoing().count(), 'count_decided': group.issues.decided().count(), 'count_cancelled': group.issues.cancelled().count(), } return [{ 'measurement': 'karrot.group.issues', 'tags': group_tags(group), 'fields': fields, }]
def get_application_stats(group): fields = { 'count_total': group.application_set.count(), } for entry in group.application_set.values('status').annotate( count=Count('status')): fields['count_status_{}'.format(entry['status'])] = entry['count'] return [{ 'measurement': 'karrot.group.applications', 'tags': group_tags(group), 'fields': fields, }]
def unsubscribed(group, choice, notification_type): tags = { 'choice': choice, } if group: tags.update(group_tags(group)) if notification_type: tags.update({ 'notification_type': notification_type, }) write_points([{ 'measurement': 'karrot.unsubscribe', 'tags': tags, 'fields': { 'token_unsubscribe': 1 }, }])
def application_status_update(application): tags = group_tags(application.group) fields = { 'application_{}'.format(application.status): 1, } if application.status != 'pending': seconds = round( (timezone.now() - application.created_at).total_seconds()) fields['application_alive_seconds'] = seconds fields['application_{}_alive_seconds'.format( application.status)] = seconds tags['application_status'] = application.status write_points([{ 'measurement': 'karrot.events', 'tags': tags, 'fields': fields, }])
def offer_tags(offer): return group_tags(offer.group)
def pickup_tags(pickup): tags = group_tags(pickup.place.group) tags.update({ 'place': str(pickup.place.id), }) return tags
def issue_tags(issue): tags = group_tags(issue.group) tags.update({ 'type': issue.type, }) return tags