

@cronjobs.register
def update_l10n_coverage_metrics():
    'Calculate and store the l10n metrics for each locale/product.\n\n    The metrics are:\n    * Percent localized of top 20 articles\n    * Percent localized of all articles\n    '
    today = date.today()
    for locale in settings.SUMO_LANGUAGES:
        if (locale == settings.WIKI_DEFAULT_LANGUAGE):
            continue
        for product in ([None] + list(Product.objects.filter(visible=True))):
            rows = l10n_overview_rows(locale=locale, product=product)
            top20 = rows['top-20']
            try:
                percent = ((100.0 * float(top20['numerator'])) / top20['denominator'])
            except ZeroDivisionError:
                percent = 0.0
            WikiMetric.objects.create(code=L10N_TOP20_CODE, locale=locale, product=product, date=today, value=percent)
            top100 = rows['top-100']
            try:
                percent = ((100.0 * float(top100['numerator'])) / top100['denominator'])
            except ZeroDivisionError:
                percent = 0.0
            WikiMetric.objects.create(code=L10N_TOP100_CODE, locale=locale, product=product, date=today, value=percent)
            all_ = rows['all']
            try:
                percent = ((100 * float(all_['numerator'])) / all_['denominator'])
            except ZeroDivisionError:
                percent = 0.0
            WikiMetric.objects.create(code=L10N_ALL_CODE, locale=locale, product=product, date=today, value=percent)

dataset/ETHPy150Open mozilla/kitsune/kitsune/dashboards/cron.py update_l10n_coverage_metrics/original