<commit_before>from __future__ import absolute_import
from __future__ import unicode_literals

from collections import OrderedDict
from memoized import memoized
from sqlalchemy.sql import func

from corehq.apps.userreports.custom.data_source import ConfigurableReportCustomQueryProvider


class MPR2APersonCases(ConfigurableReportCustomQueryProvider):
    def __init__(self, report_data_source):
        self.report_data_source = report_data_source
        self.helper = self.report_data_source.helper

    @property
    def table(self):
        return self.helper.get_table()

    @property
    @memoized
    def _age_in_days_at_death(self):
        return (self.table.c.date_death - self.table.c.dob)

    def _count_filter_aggregate_expr(self, column, label):
        return (func.count(self.table.c.doc_id).filter(column).label(label))<commit_msg>Document with simplified query<commit_after>from __future__ import absolute_import
from __future__ import unicode_literals

from collections import OrderedDict
from memoized import memoized
from sqlalchemy.sql import func

from corehq.apps.userreports.custom.data_source import ConfigurableReportCustomQueryProvider


class MPR2APersonCases(ConfigurableReportCustomQueryProvider):
    """Simplified query:

    SELECT owner_id,
           COUNT(*) FILTER WHERE (sex=X AND resident=Y AND age_death=Z) AS dead_X_Y_Z_count
    FROM ucr_table
    WHERE (location_id = A & date_death > B)
    GROUP BY owner_id
    """
    def __init__(self, report_data_source):
        self.report_data_source = report_data_source
        self.helper = self.report_data_source.helper

    @property
    def table(self):
        return self.helper.get_table()

    @property
    @memoized
    def _age_in_days_at_death(self):
        return (self.table.c.date_death - self.table.c.dob)

    def _count_filter_aggregate_expr(self, column, label):
        return (func.count(self.table.c.doc_id).filter(column).label(label))
{'fraction_non_alphanumeric': 0.07428278688524591, 'fraction_numerical': 0.0010245901639344263, 'mean_word_length': 4.25, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '1667152', 'n_tokens_mistral': 618, 'n_tokens_neox': 588, 'n_words': 128}