def update_support_forum_contributors_metric(day=None):
 if day:
  start = end = day
 else:
  latest_metric = _get_latest_metric(SUPPORT_FORUM_CONTRIBUTORS_METRIC_CODE)
  if (latest_metric is not None):
   start = (latest_metric.end + timedelta(days=1))
  else:
   start = date(2011, 1, 1)
  end = (date.today() - timedelta(days=1))
 day = start
 while (day <= end):
  thirty_days_back = (day - timedelta(days=30))
  contributors = Answer.objects.exclude(creator=F('question__creator')).filter(created__gte=thirty_days_back, created__lt=day).values('creator').annotate(count=Count('creator')).filter(count__gte=10)
  count = contributors.count()
  metric_kind = MetricKind.objects.get(code=SUPPORT_FORUM_CONTRIBUTORS_METRIC_CODE)
  Metric.objects.create(kind=metric_kind, start=thirty_days_back, end=day, value=count)
  day = (day + timedelta(days=1))

def update_support_forum_contributors_metric ( day = None ) : if day : start = end = day else : latest_metric = _get_latest_metric ( SUPPORT_FORUM_CONTRIBUTORS_METRIC_CODE ) if ( latest_metric is not None ) : start = ( latest_metric . end + timedelta ( days = 1 ) ) else : start = date ( 2011 , 1 , 1 ) end = ( date . today ( ) - timedelta ( days = 1 ) ) day = start while ( day <= end ) : thirty_days_back = ( day - timedelta ( days = 30 ) ) contributors = Answer . objects . exclude ( creator = F ( 'question__creator' ) ) . filter ( created__gte = thirty_days_back , created__lt = day ) . values ( 'creator' ) . annotate ( count = Count ( 'creator' ) ) . filter ( count__gte = 10 ) count = contributors . count ( ) metric_kind = MetricKind . objects . get ( code = SUPPORT_FORUM_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 support forum contributor counts .