Beispiel #1
0
    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)
Beispiel #2
0
def notification_tags(notification):
    tags = {
        'notification_type': notification.type,
    }
    group = Group.objects.get(id=notification.context['group'])
    tags.update(group_tags(group))
    return tags
Beispiel #3
0
def invitation_created(invitation):
    write_points([{
        'measurement': 'karrot.events',
        'tags': group_tags(invitation.group),
        'fields': {
            'invitation_created': 1
        },
    }])
Beispiel #4
0
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
Beispiel #5
0
def pickup_notification_email(group, **kwargs):
    write_points([{
        'measurement': 'karrot.email.pickup_notification',
        'tags': group_tags(group),
        'fields': {
            'value': 1,
            **kwargs
        },
    }])
Beispiel #6
0
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
Beispiel #7
0
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,
    }]
Beispiel #8
0
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,
    }]
Beispiel #9
0
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
        },
    }])
Beispiel #10
0
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,
    }])
Beispiel #11
0
def offer_tags(offer):
    return group_tags(offer.group)
Beispiel #12
0
def pickup_tags(pickup):
    tags = group_tags(pickup.place.group)
    tags.update({
        'place': str(pickup.place.id),
    })
    return tags
Beispiel #13
0
def issue_tags(issue):
    tags = group_tags(issue.group)
    tags.update({
        'type': issue.type,
    })
    return tags