Beispiel #1
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 #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 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)
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 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)
Beispiel #6
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
Beispiel #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
Beispiel #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
Beispiel #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