Skip to content

Commit

Permalink
added a method to calculate the total of aggregated weeks on MetricWe…
Browse files Browse the repository at this point in the history
…ek model
  • Loading branch information
rmaceissoft committed Jan 3, 2012
1 parent 8275809 commit d9d0e4a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions user_metrics/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
import datetime

from user_metrics.models import MetricWeek

def week_for_date(date):
return date - datetime.timedelta(days=date.weekday())


def total_weeks_aggregated():
"""
return total of weeks aggregates to MetricWeek model
"""
try:
first_week = MetricWeek.objects.all().order_by('-date_up')[0].date_up
except IndexError:
first_week = week_for_date(datetime.date.today())
return (datetime.date.today() - first_week).days / 7

0 comments on commit d9d0e4a

Please sign in to comment.