1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
# Copyright 2009 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
from zope.interface import implements
from lp.translations.interfaces.rosettastats import IRosettaStats
# XXX: Carlos Perello Marin 2005-04-14 bug=396:
# This code should be change to be an adaptor.
class RosettaStats(object):
implements(IRosettaStats)
def testStatistics(self):
"""See IRosettaStats."""
if (self.newCount() + self.updatesCount()) != self.rosettaCount():
return False
if self.untranslatedCount() < 0:
return False
if self.untranslatedCount() > self.messageCount():
return False
if self.translatedCount() > self.messageCount():
return False
return True
def updateStatistics(self):
"""See IRosettaStats."""
# this method should be overridden by the objects that inherit from
# this class
pass
def messageCount(self):
"""See IRosettaStats."""
# This method should be overrided by the objects that inherit from
# this class
return 0
def currentCount(self, language=None):
"""See IRosettaStats."""
# This method should be overrided by the objects that inherit from
# this class
return 0
def updatesCount(self, language=None):
"""See IRosettaStats."""
# This method should be overrided by the objects that inherit from
# this class
return 0
def rosettaCount(self, language=None):
"""See IRosettaStats."""
# This method should be overrided by the objects that inherit from
# this class
return 0
def translatedCount(self, language=None):
"""See IRosettaStats."""
return self.currentCount(language) + self.rosettaCount(language)
def untranslatedCount(self, language=None):
"""See IRosettaStats."""
untranslated = self.messageCount() - self.translatedCount(language)
# Statistics should not be ever less than 0
assert untranslated >= 0, (
'Stats error in %r id %d, %d untranslated' % (
self, self.id, untranslated))
return untranslated
def newCount(self, language=None):
"""See IRosettaStats."""
nonupdates = self.rosettaCount() - self.updatesCount()
if nonupdates < 0:
return 0
else:
return nonupdates
def asPercentage(self, value):
"""See IRosettaStats."""
if self.messageCount() > 0:
percent = float(value) / self.messageCount()
percent *= 100
else:
percent = 0
return percent
def translatedPercentage(self, language=None):
"""See IRosettaStats."""
return self.asPercentage(self.translatedCount(language))
def currentPercentage(self, language=None):
"""See IRosettaStats."""
return self.asPercentage(self.currentCount(language))
def untranslatedPercentage(self, language=None):
"""See IRosettaStats."""
return self.asPercentage(self.untranslatedCount(language))
def newPercentage(self, language=None):
"""See IRosettaStats."""
return self.asPercentage(self.newCount(language))
def updatesPercentage(self, language=None):
"""See IRosettaStats."""
return self.asPercentage(self.updatesCount(language))
def rosettaPercentage(self, language=None):
"""See IRosettaStats."""
return self.asPercentage(self.rosettaCount(language))
|