Esempio n. 1
0
        def render_as_json(self, partners, with_activity):
            if with_activity:
                # get reply statistics
                total = DailyCount.get_by_partner(partners, DailyCount.TYPE_REPLIES, None, None).scope_totals()
                this_month = DailyCount.get_by_partner(partners, DailyCount.TYPE_REPLIES,
                                                       *month_range(0)).scope_totals()
                last_month = DailyCount.get_by_partner(partners, DailyCount.TYPE_REPLIES,
                                                       *month_range(-1)).scope_totals()

            def as_json(partner):
                obj = partner.as_json()
                if with_activity:
                    obj['replies'] = {
                        'this_month': this_month.get(partner, 0),
                        'last_month': last_month.get(partner, 0),
                        'total': total.get(partner, 0)
                    }
                return obj

            return JsonResponse({'results': [as_json(p) for p in partners]})
Esempio n. 2
0
 def get_summary(self, partner):
     return {
         "total_replies":
         DailyCount.get_by_partner([partner],
                                   DailyCount.TYPE_REPLIES).total(),
         "cases_open":
         Case.objects.filter(org=partner.org,
                             assignee=partner,
                             closed_on=None).count(),
         "cases_closed":
         Case.objects.filter(
             org=partner.org,
             assignee=partner).exclude(closed_on=None).count(),
     }
Esempio n. 3
0
        def render_as_json(self, partners, with_activity):
            if with_activity:
                # get reply statistics
                replies_total = DailyCount.get_by_partner(
                    partners, DailyCount.TYPE_REPLIES, None,
                    None).scope_totals()
                replies_this_month = DailyCount.get_by_partner(
                    partners, DailyCount.TYPE_REPLIES,
                    *month_range(0)).scope_totals()
                replies_last_month = DailyCount.get_by_partner(
                    partners, DailyCount.TYPE_REPLIES,
                    *month_range(-1)).scope_totals()
                average_referral_response_time_this_month = DailySecondTotalCount.get_by_partner(
                    partners, DailySecondTotalCount.TYPE_TILL_REPLIED,
                    *month_range(0))
                average_referral_response_time_this_month = average_referral_response_time_this_month.scope_averages(
                )
                average_closed_this_month = DailySecondTotalCount.get_by_partner(
                    partners, DailySecondTotalCount.TYPE_TILL_CLOSED,
                    *month_range(0))
                average_closed_this_month = average_closed_this_month.scope_averages(
                )

                # get cases statistics
                cases_total = DailyCount.get_by_partner(
                    partners, DailyCount.TYPE_CASE_OPENED, None,
                    None).scope_totals()
                cases_opened_this_month = DailyCount.get_by_partner(
                    partners, DailyCount.TYPE_CASE_OPENED,
                    *month_range(0)).scope_totals()
                cases_closed_this_month = DailyCount.get_by_partner(
                    partners, DailyCount.TYPE_CASE_CLOSED,
                    *month_range(0)).scope_totals()

            def as_json(partner):
                obj = partner.as_json()
                if with_activity:
                    obj.update({
                        "replies": {
                            "this_month":
                            replies_this_month.get(partner, 0),
                            "last_month":
                            replies_last_month.get(partner, 0),
                            "total":
                            replies_total.get(partner, 0),
                            "average_referral_response_time_this_month":
                            humanize_seconds(
                                average_referral_response_time_this_month.get(
                                    partner, 0)),
                        },
                        "cases": {
                            "average_closed_this_month":
                            humanize_seconds(
                                average_closed_this_month.get(partner, 0)),
                            "opened_this_month":
                            cases_opened_this_month.get(partner, 0),
                            "closed_this_month":
                            cases_closed_this_month.get(partner, 0),
                            "total":
                            cases_total.get(partner, 0),
                        },
                    })
                return obj

            return JsonResponse({"results": [as_json(p) for p in partners]})
Esempio n. 4
0
 def get_summary(self, partner):
     return {
         'total_replies': DailyCount.get_by_partner([partner], DailyCount.TYPE_REPLIES).total(),
         'cases_open': Case.objects.filter(org=partner.org, assignee=partner, closed_on=None).count(),
         'cases_closed': Case.objects.filter(org=partner.org, assignee=partner).exclude(closed_on=None).count()
     }