<commit_before>from django.utils.translation import ugettext_noop
from corehq.apps.domain.calculations import CALC_FNS
from corehq.apps.reports.datatables import DataTablesHeader, DataTablesColumn, DTSortType
from corehq.apps.reports.dispatcher import BasicReportDispatcher, AdminReportDispatcher
from corehq.apps.reports.generic import GenericTabularReport
from django.utils.translation import ugettext as _


class DomainStatsReport(GenericTabularReport):
    dispatcher = BasicReportDispatcher
    asynchronous = True
    section_name = 'DOMSTATS'
    base_template = "reports/async/default.html"
    custom_params = []
    # fields = ['corehq.apps.reports.fields.FilterUsersField',
    #           'corehq.apps.reports.fields.SelectMobileWorkerField']

    name = ugettext_noop('Domain Statistics')
    slug = 'dom_stats'

    def get_domains(self):
        return getattr(self, 'domains', [])

    @property
    def headers(self):
        headers = DataTablesHeader(
            DataTablesColumn("Project"),
            DataTablesColumn(_("# Web Users")),
            DataTablesColumn(_("# Active Mobile Workers")),
            DataTablesColumn(_("# Mobile Workers")),
            DataTablesColumn(_("# Active Cases")),
            DataTablesColumn(_("# Cases")),
            DataTablesColumn(_("# Form Submissions")),
            DataTablesColumn(_("First Form Submission")),
            DataTablesColumn(_("Last Form Submission")),
            # DataTablesColumn(_("Admins"))
        )
        # headers.no_sort = True
        return headers

    @property
    def rows(self):
        from corehq.apps.hqadmin.views import _all_domain_stats
        rows = []
        all_stats = _all_domain_stats()
        for dom in self.get_domains():
            rows.append([
                dom,
                int(all_stats["web_users"][dom]),
                CALC_FNS["mobile_users"](dom),
                int(all_stats["commcare_users"][dom]),
                CALC_FNS["cases_in_last"](dom, 120),
                int(all_stats["cases"][dom]),
                int(all_stats["forms"][dom]),
                CALC_FNS["first_form_submission"](dom),
                CALC_FNS["last_form_submission"](dom),
                # [row["doc"]["email"] for row in get_db().view("users/admins_by_domain",
                #                                               key=dom, reduce=False, include_docs=True).all()],
            ])
        return rows

    @property
    def shared_pagination_GET_params(self):
        ret = super(DomainStatsReport, self).shared_pagination_GET_params
        for k, v in self.request.GET.items():
            if k in self.custom_params:
                ret.append(dict(name=k, value=v))
        return ret

class OrgDomainStatsReport(DomainStatsReport):
    custom_params = ['org']

    def get_domains(self):
        from corehq.apps.orgs.models import Organization
        from corehq.apps.domain.models import Domain
        org = self.request.GET.get('org', None)
        organization = Organization.get_by_name(org, strict=True)
        if organization and \
                (self.request.couch_user.is_superuser or self.request.couch_user.is_member_of_org(org)):
            return [d.name for d in Domain.get_by_organization(organization.name).all()]
        return []<commit_msg>disable sorting until I can fix it<commit_after>from django.utils.translation import ugettext_noop
from corehq.apps.domain.calculations import CALC_FNS
from corehq.apps.reports.datatables import DataTablesHeader, DataTablesColumn, DTSortType
from corehq.apps.reports.dispatcher import BasicReportDispatcher, AdminReportDispatcher
from corehq.apps.reports.generic import GenericTabularReport
from django.utils.translation import ugettext as _


class DomainStatsReport(GenericTabularReport):
    dispatcher = BasicReportDispatcher
    asynchronous = True
    section_name = 'DOMSTATS'
    base_template = "reports/async/default.html"
    custom_params = []

    name = ugettext_noop('Domain Statistics')
    slug = 'dom_stats'

    def get_domains(self):
        return getattr(self, 'domains', [])

    @property
    def headers(self):
        headers = DataTablesHeader(
            DataTablesColumn("Project"),
            DataTablesColumn(_("# Web Users"), sort_type=DTSortType.NUMERIC),
            DataTablesColumn(_("# Active Mobile Workers"), sort_type=DTSortType.NUMERIC),
            DataTablesColumn(_("# Mobile Workers"), sort_type=DTSortType.NUMERIC),
            DataTablesColumn(_("# Active Cases"), sort_type=DTSortType.NUMERIC),
            DataTablesColumn(_("# Cases"), sort_type=DTSortType.NUMERIC),
            DataTablesColumn(_("# Form Submissions"), sort_type=DTSortType.NUMERIC),
            DataTablesColumn(_("First Form Submission")),
            DataTablesColumn(_("Last Form Submission")),
            # DataTablesColumn(_("Admins"))
        )
        headers.no_sort = True
        return headers

    @property
    def rows(self):
        from corehq.apps.hqadmin.views import _all_domain_stats
        rows = []
        all_stats = _all_domain_stats()
        for dom in self.get_domains():
            rows.append([
                dom,
                int(all_stats["web_users"][dom]),
                int(CALC_FNS["mobile_users"](dom)),
                int(all_stats["commcare_users"][dom]),
                int(CALC_FNS["cases_in_last"](dom, 120)),
                int(all_stats["cases"][dom]),
                int(all_stats["forms"][dom]),
                CALC_FNS["first_form_submission"](dom),
                CALC_FNS["last_form_submission"](dom),
                # [row["doc"]["email"] for row in get_db().view("users/admins_by_domain",
                #                                               key=dom, reduce=False, include_docs=True).all()],
            ])
        return rows

    @property
    def shared_pagination_GET_params(self):
        ret = super(DomainStatsReport, self).shared_pagination_GET_params
        for k, v in self.request.GET.items():
            if k in self.custom_params:
                ret.append(dict(name=k, value=v))
        return ret

class OrgDomainStatsReport(DomainStatsReport):
    custom_params = ['org']

    def get_domains(self):
        from corehq.apps.orgs.models import Organization
        from corehq.apps.domain.models import Domain
        org = self.request.GET.get('org', None)
        organization = Organization.get_by_name(org, strict=True)
        if organization and \
                (self.request.couch_user.is_superuser or self.request.couch_user.is_member_of_org(org)):
            return [d.name for d in Domain.get_by_organization(organization.name).all()]
        return []
{'fraction_non_alphanumeric': 0.10803945008965929, 'fraction_numerical': 0.0008965929468021519, 'mean_word_length': 2.6217532467532467, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3616090', 'n_tokens_mistral': 1965, 'n_tokens_neox': 1865, 'n_words': 357}