<commit_before>import logging
import re
from django.core.management import BaseCommand

from corehq.apps.app_manager.dbaccessors import get_apps_in_domain
from corehq.apps.userreports.exceptions import ReportConfigurationNotFoundError
from toggle.models import Toggle


logger = logging.getLogger('report_module_migration')
logger.setLevel('DEBUG')


class Command(BaseCommand):
    help = '''
        Migrate ReportAppConfig objects from storing graph configurations
        using ReportGraphConfig to storing them using GraphConfiguration
    '''

    def handle(self, **options):
        domains = Toggle.get('mobile_ucr').enabled_users
        domains = [re.sub(r'^domain:', '', d) for d in domains]
        for domain in domains:
            apps = get_apps_in_domain(domain, include_remote=False)
            for app in apps:
                dirty = False
                for module in app.modules:
                    if module.doc_type == 'ReportModule':
                        for config in module.report_configs:
                            if len(config.complete_graph_configs):
                                logger.info("Already migrated module {} in app {} in domain {}".format(
                                    module.id, app.id, domain
                                ))
                            else:
                                logger.info("Migrating module {} in app {} in domain {}".format(
                                    module.id, app.id, domain
                                ))
                                try:
                                    config.migrate_graph_configs(domain)
                                    dirty = True
                                except ReportConfigurationNotFoundError:<commit_msg>Don't attempt to migrate configs that don't have graphs<commit_after>import logging
import re
from django.core.management import BaseCommand

from corehq.apps.app_manager.dbaccessors import get_apps_in_domain
from corehq.apps.userreports.exceptions import ReportConfigurationNotFoundError
from toggle.models import Toggle


logger = logging.getLogger('report_module_migration')
logger.setLevel('DEBUG')


class Command(BaseCommand):
    help = '''
        Migrate ReportAppConfig objects from storing graph configurations
        using ReportGraphConfig to storing them using GraphConfiguration
    '''

    def handle(self, **options):
        domains = Toggle.get('mobile_ucr').enabled_users
        domains = [re.sub(r'^domain:', '', d) for d in domains]
        for domain in domains:
            apps = get_apps_in_domain(domain, include_remote=False)
            for app in apps:
                dirty = False
                for module in app.modules:
                    if module.doc_type == 'ReportModule':
                        for config in module.report_configs:
                            if len(config.complete_graph_configs):
                                logger.info("Already migrated module {} in app {} in domain {}".format(
                                    module.id, app.id, domain
                                ))
                            elif len(config.graph_configs):
                                logger.info("Migrating module {} in app {} in domain {}".format(
                                    module.id, app.id, domain
                                ))
                                try:
                                    config.migrate_graph_configs(domain)
                                    dirty = True
                                except ReportConfigurationNotFoundError:
{'fraction_non_alphanumeric': 0.0709515859766277, 'fraction_numerical': 0.0, 'mean_word_length': 1.5514549325762952, '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': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2655392', 'n_tokens_mistral': 845, 'n_tokens_neox': 797, 'n_words': 220}