Пример #1
0
    def profile_stats(self):
        from mresponse.moderations.models import Moderation

        current_window_start = datetime.combine(
            (now() - timedelta(days=STATS_ROLLING_WINDOW_SIZE)).date(),
            datetime.min.time(),
            pytz.UTC,
        )

        start_previous_window = current_window_start - timedelta(
            days=STATS_ROLLING_WINDOW_SIZE)
        end_previous_window = current_window_start
        current = Moderation.objects.filter(
            response__author=self.user,
            submitted_at__gte=current_window_start).aggregate(
                total_moderations_count=Count("id"),
                positive_in_tone_count=Count("id",
                                             filter=Q(positive_in_tone=True)),
                addressing_the_issue_count=Count(
                    "id", filter=Q(addressing_the_issue=True)),
                personal_count=Count("id", filter=Q(personal=True)),
            )

        previous = Moderation.objects.filter(
            response__author=self.user,
            submitted_at__lt=end_previous_window,
            submitted_at__gte=start_previous_window,
        ).aggregate(
            total_moderations_count=Count("id"),
            positive_in_tone_count=Count("id",
                                         filter=Q(positive_in_tone=True)),
            addressing_the_issue_count=Count(
                "id", filter=Q(addressing_the_issue=True)),
            personal_count=Count("id", filter=Q(personal=True)),
        )

        return dict(
            current_count=current["total_moderations_count"],
            previous_count=previous["total_moderations_count"],
            positive_in_tone_count=current["positive_in_tone_count"],
            positive_in_tone_change=change_calculation(
                previous["positive_in_tone_count"],
                current["positive_in_tone_count"]),
            addressing_the_issue_count=current["addressing_the_issue_count"],
            addressing_the_issue_change=change_calculation(
                previous["addressing_the_issue_count"],
                current["addressing_the_issue_count"],
            ),
            personal_count=current["personal_count"],
            personal_change=change_calculation(previous["personal_count"],
                                               current["personal_count"]),
        )
Пример #2
0
 def test_value_1_is_less_than_value_2(self):
     self.assertEqual(change_calculation(1, 10), 9.0)
Пример #3
0
 def test_value_1_is_zero(self):
     self.assertEqual(change_calculation(0, 10), None)
Пример #4
0
 def test_value_1_is_greater_than_value_2(self):
     self.assertEqual(change_calculation(10, 1), -0.9)