~ubuntu-translations-coordinators/ubuntu-translations/ul10n-stats-refactored

« back to all changes in this revision

Viewing changes to common/ul10n_stats_calc.py

  • Committer: Kyle Nitzsche
  • Date: 2011-02-18 18:15:19 UTC
  • Revision ID: kyle.nitzsche@canonical.com-20110218181519-lf4gr25xsa5tyeqv
create class (in common/LpSrcPkgs.py) to represent and provide access to
src pkg data exported from LP. Create class instance in 
ubuntu-translations-stats.py, then pass it to common/ul10n_stats_calc.py
which can use it instead of reading the export file. This "Classification"
brings Pkg LP Exports under the same treatment I did previously for LP
template exports. And it will facilitate refactoring 
common/ul10n_stats_calc.py, which is a lot of stuff mixed together and is
not sufficiently modular for maintainability.

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
#   David Planella <david.planella@ubuntu.com>
8
8
#   Kyle Nitzsche <kyle.nitzsche@canonical.com>
9
9
#
10
 
# Copyright (c) 2009, 2010 Canonical Ltd.
 
10
# Copyright (c) 2009, 2010, 2011 Canonical Ltd.
11
11
#
12
12
# This program is free software: you can redistribute it and/or modify it
13
13
# under the terms of the GNU General Public License version 3, as published
47
47
            'total': total,
48
48
            }
49
49
 
50
 
def calculate_stats(options, settings, templates):
 
50
def calculate_stats(options, settings, templates, lp_srcpkgs):
51
51
 
52
52
    # To hold all statistics.
53
53
    stats = {}
58
58
    # set up some vars
59
59
    translated_percent_min = int(settings['translated_percent_min'])
60
60
 
61
 
    TOTAL = 0
62
 
    working_templates = set()
63
 
    final_templates = list()
64
 
    for record in templates.templates_project:
65
 
        working_templates.add((record['src'], record['template']))
66
 
        final_templates.append(record)
67
 
        TOTAL += int(record['total'])
68
 
 
 
61
    # get the total number of translatable messages in the curret set of
 
62
    # working templates
 
63
    TOTAL = int(templates.get_total_number_messages_in_working_templates())
 
64
    #print "TOTAL %s" % TOTAL
 
65
 
 
66
    # get the working templates as a set of tuples (src, pot)
 
67
    working_templates = templates.working_src_template_set
 
68
 
 
69
    # get up languages
69
70
    languages = Languages.LanguageSet()
70
71
    languages.get_all_languages(options, options.languages_file)
71
72
 
72
73
    # Skip 2 lines from the package stats file
73
74
    started = 2
74
75
 
75
 
    # Read all stats from the package stats file
76
 
    for line in gzip.open(pkg_stats, 'rb').readlines():
77
 
        if started > 0:
78
 
            started -= 1
79
 
        elif '|' in line:
80
 
            (pkg, domain, pot, date_pot, date_translation, lang, translated,
81
 
                unreviewed, changed, total) = line.split('|')
82
 
            pkg = pkg.strip()
83
 
            pot = pot.strip()
84
 
            lang = lang.strip()
85
 
            translated = int(translated.strip())
86
 
            total = int(total.strip())
 
76
    # go through lp_srcpkgs object. For each, if the srcpkg/template
 
77
    # is in working templates, add the translation data to stats
 
78
    for record in lp_srcpkgs.srcpkgs:
87
79
 
88
 
            if (pkg, pot) in working_templates and lang in languages:
89
 
                addToLanguage(stats, lang, translated, total)
 
80
        if (record['src'], record['template']) in working_templates \
 
81
            and record['language'] in languages:
 
82
            addToLanguage(stats,
 
83
                    record['language'],
 
84
                    int(record['translated']),
 
85
                    int(record['total']),
 
86
                    )
90
87
                ## Prints the per-language detailed template statistics
91
88
                ## Caveat: if there are no translations for a template in a
92
89
                ## given language, the template will not be listed
104
101
    languages_supported = 0
105
102
    for lang in languages_available:
106
103
        if lang in languages:
107
 
            translated_percent = 100.00 * stats[lang]['translated'] / TOTAL
 
104
            #print "TOTAL %d" % TOTAL
 
105
            print str(stats[lang]['translated'])
 
106
            translated_percent = 100.00 * int(stats[lang]['translated']) / TOTAL
108
107
            language_stats.append({
109
108
                "language": str(languages[lang]),
110
109
                "translated": translated_percent