def handle_noargs(self, **options):
        """ Aggregate Application Metrics """

        # Aggregate Items
        items = MetricItem.objects.all()

        for i in items:
            # Daily Aggregation
            day, create = MetricDay.objects.get_or_create(metric=i.metric, created=i.created)

            day.num = day.num + i.num
            day.save()

            # Weekly Aggregation
            week_date = week_for_date(i.created)
            week, create = MetricWeek.objects.get_or_create(metric=i.metric, created=week_date)

            week.num = week.num + i.num
            week.save()

            # Monthly Aggregation
            month_date = month_for_date(i.created)
            month, create = MetricMonth.objects.get_or_create(metric=i.metric, created=month_date)
            month.num = month.num + i.num
            month.save()

            # Yearly Aggregation
            year_date = year_for_date(i.created)
            year, create = MetricYear.objects.get_or_create(metric=i.metric, created=year_date)
            year.num = year.num + i.num
            year.save()

        # Kill off our items
        items.delete()
Beispiel #2
0
def _trending_for_month(metric=None):
    this_month_date = month_for_date(datetime.date.today())
    previous_month_date = get_previous_month(this_month_date)
    previous_month_year_date = get_previous_year(this_month_date)

    data = {'month': 0, 'previous_month': 0, 'previous_month_year': 0}

    try:
        month = MetricMonth.objects.get(metric=metric, created=this_month_date)
        data['month'] = month.num
    except ObjectDoesNotExist:
        pass

    try:
        previous_month = MetricMonth.objects.get(metric=metric,
                                                 created=previous_month_date)
        data['previous_month'] = previous_month.num
    except ObjectDoesNotExist:
        pass

    try:
        previous_month_year = MetricMonth.objects.get(
            metric=metric, created=previous_month_year_date)
        data['previous_month_year'] = previous_month_year.num
    except ObjectDoesNotExist:
        pass

    return data
Beispiel #3
0
def _trending_for_month(metric=None):
    this_month_date = month_for_date(datetime.date.today())
    previous_month_date = get_previous_month(this_month_date)
    previous_month_year_date = get_previous_year(this_month_date)

    data = {
            'month': 0,
            'previous_month': 0,
            'previous_month_year': 0
    }

    try:
        month = MetricMonth.objects.get(metric=metric, created=this_month_date)
        data['month'] = month.num
    except ObjectDoesNotExist:
        pass

    try:
        previous_month = MetricMonth.objects.get(metric=metric, created=previous_month_date)
        data['previous_month'] = previous_month.num
    except ObjectDoesNotExist:
        pass

    try:
        previous_month_year = MetricMonth.objects.get(metric=metric, created=previous_month_year_date)
        data['previous_month_year'] = previous_month_year.num
    except ObjectDoesNotExist:
        pass

    return data
Beispiel #4
0
    def test_trending_for_month(self):
        """ Test monthly trending data """
        this_month_date = month_for_date(datetime.date.today())
        previous_month_date = get_previous_month(this_month_date)
        previous_month_year_date = get_previous_year(this_month_date)

        MetricMonth.objects.create(metric=self.metric1, num=5, created=this_month_date)
        MetricMonth.objects.create(metric=self.metric1, num=4, created=previous_month_date)
        MetricMonth.objects.create(metric=self.metric1, num=3, created=previous_month_year_date)

        data = _trending_for_month(self.metric1)
        self.assertEqual(data['month'], 5)
        self.assertEqual(data['previous_month'], 4)
        self.assertEqual(data['previous_month_year'], 3)
