<commit_before># This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

from abc import ABCMeta, abstractmethod
from collections import defaultdict

recursivedict = lambda: defaultdict(recursivedict)

class BaseFormatter(object):
    __metaclass__ = ABCMeta

    @abstractmethod
    def format_report(self, report, order='suite'):
        pass

    def save_report(self, report, file_name, **kwargs):
        with open(file_name, 'w') as f:
            f.write(self.format_report(report, **kwargs))

    def print_report(self, *args, **kwargs):
        print(self.format_report(*args, **kwargs))

    def _build_data(self, report, include=None, exclude=None):
        data = {
            'suites': defaultdict(recursivedict),
            'total_tests': 0,
            'total_active': 0,
        }

        from_suites = report.from_data['suites']
        to_suites = report.to_data['suites']

        for suite, platforms in to_suites.iteritems():
            if exclude and suite in exclude:
                continue
            if include and suite not in include:
                continue

            total_suite_tests = 0
            total_suite_active = 0
            total_suite_added = 0
            total_suite_removed = 0

            for platform, tests in platforms.iteritems():
                added = removed = []
                if suite in from_suites:
                    added = [t for t in tests['active'] if t not in from_suites[suite][platform]['active']]
                    removed = [t for t in from_suites[suite][platform]['active'] if t not in tests['active']]

                data['suites'][suite][platform]['total'] =  len(tests['active']) + len(tests['skipped'])
                data['suites'][suite][platform]['active'] = len(tests['active'])
                data['suites'][suite][platform]['skipped'] = tests['skipped']
                data['suites'][suite][platform]['added'] = added<commit_msg>Don't count new platforms as added or removed<commit_after># This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

from abc import ABCMeta, abstractmethod
from collections import defaultdict

recursivedict = lambda: defaultdict(recursivedict)

class BaseFormatter(object):
    __metaclass__ = ABCMeta

    @abstractmethod
    def format_report(self, report, order='suite'):
        pass

    def save_report(self, report, file_name, **kwargs):
        with open(file_name, 'w') as f:
            f.write(self.format_report(report, **kwargs))

    def print_report(self, *args, **kwargs):
        print(self.format_report(*args, **kwargs))

    def _build_data(self, report, include=None, exclude=None):
        data = {
            'suites': defaultdict(recursivedict),
            'total_tests': 0,
            'total_active': 0,
        }

        from_suites = report.from_data['suites']
        to_suites = report.to_data['suites']

        for suite, platforms in to_suites.iteritems():
            if exclude and suite in exclude:
                continue
            if include and suite not in include:
                continue

            total_suite_tests = 0
            total_suite_active = 0
            total_suite_added = 0
            total_suite_removed = 0

            for platform, tests in platforms.iteritems():
                added = removed = []
                if suite in from_suites and platform in from_suites[suite]:
                    added = [t for t in tests['active'] if t not in from_suites[suite][platform]['active']]
                    removed = [t for t in from_suites[suite][platform]['active'] if t not in tests['active']]

                data['suites'][suite][platform]['total'] =  len(tests['active']) + len(tests['skipped'])
                data['suites'][suite][platform]['active'] = len(tests['active'])
                data['suites'][suite][platform]['skipped'] = tests['skipped']
                data['suites'][suite][platform]['added'] = added
{'fraction_non_alphanumeric': 0.11517454286392781, 'fraction_numerical': 0.0047494656851104254, 'mean_word_length': 2.463815789473684, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3482302', 'n_tokens_mistral': 1193, 'n_tokens_neox': 1141, 'n_words': 332}