<commit_before>from corehq.apps.users.models import CouchUser
from casexml.apps.case.models import CommCareCase
from corehq.apps.app_manager.models import ApplicationBase, Application

def get_all_cases(domain, include_closed=False):
    """
    Get all cases in a domain.
    """
    cases = CommCareCase.view('hqcase/types_by_domain', 
                              startkey=[domain],
                              endkey=[domain, {}],
                              reduce=False,
                              include_docs=True)
    if not include_closed:
        cases = filter(lambda case: not case.closed, cases)
    return [case.get_json() for case in cases]


def get_owned_cases(domain, user_id):
    """
    Get all cases in a domain owned by a particular user.
    """
    user = CouchUser.get_by_user_id(user_id, domain)
    try:
        owner_ids = user.get_owner_ids()
    except AttributeError:
        owner_ids = [user_id]
    keys = [[owner_id, False] for owner_id in owner_ids]
    cases = CommCareCase.view('case/by_owner', keys=keys, include_docs=True)
    return [case.get_json() for case in cases]

def get_cloudcare_apps(domain):<commit_msg>add reduce=False to all calls of case/by_owner view, now that it has a reduce<commit_after>from corehq.apps.users.models import CouchUser
from casexml.apps.case.models import CommCareCase
from corehq.apps.app_manager.models import ApplicationBase, Application

def get_all_cases(domain, include_closed=False):
    """
    Get all cases in a domain.
    """
    cases = CommCareCase.view('hqcase/types_by_domain', 
                              startkey=[domain],
                              endkey=[domain, {}],
                              reduce=False,
                              include_docs=True)
    if not include_closed:
        cases = filter(lambda case: not case.closed, cases)
    return [case.get_json() for case in cases]


def get_owned_cases(domain, user_id):
    """
    Get all cases in a domain owned by a particular user.
    """
    user = CouchUser.get_by_user_id(user_id, domain)
    try:
        owner_ids = user.get_owner_ids()
    except AttributeError:
        owner_ids = [user_id]
    keys = [[owner_id, False] for owner_id in owner_ids]
    cases = CommCareCase.view('case/by_owner', keys=keys, include_docs=True, reduce=False)
    return [case.get_json() for case in cases]

def get_cloudcare_apps(domain):
{'fraction_non_alphanumeric': 0.09268495428096425, 'fraction_numerical': 0.0, 'mean_word_length': 2.6032934131736525, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '2824091', 'n_tokens_mistral': 723, 'n_tokens_neox': 712, 'n_words': 185}