<commit_before>"""
Logic about chws phones and cases go here.
"""
from collections import defaultdict
from datetime import datetime
import itertools
import logging
from casexml.apps.case.models import CommCareCase
from casexml.apps.case import const
from casexml.apps.case.xform import CaseDbCache


def get_footprint(initial_case_list, strip_history=False, domain=None):
    """
    Gets the flat list of the footprint of cases based on a starting list.
    Walks all the referenced indexes recursively.
    """
    if not initial_case_list:
        return {}

    domain = domain or list(initial_case_list)[0].domain
    case_db = CaseDbCache(domain=domain,
                          strip_history=strip_history,
                          deleted_ok=True)

    def children(case_db, case):
        return [case_db.get(index.referenced_id) for index in case.indices]

    relevant_cases = {}
    relevant_deleted_case_ids = []

    queue = list(case for case in initial_case_list)
    directly_referenced_indices = itertools.chain(*[[index.referenced_id for index in case.indices]
                                                    for case in initial_case_list])
    case_db.populate(directly_referenced_indices)
    while queue:
        case = queue.pop()<commit_msg>reorder arguments and make domain required<commit_after>"""
Logic about chws phones and cases go here.
"""
from collections import defaultdict
from datetime import datetime
import itertools
import logging
from casexml.apps.case.models import CommCareCase
from casexml.apps.case import const
from casexml.apps.case.xform import CaseDbCache


def get_footprint(initial_case_list, domain, strip_history=False):
    """
    Gets the flat list of the footprint of cases based on a starting list.
    Walks all the referenced indexes recursively.
    """
    if not initial_case_list:
        return {}

    # todo: should assert that domain exists here but this breaks tests
    case_db = CaseDbCache(domain=domain,
                          strip_history=strip_history,
                          deleted_ok=True)

    def children(case_db, case):
        return [case_db.get(index.referenced_id) for index in case.indices]

    relevant_cases = {}
    relevant_deleted_case_ids = []

    queue = list(case for case in initial_case_list)
    directly_referenced_indices = itertools.chain(*[[index.referenced_id for index in case.indices]
                                                    for case in initial_case_list])
    case_db.populate(directly_referenced_indices)
    while queue:
        case = queue.pop()
{'fraction_non_alphanumeric': 0.06702828361100349, 'fraction_numerical': 0.0003874467260751647, 'mean_word_length': 2.9240121580547114, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7565294', 'n_tokens_mistral': 701, 'n_tokens_neox': 694, 'n_words': 213}