Beispiel #5
0
    def handle(self, *args, **options):
        """ Aggregate Application Metrics """

        backend = get_backend()

        # If using Mixpanel this command is a NOOP
        if backend == 'app_metrics.backends.mixpanel':
            print(
                "Useless use of metrics_aggregate when using Mixpanel backend")
            return

        # Aggregate Items
        items = MetricItem.objects.all().order_by('id')

        while items.exists():
            with transaction.atomic():
                batch = items[0:BATCH_SIZE]
                for i in batch:
                    # Daily Aggregation
                    day, create = MetricDay.objects.get_or_create(
                        metric=i.metric, created=i.created)

                    day.num = day.num + i.num
                    day.save()

                    # Weekly Aggregation
                    week_date = week_for_date(i.created)
                    week, create = MetricWeek.objects.get_or_create(
                        metric=i.metric, created=week_date)

                    week.num = week.num + i.num
                    week.save()

                    # Monthly Aggregation
                    month_date = month_for_date(i.created)
                    month, create = MetricMonth.objects.get_or_create(
                        metric=i.metric, created=month_date)
                    month.num = month.num + i.num
                    month.save()

                    # Yearly Aggregation
                    year_date = year_for_date(i.created)
                    year, create = MetricYear.objects.get_or_create(
                        metric=i.metric, created=year_date)
                    year.num = year.num + i.num
                    year.save()

                # Kill off our items
                items.filter(id__in=[i.id for i in batch]).delete()
