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()
Esempio n. 2
0
    def test_trending_for_year(self):
        """ Test yearly trending data """
        this_year_date = year_for_date(datetime.date.today())
        previous_year_date = get_previous_year(this_year_date)

        MetricYear.objects.create(metric=self.metric1, num=5, created=this_year_date)
        MetricYear.objects.create(metric=self.metric1, num=4, created=previous_year_date)

        data = _trending_for_year(self.metric1)
        self.assertEqual(data['year'], 5)
        self.assertEqual(data['previous_year'], 4)
Esempio n. 3
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()
Esempio n. 4
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() 
Esempio n. 7
0
def _trending_for_year(metric=None):
    this_year_date = year_for_date(datetime.date.today())
    previous_year_date = get_previous_year(this_year_date)

    data = {
            'year': 0,
            'previous_year': 0,
    }

    try:
        year = MetricYear.objects.get(metric=metric, created=this_year_date)
        data['year'] = year.num
    except ObjectDoesNotExist:
        pass

    try:
        previous_year = MetricYear.objects.get(metric=metric, created=previous_year_date)
        data['previous_year'] = previous_year.num
    except ObjectDoesNotExist:
        pass

    return data
Esempio n. 8
0
def _trending_for_year(metric=None):
    this_year_date = year_for_date(datetime.date.today())
    previous_year_date = get_previous_year(this_year_date)

    data = {
            'year': 0,
            'previous_year': 0,
    }

    try:
        year = MetricYear.objects.get(metric=metric, created=this_year_date)
        data['year'] = year.num
    except ObjectDoesNotExist:
        pass

    try:
        previous_year = MetricYear.objects.get(metric=metric, created=previous_year_date)
        data['previous_year'] = previous_year.num
    except ObjectDoesNotExist:
        pass

    return data
    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()