def update_aoa_contributors_metric(day=None):
 if day:
  start = end = day
 else:
  latest_metric = _get_latest_metric(AOA_CONTRIBUTORS_METRIC_CODE)
  if (latest_metric is not None):
   start = (latest_metric.end + timedelta(days=1))
  else:
   try:
    first_reply = Reply.objects.order_by('created')[0]
    start = (first_reply.created.date() + timedelta(days=30))
   except IndexError:
    return
  end = (date.today() - timedelta(days=1))
 day = start
 while (day <= end):
  thirty_days_back = (day - timedelta(days=30))
  contributors = Reply.objects.filter(created__gte=thirty_days_back, created__lt=day).values_list('twitter_username').distinct()
  count = contributors.count()
  metric_kind = MetricKind.objects.get(code=AOA_CONTRIBUTORS_METRIC_CODE)
  Metric.objects.create(kind=metric_kind, start=thirty_days_back, end=day, value=count)
  day = (day + timedelta(days=1))

def update_aoa_contributors_metric ( day = None ) : if day : start = end = day else : latest_metric = _get_latest_metric ( AOA_CONTRIBUTORS_METRIC_CODE ) if ( latest_metric is not None ) : start = ( latest_metric . end + timedelta ( days = 1 ) ) else : try : first_reply = Reply . objects . order_by ( 'created' ) [ 0 ] start = ( first_reply . created . date ( ) + timedelta ( days = 30 ) ) except IndexError : return end = ( date . today ( ) - timedelta ( days = 1 ) ) day = start while ( day <= end ) : thirty_days_back = ( day - timedelta ( days = 30 ) ) contributors = Reply . objects . filter ( created__gte = thirty_days_back , created__lt = day ) . values_list ( 'twitter_username' ) . distinct ( ) count = contributors . count ( ) metric_kind = MetricKind . objects . get ( code = AOA_CONTRIBUTORS_METRIC_CODE ) Metric . objects . create ( kind = metric_kind , start = thirty_days_back , end = day , value = count ) day = ( day + timedelta ( days = 1 ) )
calculate and save the aoa contributor counts .