7
7
# David Planella <david.planella@ubuntu.com>
8
8
# Kyle Nitzsche <kyle.nitzsche@canonical.com>
10
# Copyright (c) 2009, 2010 Canonical Ltd.
10
# Copyright (c) 2009, 2010, 2011 Canonical Ltd.
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
50
def calculate_stats(options, settings, templates):
50
def calculate_stats(options, settings, templates, lp_srcpkgs):
52
52
# To hold all statistics.
59
59
translated_percent_min = int(settings['translated_percent_min'])
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'])
61
# get the total number of translatable messages in the curret set of
63
TOTAL = int(templates.get_total_number_messages_in_working_templates())
64
#print "TOTAL %s" % TOTAL
66
# get the working templates as a set of tuples (src, pot)
67
working_templates = templates.working_src_template_set
69
70
languages = Languages.LanguageSet()
70
71
languages.get_all_languages(options, options.languages_file)
72
73
# Skip 2 lines from the package stats file
75
# Read all stats from the package stats file
76
for line in gzip.open(pkg_stats, 'rb').readlines():
80
(pkg, domain, pot, date_pot, date_translation, lang, translated,
81
unreviewed, changed, total) = line.split('|')
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:
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:
84
int(record['translated']),
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