<commit_before>from django.utils.translation import ugettext_noop
from corehq.apps.reports.filters.base import BaseDrilldownOptionFilter, BaseSingleOptionFilter
from corehq.apps.reports.filters.select import YearFilter
from casexml.apps.case.models import CommCareCase
from corehq.apps.users.models import CommCareUser
from custom.care_pathways.sqldata import GeographySqlData
from custom.care_pathways.utils import get_domain_configuration


class CareBaseDrilldownOptionFilter(BaseDrilldownOptionFilter):
    single_option_select = -1

    @property
    def filter_context(self):
        context = super(CareBaseDrilldownOptionFilter, self).filter_context
        context.update({'single_option_select': self.single_option_select})
        return context


class GeographyFilter(CareBaseDrilldownOptionFilter):
    label = ugettext_noop("Geography")
    slug = "geography"
    template = "care_pathways/filters/drilldown_options.html"

    @property
    def drilldown_map(self):
        hierarchy = helper = []
        hierarchy_config = sorted([k for k in get_domain_configuration('pathways-india-mis')['geography_hierarchy'].keys()])
        data = GeographySqlData('pathways-india-mis').get_data()
        for val in data:
            for lvl in hierarchy_config:
                tmp = dict(val=val[lvl], text=val[lvl], next=[])
                tmp_next = []
                exist = False
                for item in hierarchy:
                    if item['val'] == val[lvl]:
                        exist = True
                        tmp_next = item['next']
                        break
                if not exist:
                    hierarchy.append(tmp)
                    hierarchy = tmp['next']
                else:
                    hierarchy = tmp_next
            hierarchy = helper

        return hierarchy

    @classmethod
    def get_labels(cls):
        return [(v['name'], 'All', v['prop']) for k,v in get_domain_configuration('pathways-india-mis')['geography_hierarchy'].iteritems()]


    @classmethod
    def _get_label_value(cls, request, label):
        slug = str(label[2])
        val = request.GET.getlist('%s_%s' % (cls.slug, str(label[2])))
        return {<commit_msg>Fixed order of Hierarchy Filter Labels.<commit_after>from django.utils.translation import ugettext_noop
from corehq.apps.reports.filters.base import BaseDrilldownOptionFilter, BaseSingleOptionFilter
from corehq.apps.reports.filters.select import YearFilter
from casexml.apps.case.models import CommCareCase
from corehq.apps.users.models import CommCareUser
from custom.care_pathways.sqldata import GeographySqlData
from custom.care_pathways.utils import get_domain_configuration


class CareBaseDrilldownOptionFilter(BaseDrilldownOptionFilter):
    single_option_select = -1

    @property
    def filter_context(self):
        context = super(CareBaseDrilldownOptionFilter, self).filter_context
        context.update({'single_option_select': self.single_option_select})
        return context


class GeographyFilter(CareBaseDrilldownOptionFilter):
    label = ugettext_noop("Geography")
    slug = "geography"
    template = "care_pathways/filters/drilldown_options.html"

    @property
    def drilldown_map(self):
        hierarchy = helper = []
        hierarchy_config = sorted([k for k in get_domain_configuration('pathways-india-mis')['geography_hierarchy'].keys()])
        data = GeographySqlData('pathways-india-mis').get_data()
        for val in data:
            for lvl in hierarchy_config:
                tmp = dict(val=val[lvl], text=val[lvl], next=[])
                tmp_next = []
                exist = False
                for item in hierarchy:
                    if item['val'] == val[lvl]:
                        exist = True
                        tmp_next = item['next']
                        break
                if not exist:
                    hierarchy.append(tmp)
                    hierarchy = tmp['next']
                else:
                    hierarchy = tmp_next
            hierarchy = helper

        return hierarchy

    @classmethod
    def get_labels(cls):
        return [(v['name'], 'All', v['prop']) for k,v in sorted(get_domain_configuration('pathways-india-mis')['geography_hierarchy'].iteritems())]


    @classmethod
    def _get_label_value(cls, request, label):
        slug = str(label[2])
        val = request.GET.getlist('%s_%s' % (cls.slug, str(label[2])))
        return {
{'fraction_non_alphanumeric': 0.0959119496855346, 'fraction_numerical': 0.0013477088948787063, 'mean_word_length': 2.5940274414850686, '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': '3926298', 'n_tokens_mistral': 1295, 'n_tokens_neox': 1253, 'n_words': 259}