@cronjobs.register
def update_l10n_metric():
 if settings.STAGE:
  return
 top_60_docs = _get_top_docs(60)
 end = (date.today() - timedelta(days=1))
 start = (end - timedelta(days=30))
 locale_visits = googleanalytics.visitors_by_locale(start, end)
 total_visits = sum(locale_visits.itervalues())
 coverage = 0
 for (locale, visits) in locale_visits.iteritems():
  if (locale == settings.WIKI_DEFAULT_LANGUAGE):
   num_docs = MAX_DOCS_UP_TO_DATE
   up_to_date_docs = MAX_DOCS_UP_TO_DATE
  else:
   (up_to_date_docs, num_docs) = _get_up_to_date_count(top_60_docs, locale)
  if (num_docs and total_visits):
   coverage += ((float(up_to_date_docs) / num_docs) * (float(visits) / total_visits))
 metric_kind = MetricKind.objects.get(code=L10N_METRIC_CODE)
 day = date.today()
 Metric.objects.create(kind=metric_kind, start=day, end=(day + timedelta(days=1)), value=int((coverage * 100)))

@ cronjobs . register def update_l10n_metric ( ) : if settings . STAGE : return top_60_docs = _get_top_docs ( 60 ) end = ( date . today ( ) - timedelta ( days = 1 ) ) start = ( end - timedelta ( days = 30 ) ) locale_visits = googleanalytics . visitors_by_locale ( start , end ) total_visits = sum ( locale_visits . itervalues ( ) ) coverage = 0 for ( locale , visits ) in locale_visits . iteritems ( ) : if ( locale == settings . WIKI_DEFAULT_LANGUAGE ) : num_docs = MAX_DOCS_UP_TO_DATE up_to_date_docs = MAX_DOCS_UP_TO_DATE else : ( up_to_date_docs , num_docs ) = _get_up_to_date_count ( top_60_docs , locale ) if ( num_docs and total_visits ) : coverage += ( ( float ( up_to_date_docs ) / num_docs ) * ( float ( visits ) / total_visits ) ) metric_kind = MetricKind . objects . get ( code = L10N_METRIC_CODE ) day = date . today ( ) Metric . objects . create ( kind = metric_kind , start = day , end = ( day + timedelta ( days = 1 ) ) , value = int ( ( coverage * 100 ) ) )
calculate new l10n coverage numbers and save .