<commit_before>from django.db.models import OneToOneField, ManyToManyField, TextField, DateTimeField, ForeignKey
from yunity.models.utils import MaxLengthCharField, BaseModel
from yunity.utils.elasticsearch import ElasticsearchMixin
from django.contrib.postgres.fields import JSONField


class VersionTrait(BaseModel):
    _VersionTrait_to_BaseModel = OneToOneField('yunity.BaseModel', parent_link=True)

    next_version = ForeignKey('self', null=True, related_name='previous_version')


class FeedbackTrait(BaseModel):
    _FeedbackTrait_to_BaseModel = OneToOneField('yunity.BaseModel', parent_link=True)


class AdministrationTrait(BaseModel):
    _AdministrationTrait_to_BaseModel = OneToOneField('yunity.BaseModel', parent_link=True)

    administrated_by = ManyToManyField('yunity.User')


class MapItem(VersionTrait, FeedbackTrait, AdministrationTrait, ElasticsearchMixin):
    type = ForeignKey('yunity.Category')

    provenance = MaxLengthCharField()
    name = TextField()
    # [{lat: float, long: float, startTime: timestring, endTime: timestring, description: text}]
    locations = JSONField()
    # [{type: text, value: text}
    contacts = JSONField(null=True)
    metadata = JSONField(null=True)

    def to_es(self):
        return {
            "id": self.id,
            "name": self.name,
            "locations": [{"lat": loc.latitude, "lon": loc.longitude} for loc in self.location.all()],
        }


class Request(FeedbackTrait):
    requested_by = ForeignKey('yunity.User', null=True)
<commit_msg>corrected elasticsearch for MapItem.location JSON field - untested<commit_after>from django.db.models import OneToOneField, ManyToManyField, TextField, DateTimeField, ForeignKey
from yunity.models.utils import MaxLengthCharField, BaseModel
from yunity.utils.elasticsearch import ElasticsearchMixin
from django.contrib.postgres.fields import JSONField


class VersionTrait(BaseModel):
    _VersionTrait_to_BaseModel = OneToOneField('yunity.BaseModel', parent_link=True)

    next_version = ForeignKey('self', null=True, related_name='previous_version')


class FeedbackTrait(BaseModel):
    _FeedbackTrait_to_BaseModel = OneToOneField('yunity.BaseModel', parent_link=True)


class AdministrationTrait(BaseModel):
    _AdministrationTrait_to_BaseModel = OneToOneField('yunity.BaseModel', parent_link=True)

    administrated_by = ManyToManyField('yunity.User')


class MapItem(VersionTrait, FeedbackTrait, AdministrationTrait, ElasticsearchMixin):
    type = ForeignKey('yunity.Category')

    provenance = MaxLengthCharField()
    name = TextField()
    # [{latitude: float, longitude: float, startTime: timestring, endTime: timestring, description: text}]
    locations = JSONField()
    # [{type: text, value: text}
    contacts = JSONField(null=True)
    metadata = JSONField(null=True)

    def to_es(self):
        return {
            "id": self.id,
            "name": self.name,
            "locations": [{"lat": loc['latitude'], "lon": loc['longitude']} for loc in self.locations],
        }


class Request(FeedbackTrait):
    requested_by = ForeignKey('yunity.User', null=True)

{'fraction_non_alphanumeric': 0.10700514138817481, 'fraction_numerical': 0.0, 'mean_word_length': 4.975047984644914, 'pattern_counts': {'":': 10, '<': 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': '4480552', 'n_tokens_mistral': 950, 'n_tokens_neox': 931, 'n_words': 194}