Beispiel #6
0
    def handle_noargs(self, **options):
        """ Aggregate Application Metrics """

        backend = get_backend()

        # If using Mixpanel this command is a NOOP
        if backend == 'app_metrics.backends.mixpanel':
            print("Useless use of metrics_aggregate when using Mixpanel backend")
            return

        # Aggregate Items
        items = MetricItem.objects.all().order_by('id')

        while items.exists():
            with transaction.atomic():
                batch = items[0:BATCH_SIZE]
                for i in batch:
                    # Daily Aggregation
                    day,create = MetricDay.objects.get_or_create(metric=i.metric,
                                                                 created=i.created)

                    day.num = day.num + i.num
                    day.save()

                    # Weekly Aggregation
                    week_date = week_for_date(i.created)
                    week, create = MetricWeek.objects.get_or_create(metric=i.metric,
                                                                    created=week_date)

                    week.num = week.num + i.num
                    week.save()

                    # Monthly Aggregation
                    month_date = month_for_date(i.created)
                    month, create = MetricMonth.objects.get_or_create(metric=i.metric,
                                                                      created=month_date)
                    month.num = month.num + i.num
                    month.save()

                    # Yearly Aggregation
                    year_date = year_for_date(i.created)
                    year, create = MetricYear.objects.get_or_create(metric=i.metric,
                                                                    created=year_date)
                    year.num = year.num + i.num
                    year.save()

                # Kill off our items
                items.filter(id__in=[i.id for i in batch]).delete()
    def handle_noargs(self, **options):
        """ Aggregate Application Metrics """

        backend = get_backend()

        # If using Mixpanel this command is a NOOP
        if backend == 'app_metrics.backends.mixpanel':
            print "Useless use of metrics_aggregate when using Mixpanel backend"
            return

        # Aggregate Items
        items = MetricItem.objects.all()

        for i in items:
            # Daily Aggregation
            day, create = MetricDay.objects.get_or_create(metric=i.metric,
                                                          created=i.created)

            day.num = day.num + i.num
            day.save()

            # Weekly Aggregation
            week_date = week_for_date(i.created)
            week, create = MetricWeek.objects.get_or_create(metric=i.metric,
                                                            created=week_date)

            week.num = week.num + i.num
            week.save()

            # Monthly Aggregation
            month_date = month_for_date(i.created)
            month, create = MetricMonth.objects.get_or_create(
                metric=i.metric, created=month_date)
            month.num = month.num + i.num
            month.save()

            # Yearly Aggregation
            year_date = year_for_date(i.created)
            year, create = MetricYear.objects.get_or_create(metric=i.metric,
                                                            created=year_date)
            year.num = year.num + i.num
            year.save()

        # Kill off our items
        items.delete()
    def handle_noargs(self, **options): 
        """ Aggregate Application Metrics """ 

        backend = get_backend() 

        # If using Mixpanel this command is a NOOP
        if backend == 'app_metrics.backends.mixpanel': 
            print "Useless use of metrics_aggregate when using Mixpanel backend"
            return 

        # Aggregate Items
        items = MetricItem.objects.filter(site_id=settings.SITE_ID)

        for i in items: 
            # Daily Aggregation 
            day,create = MetricDay.objects.get_or_create(metric=i.metric, 
                                                         created=i.created)

            day.num = day.num + i.num
            day.save() 

            # Weekly Aggregation 
            week_date = week_for_date(i.created)
            week, create = MetricWeek.objects.get_or_create(metric=i.metric,
                                                            created=week_date)

            week.num = week.num + i.num 
            week.save() 

            # Monthly Aggregation 
            month_date = month_for_date(i.created) 
            month, create = MetricMonth.objects.get_or_create(metric=i.metric,
                                                              created=month_date)
            month.num = month.num + i.num 
            month.save() 

            # Yearly Aggregation 
            year_date = year_for_date(i.created) 
            year, create = MetricYear.objects.get_or_create(metric=i.metric,
                                                              created=year_date)
            year.num = year.num + i.num 
            year.save() 

        # Kill off our items 
        items.delete() 
    def handle(self, **options):
        """ Aggregate Application Metrics """

        backend = get_backend()

        # If using Mixpanel this command is a NOOP
        if backend == 'app_metrics.backends.mixpanel':
            print "Useless use of metrics_aggregate when using Mixpanel backend"
            return

        # Aggregate Items
        items = MetricItem.objects.all()

        for i in items:
            # Daily Aggregation
            try:
                days = MetricDay.objects.filter(metric=i.metric, created=i.created)
            except ObjectDoesNotExist:
                day,create = MetricDay.objects.get_or_create(metric=i.metric, created=i.created)
            else:
                if days.count() > 1:
                     days = days.exclude(id=days[0].id)
                     days.delete()
                try:
                    day = days[0]
                except IndexError:
                    day,create = MetricDay.objects.get_or_create(metric=i.metric, created=i.created)

            day.num = day.num + i.num
            day.save()

            # Weekly Aggregation
            week_date = week_for_date(i.created)
            try:
                weeks = MetricWeek.objects.filter(metric=i.metric, created=week_date)
            except ObjectDoesNotExist:
                week,create = MetricWeek.objects.get_or_create(metric=i.metric, created=week_date)
            else:
                if weeks.count() > 1:
                     weeks = weeks.exclude(id=weeks[0].id)
                     weeks.delete()
                try:
                    week = weeks[0]
                except IndexError:
                    week,create = MetricWeek.objects.get_or_create(metric=i.metric, created=week_date)

            week.num = week.num + i.num
            week.save()

            # Monthly Aggregation
            month_date = month_for_date(i.created)
            try:
                months = MetricMonth.objects.filter(metric=i.metric, created=month_date)
            except ObjectDoesNotExist:
                month,create = MetricMonth.objects.get_or_create(metric=i.metric, created=month_date)
            else:
                if months.count() > 1:
                     months = months.exclude(id=months[0].id)
                     months.delete()
                try:
                    month = months[0]
                except IndexError:
                    month,create = MetricMonth.objects.get_or_create(metric=i.metric, created=month_date)

            # Yearly Aggregation
            year_date = year_for_date(i.created)
            try:
                years = MetricYear.objects.filter(metric=i.metric, created=year_date)
            except ObjectDoesNotExist:
                years,create = MetricYear.objects.get_or_create(metric=i.metric, created=year_date)
            else:
                if years.count() > 1:
                     years = years.exclude(id=years[0].id)
                     years.delete()
                try:
                    year = years[0]
                except IndexError:
                    year,create = MetricYear.objects.get_or_create(metric=i.metric, created=year_date)

            year.num = year.num + i.num
            year.save()

        # Kill off our items
        items.delete()