def _get_percents(self): ''' Returns percentages of translation status. ''' # No units? if self.total == 0: return (0, 0, 0) return ( translation_percent(self.translated, self.total), translation_percent(self.fuzzy, self.total), translation_percent(self.failing_checks, self.total), )
def get_percents(self, project=None, subproject=None, language=None): ''' Returns tuple consting of status percents - (translated, fuzzy, failing checks) ''' # Filter translations translations = self if project is not None: translations = translations.filter(subproject__project=project) if subproject is not None: translations = translations.filter(subproject=subproject) if language is not None: translations = translations.filter(language=language) # Aggregate translations = translations.aggregate( Sum('translated'), Sum('fuzzy'), Sum('failing_checks'), Sum('total'), ) total = translations['total__sum'] # Catch no translations (division by zero) if total == 0 or total is None: return (0, 0, 0) # Fetch values result = [ translations['translated__sum'], translations['fuzzy__sum'], translations['failing_checks__sum'], ] # Calculate percent return tuple([translation_percent(value, total) for value in result])
def get_words_percent(self): if self.total_words == 0: return 0 return translation_percent(self.translated_words, self.total_words)