<commit_before>import json

from django.core.management.base import BaseCommand

from evostream import EvoStreamException


class BaseEvoStreamCommand(BaseCommand):
    requires_system_checks = False

    silent_keys = ()

    def get_results(self, *args, **options):
        raise NotImplementedError()

    def format_results(self, results, verbosity):
        if verbosity > 1 or len(self.silent_keys) == 0:
            self.stdout.write(json.dumps(results, indent=1, sort_keys=True))
        else:
            if not isinstance(results, list):
                results = [results]
            for result in results:
                for key in self.silent_keys:
                    if key in result:
                        self.stdout.write(key + ': ' + json.dumps(result[key]) + '\n')

    def handle(self, verbosity, *args, **options):
        if not isinstance(verbosity, int):
            verbosity = int(verbosity)

        try:
            results = self.get_results(*args, **options)
        except EvoStreamException as ex:
            self.stderr.write(str(ex) + '\n')
            return

        if results is None:
            self.stdout.write('No data\n')
            return

        self.format_results(results, verbosity=verbosity)
<commit_msg>code formatting<commit_after>import json

from django.core.management.base import BaseCommand

from evostream import EvoStreamException


class BaseEvoStreamCommand(BaseCommand):
    requires_system_checks = False

    silent_keys = ()

    def get_results(self, *args, **options):
        raise NotImplementedError()

    def format_results(self, results, verbosity):
        if verbosity > 1 or len(self.silent_keys) == 0:
            self.stdout.write(json.dumps(results, indent=1, sort_keys=True))
        else:
            if not isinstance(results, list):
                results = [results]

            for result in results:
                for key in self.silent_keys:
                    if key in result:
                        self.stdout.write(key + ': ' + json.dumps(result[key]) + '\n')

    def handle(self, verbosity, *args, **options):
        if not isinstance(verbosity, int):
            verbosity = int(verbosity)

        try:
            results = self.get_results(*args, **options)
        except EvoStreamException as ex:
            self.stderr.write(str(ex) + '\n')
            return

        if results is None:
            self.stdout.write('No data\n')
            return

        self.format_results(results, verbosity=verbosity)

{'fraction_non_alphanumeric': 0.09893153937475267, 'fraction_numerical': 0.002374356944994064, 'mean_word_length': 2.148194271481943, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6246780', 'n_tokens_mistral': 718, 'n_tokens_neox': 685, 'n_words': 175}