<commit_before>"""
Custom report definitions - control display of reports.

The BaseReport is somewhat general, but it's
currently specific to monthly reports.  It would be pretty simple to make
this more general and subclass for montly reports , but I'm holding off on
that until we actually have another use case for it.
"""
from collections import defaultdict
import datetime
import logging
import simplejson
import re
from dateutil import parser
from decimal import Decimal
from numbers import Number

from django.http import HttpResponse
from django.template import RequestContext
from django.template.loader import render_to_string
from django.utils.translation import ugettext_noop, ugettext as _

from couchdbkit.exceptions import ResourceNotFound
from sqlagg.filters import ANDFilter, BETWEEN
from dimagi.utils.couch.database import iter_docs
from dimagi.utils.dates import DateSpan
from dimagi.utils.decorators.memoized import memoized
from sqlagg.base import AliasColumn
from sqlagg.columns import SimpleColumn, SumColumn, CountColumn

from corehq.apps.es import cases as case_es, filters as es_filters
from corehq.apps.hqcase.utils import get_cases_in_domain
from corehq.apps.reports.cache import request_cache
from corehq.apps.reports.datatables import DataTablesHeader, DataTablesColumn
from corehq.apps.reports.filters.dates import DatespanFilter
from corehq.apps.reports.filters.select import SelectOpenCloseFilter, MonthFilter, YearFilter
from corehq.apps.reports.generic import ElasticTabularReport, GetParamsMixin
from corehq.apps.reports.sqlreport import DatabaseColumn, SqlData, AggregateColumn, DataFormatter, DictDataFormat
from corehq.apps.reports.standard import CustomProjectReport, MonthYearMixin
from corehq.apps.reports.standard.maps import ElasticSearchMapReport
from corehq.apps.reports.tasks import export_all_rows_task
from corehq.apps.users.models import CommCareCase, CouchUser, CommCareUser
from corehq.elastic import es_query
from corehq.pillows.mappings.reportcase_mapping import REPORT_CASE_INDEX
from corehq.pillows.mappings.user_mapping import USER_INDEX
from corehq.util.translation import localize

from custom.opm import BaseMixin, normal_format, format_percent
from ..opm_tasks.models import OpmReportSnapshot
from .beneficiary import Beneficiary, ConditionsMet
from .health_status import HealthStatus
from .incentive import Worker
from .filters import SnapshotFilter, HierarchyFilter, MetHierarchyFilter
from .constants import *


DATE_FILTER ="date between :startdate and :enddate"
DATE_FILTER_EXTENDED = '(opened_on <= :enddate AND (closed_on >= :enddate OR closed_on = '')) OR (opened_on <= :enddate AND (closed_on >= :startdate or closed_on <= :enddate))'<commit_msg>clean imports<commit_after>"""
Custom report definitions - control display of reports.

The BaseReport is somewhat general, but it's
currently specific to monthly reports.  It would be pretty simple to make
this more general and subclass for montly reports , but I'm holding off on
that until we actually have another use case for it.
"""
from collections import defaultdict
import datetime
import logging
import simplejson
import re
from dateutil import parser
from decimal import Decimal

from django.http import HttpResponse
from django.template import RequestContext
from django.template.loader import render_to_string
from django.utils.translation import ugettext_noop, ugettext as _

from dimagi.utils.couch.database import iter_docs
from dimagi.utils.dates import DateSpan
from dimagi.utils.decorators.memoized import memoized
from sqlagg.base import AliasColumn
from sqlagg.columns import SimpleColumn, SumColumn

from corehq.apps.es import cases as case_es, filters as es_filters
from corehq.apps.reports.cache import request_cache
from corehq.apps.reports.datatables import DataTablesHeader, DataTablesColumn
from corehq.apps.reports.filters.dates import DatespanFilter
from corehq.apps.reports.filters.select import SelectOpenCloseFilter, MonthFilter, YearFilter
from corehq.apps.reports.generic import ElasticTabularReport, GetParamsMixin
from corehq.apps.reports.sqlreport import DatabaseColumn, SqlData, AggregateColumn, DataFormatter, DictDataFormat
from corehq.apps.reports.standard import CustomProjectReport, MonthYearMixin
from corehq.apps.reports.standard.maps import ElasticSearchMapReport
from corehq.apps.reports.tasks import export_all_rows_task
from corehq.apps.users.models import CommCareCase, CouchUser, CommCareUser
from corehq.elastic import es_query
from corehq.pillows.mappings.user_mapping import USER_INDEX
from corehq.util.translation import localize

from custom.opm import BaseMixin, normal_format, format_percent
from ..opm_tasks.models import OpmReportSnapshot
from .beneficiary import Beneficiary, ConditionsMet
from .health_status import HealthStatus
from .incentive import Worker
from .filters import SnapshotFilter, HierarchyFilter, MetHierarchyFilter
from .constants import *


DATE_FILTER ="date between :startdate and :enddate"
DATE_FILTER_EXTENDED = '(opened_on <= :enddate AND (closed_on >= :enddate OR closed_on = '')) OR (opened_on <= :enddate AND (closed_on >= :startdate or closed_on <= :enddate))'
{'fraction_non_alphanumeric': 0.05496419585833172, 'fraction_numerical': 0.0, 'mean_word_length': 6.555555555555555, 'pattern_counts': {'":': 0, '<': 9, '<?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': '3201930', 'n_tokens_mistral': 1458, 'n_tokens_neox': 1410, 'n_words': 494}