def add_input( self, accumulator: suggestion_registry.TranslationContributionStats, translation: Dict[str, Union[bool, int, str]] ) -> suggestion_registry.TranslationContributionStats: is_accepted = (translation['suggestion_status'] == suggestion_models.STATUS_ACCEPTED) is_accepted_and_not_edited = (is_accepted and not translation['edited_by_reviewer']) is_rejected = (translation['suggestion_status'] == suggestion_models.STATUS_REJECTED) word_count = translation['content_word_count'] suggestion_date = datetime.datetime.strptime( python_utils.UNICODE(translation['last_updated_date']), '%Y-%m-%d').date() return suggestion_registry.TranslationContributionStats( # type: ignore[no-untyped-call] accumulator.language_code, accumulator.contributor_user_id, accumulator.topic_id, accumulator.submitted_translations_count + 1, accumulator.submitted_translation_word_count + word_count, accumulator.accepted_translations_count + int(is_accepted), (accumulator.accepted_translations_without_reviewer_edits_count + int(is_accepted_and_not_edited)), (accumulator.accepted_translation_word_count + word_count * int(is_accepted)), accumulator.rejected_translations_count + int(is_rejected), (accumulator.rejected_translation_word_count + word_count * int(is_rejected)), accumulator.contribution_dates | {suggestion_date})
def merge_accumulators( self, accumulators: Iterable[ suggestion_registry.TranslationContributionStats] ) -> suggestion_registry.TranslationContributionStats: return suggestion_registry.TranslationContributionStats( # type: ignore[no-untyped-call] list(accumulators)[0].language_code, list(accumulators)[0].contributor_user_id, list(accumulators)[0].topic_id, sum(acc.submitted_translations_count for acc in accumulators), sum(acc.submitted_translation_word_count for acc in accumulators), sum(acc.accepted_translations_count for acc in accumulators), sum(acc.accepted_translations_without_reviewer_edits_count for acc in accumulators), sum(acc.accepted_translation_word_count for acc in accumulators), sum(acc.rejected_translations_count for acc in accumulators), sum(acc.rejected_translation_word_count for acc in accumulators), set().union(*[acc.contribution_dates for acc in accumulators]))