<commit_before>from django.utils import timezone
from excerptconverter import converter_registry


class ConverterManager:
    @staticmethod
    def converter_configuration():
        return {Converter.__name__: Converter.converter_configuration()
                for Converter in converter_registry.available_converters}

    def __init__(self, extraction_order,
                 available_converters=converter_registry.available_converters,
                 run_as_celery_tasks=True):
        """"
        :param execution_configuration example:
            {
                'gis': {
                    'formats': ['txt', 'file_gdb'],
                    'options': {
                        'coordinate_reference_system': 'wgs72',
                        'detail_level': 'verbatim'
                    }
                },
                'routing': { ... }
            }
        """
        self.extraction_order = extraction_order
        self.available_converters = available_converters
        self.run_as_celery_tasks = run_as_celery_tasks

    def execute_converters(self):
        converters_in_configuration = self._get_converters_from_configuration()

        if len(converters_in_configuration) > 0:
            self.extraction_order.process_start_date = timezone.now()
            self.extraction_order.save()
        for Converter in converters_in_configuration:

            if self.run_as_celery_tasks:
                Converter.execute.delay(
                    self.extraction_order.id,
                    self.extraction_order.extraction_configuration[Converter.__name__]
                )
            else:
                Converter.execute(
                    self.extraction_order.id,
                    self.extraction_order.extraction_configuration[Converter.__name__]
                )

    def _get_converters_from_configuration(self):
        return [C for C in self.available_converters if self._config_has_formats_provided_by_converter(C)]

    def _config_has_formats_provided_by_converter(self, Converter):
        return (Converter.__name__ in self.extraction_order.extraction_configuration and
                len(self.extraction_order.extraction_configuration[Converter.__name__]['formats']) > 0)<commit_msg>refactoring: move method call out of conditionally executed code<commit_after>from django.utils import timezone
from excerptconverter import converter_registry


class ConverterManager:
    @staticmethod
    def converter_configuration():
        return {Converter.__name__: Converter.converter_configuration()
                for Converter in converter_registry.available_converters}

    def __init__(self, extraction_order,
                 available_converters=converter_registry.available_converters,
                 run_as_celery_tasks=True):
        """"
        :param execution_configuration example:
            {
                'gis': {
                    'formats': ['txt', 'file_gdb'],
                    'options': {
                        'coordinate_reference_system': 'wgs72',
                        'detail_level': 'verbatim'
                    }
                },
                'routing': { ... }
            }
        """
        self.extraction_order = extraction_order
        self.available_converters = available_converters
        self.run_as_celery_tasks = run_as_celery_tasks

    def execute_converters(self):
        converters_in_configuration = self._get_converters_from_configuration()

        if len(converters_in_configuration) > 0:
            self.extraction_order.process_start_date = timezone.now()
            self.extraction_order.save()
        for Converter in converters_in_configuration:
            if self.run_as_celery_tasks:
                execute_converter = Converter.execute.delay
            else:
                execute_converter = Converter.execute
            execute_converter(
                self.extraction_order.id,
                self.extraction_order.extraction_configuration[Converter.__name__]
            )

    def _get_converters_from_configuration(self):
        return [C for C in self.available_converters if self._config_has_formats_provided_by_converter(C)]

    def _config_has_formats_provided_by_converter(self, Converter):
        return (Converter.__name__ in self.extraction_order.extraction_configuration and
                len(self.extraction_order.extraction_configuration[Converter.__name__]['formats']) > 0)
{'fraction_non_alphanumeric': 0.07117198024247867, 'fraction_numerical': 0.001796138302649304, 'mean_word_length': 2.24945295404814, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '521354', 'n_tokens_mistral': 1208, 'n_tokens_neox': 1137, 'n_words': 182}