<commit_before># from rapidsms.contrib.locations.models import Location
from survey.models.locations import Location
from survey.models import BaseModel
from django.db import models
from survey.models.surveys import Survey
from survey.models.batch import Batch, BatchLocationStatus


class EnumerationArea(BaseModel):
    name = models.CharField(max_length=200, blank=False, null=True)
    code = models.CharField(max_length=200, editable=False,
                            blank=True, null=True, unique=True)
    # total_households = models.PositiveIntegerField(null=True, blank=True)
    locations = models.ManyToManyField(
        Location, related_name="enumeration_areas")

    def __unicode__(self):
        return self.name

    def parent_locations(self):
        # now this assumes ea locations are made from smallest units belonging
        # to same group
        if self.locations.exists():
            location = self.locations.all()[0]
            return location.get_ancestors().exclude(parent__isnull=True)

    def get_survey_openings(self, survey=None):
        parent_locations = set()
        ea_locations = self.locations.all()
        if ea_locations:
            map(lambda loc: parent_locations.update(
                loc.get_ancestors(include_self=True)), ea_locations)
        kwargs = {'location__pk__in': [loc.pk for loc in parent_locations]}
        if survey:
            kwargs['batch__survey'] = survey
        location_registry = BatchLocationStatus.objects.filter(**kwargs)
        return location_registry<commit_msg>added db_index in ea locations<commit_after># from rapidsms.contrib.locations.models import Location
from survey.models.locations import Location
from survey.models import BaseModel
from django.db import models
from survey.models.surveys import Survey
from survey.models.batch import Batch, BatchLocationStatus


class EnumerationArea(BaseModel):
    name = models.CharField(max_length=200, blank=False, null=True)
    code = models.CharField(max_length=200, editable=False,
                            blank=True, null=True, unique=True)
    # total_households = models.PositiveIntegerField(null=True, blank=True)
    locations = models.ManyToManyField(
        Location, related_name="enumeration_areas", db_index=True)

    def __unicode__(self):
        return self.name

    def parent_locations(self):
        # now this assumes ea locations are made from smallest units belonging
        # to same group
        if self.locations.exists():
            location = self.locations.all()[0]
            return location.get_ancestors().exclude(parent__isnull=True)

    def get_survey_openings(self, survey=None):
        parent_locations = set()
        ea_locations = self.locations.all()
        if ea_locations:
            map(lambda loc: parent_locations.update(
                loc.get_ancestors(include_self=True)), ea_locations)
        kwargs = {'location__pk__in': [loc.pk for loc in parent_locations]}
        if survey:
            kwargs['batch__survey'] = survey
        location_registry = BatchLocationStatus.objects.filter(**kwargs)
        return location_registry
{'fraction_non_alphanumeric': 0.08476736775015933, 'fraction_numerical': 0.004461440407903123, 'mean_word_length': 3.3, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1666433', 'n_tokens_mistral': 892, 'n_tokens_neox': 835, 'n_words': 204}