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
def _trending_for_yesterday(metric=None):
    today = datetime.date.today()
    yesterday_date = today - datetime.timedelta(days=1)
    previous_week_date = today - datetime.timedelta(weeks=1)
    previous_month_date = get_previous_month(today)

    data = {
        'yesterday': 0,
        'previous_week': 0,
        'previous_month': 0,
    }

    try:
        yesterday = MetricDay.objects.get(metric=metric,
                                          created=yesterday_date)
        data['yesterday'] = yesterday.num
    except ObjectDoesNotExist:
        pass

    try:
        previous_week = MetricDay.objects.get(metric=metric,
                                              created=previous_week_date)
        data['previous_week'] = previous_week.num
    except ObjectDoesNotExist:
        pass

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

    return data
Exemple #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
Exemple #4
0
def _trending_for_yesterday(metric=None):
    today = datetime.date.today()
    yesterday_date = today - datetime.timedelta(days=1)
    previous_week_date = today - datetime.timedelta(weeks=1)
    previous_month_date = get_previous_month(today)

    data = {
            'yesterday': 0,
            'previous_week': 0,
            'previous_month': 0,
    }

    try:
        yesterday = MetricDay.objects.get(metric=metric, created=yesterday_date)
        data['yesterday'] = yesterday.num
    except ObjectDoesNotExist:
        pass

    try: 
        previous_week = MetricDay.objects.get(metric=metric, created=previous_week_date)
        data['previous_week'] = previous_week.num
    except ObjectDoesNotExist:
        pass

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

    return data
Exemple #5
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)
Exemple #6
0
    def test_missing_trending(self):
        this_week_date = week_for_date(datetime.date.today())
        previous_week_date = this_week_date - datetime.timedelta(weeks=1)
        previous_month_date = get_previous_month(this_week_date)
        previous_year_date = get_previous_year(this_week_date)

        MetricWeek.objects.create(metric=self.metric1, num=5, created=this_week_date)
        MetricWeek.objects.create(metric=self.metric1, num=4, created=previous_week_date)
        MetricWeek.objects.create(metric=self.metric1, num=3, created=previous_month_date)

        data = _trending_for_week(self.metric1)
        self.assertEqual(data['week'], 5)
        self.assertEqual(data['previous_week'], 4)
        self.assertEqual(data['previous_month_week'], 3)
        self.assertEqual(data['previous_year_week'], 0)
Exemple #7
0
    def test_trending_for_yesterday(self):
        """ Test yesterday trending """
        today = datetime.date.today()
        yesterday_date = today - datetime.timedelta(days=1)
        previous_week_date = today - datetime.timedelta(weeks=1)
        previous_month_date = get_previous_month(today)

        MetricDay.objects.create(metric=self.metric1, num=5, created=yesterday_date)
        MetricDay.objects.create(metric=self.metric1, num=4, created=previous_week_date)
        MetricDay.objects.create(metric=self.metric1, num=3, created=previous_month_date)

        data = _trending_for_yesterday(self.metric1)
        self.assertEqual(data['yesterday'], 5)
        self.assertEqual(data['previous_week'], 4)
        self.assertEqual(data['previous_month'], 3)
def _trending_for_week(metric=None):
    this_week_date = week_for_date(datetime.date.today())
    previous_week_date = this_week_date - datetime.timedelta(weeks=1)
    previous_month_week_date = get_previous_month(this_week_date)
    previous_year_week_date = get_previous_year(this_week_date)

    data = {
        'week': 0,
        'previous_week': 0,
        'previous_month_week': 0,
        'previous_year_week': 0,
    }

    try:
        week = MetricWeek.objects.get(metric=metric, created=this_week_date)
        data['week'] = week.num
    except ObjectDoesNotExist:
        pass

    try:
        previous_week = MetricWeek.objects.get(metric=metric,
                                               created=previous_week_date)
        data['previous_week'] = previous_week.num
    except ObjectDoesNotExist:
        pass

    try:
        previous_month_week = MetricWeek.objects.get(
            metric=metric, created=previous_month_week_date)
        data['previous_month_week'] = previous_month_week.num
    except ObjectDoesNotExist:
        pass

    try:
        previous_year_week = MetricWeek.objects.get(
            metric=metric, created=previous_year_week_date)
        data['previous_year_week'] = previous_year_week.num
    except ObjectDoesNotExist:
        pass

    return data
Exemple #9
0
def _trending_for_week(metric=None):
    this_week_date = week_for_date(datetime.date.today())
    previous_week_date = this_week_date - datetime.timedelta(weeks=1)
    previous_month_week_date = get_previous_month(this_week_date)
    previous_year_week_date = get_previous_year(this_week_date)

    data = {
            'week': 0,
            'previous_week': 0,
            'previous_month_week': 0,
            'previous_year_week': 0,
    }

    try:
        week = MetricWeek.objects.get(metric=metric, created=this_week_date)
        data['week'] = week.num
    except ObjectDoesNotExist:
        pass

    try:
        previous_week = MetricWeek.objects.get(metric=metric, created=previous_week_date)
        data['previous_week'] = previous_week.num
    except ObjectDoesNotExist:
        pass

    try:
        previous_month_week = MetricWeek.objects.get(metric=metric, created=previous_month_week_date)
        data['previous_month_week'] = previous_month_week.num
    except ObjectDoesNotExist:
        pass

    try:
        previous_year_week = MetricWeek.objects.get(metric=metric, created=previous_year_week_date)
        data['previous_year_week'] = previous_year_week.num
    except ObjectDoesNotExist:
        pass

    return data
Exemple #10
0
def _trending_for_yesterday(metric=None):
    today = datetime.date.today()
    yesterday_date = today - datetime.timedelta(days=1)
    minus2_date = today - datetime.timedelta(days=2)
    minus3_date = today - datetime.timedelta(days=3)
    minus4_date = today - datetime.timedelta(days=4)
    minus5_date = today - datetime.timedelta(days=5)
    minus6_date = today - datetime.timedelta(days=6)
    previous_week_date = today - datetime.timedelta(weeks=1)
    previous_month_date = get_previous_month(today)

    data = {
            'yesterday': 0,
            'minus2': 0,
            'minus3': 0,
            'minus4': 0,
            'minus5': 0,
            'minus6': 0,
            'previous_week': 0,
            'previous_month': 0,
    }

    try:
        yesterday = MetricDay.objects.get(metric=metric, created=yesterday_date)
        data['yesterday'] = yesterday.num
    except ObjectDoesNotExist:
        pass
    
    try:
        metricdata = MetricDay.objects.get(metric=metric, created=minus2_date)
        data['minus2'] = metricdata.num
    except ObjectDoesNotExist:
        pass

    try:
        metricdata = MetricDay.objects.get(metric=metric, created=minus3_date)
        data['minus3'] = metricdata.num
    except ObjectDoesNotExist:
        pass

    try:
        metricdata = MetricDay.objects.get(metric=metric, created=minus4_date)
        data['minus4'] = metricdata.num
    except ObjectDoesNotExist:
        pass

    try:
        metricdata = MetricDay.objects.get(metric=metric, created=minus5_date)
        data['minus5'] = metricdata.num
    except ObjectDoesNotExist:
        pass

    try:
        metricdata = MetricDay.objects.get(metric=metric, created=minus6_date)
        data['minus6'] = metricdata.num
    except ObjectDoesNotExist:
        pass

    try: 
        previous_week = MetricDay.objects.get(metric=metric, created=previous_week_date)
        data['previous_week'] = previous_week.num
    except ObjectDoesNotExist:
        pass

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

    return data