<commit_before># -*- coding: utf-8 -*-
from django.contrib.gis.db import models

# Originally from 'iso lat long.xlsx'.  This spreadsheet contains ISO Codes and their
# Locations.  Only iso codes from the 16th edition ethnologue were present.
# Other datasets references ISO Codes that were not present in 16th ed, so now
# this is loaded from the ethnologue, and locations are annotated later if known

class ISOCode(models.Model):
    iso_code = models.CharField('ISO Code', db_index=True, max_length=3)
    location = models.PointField(null=True) # only have locations for ISO codes in 16th ed ethnologue
    # For GeoDjango, must override the manager
    objects = models.GeoManager()
    def __unicode__(self):
        return "%s (%s)" % (self.iso_code, self.location)
    class Meta:
        verbose_name = "ISO Code"

SOCIETY_SOURCES = (
    ('EA', 'EA'),
    ('EA_Korotayev', 'EA_Korotayev'),
    ('EA_Bodarenko', 'EA_Bodarenko'),
    ('Binford', 'Binford'),
)

class Society(models.Model):
    ext_id = models.CharField('External ID', unique=True, max_length=10)
    name = models.CharField('Name', db_index=True, max_length=200)
    location = models.PointField('Location',null=True)
    source = models.CharField(max_length=16,choices=SOCIETY_SOURCES)
    iso_code = models.ForeignKey('ISOCode', null=True, related_name="societies")
    language = models.ForeignKey('Language', null=True, related_name="societies")

    def get_cultural_trait_data(self):
        """Returns the Ethnographic Atlas data for the given society"""
        values = []
        qset = self.variablecodedvalue_set.select_related('code').select_related('variable')
        for value in qset.order_by('variable__label').all():
            values.append({
                'label': value.variable.label,
                'name': value.variable.name,
                'code': value.coded_value,
                'description': value.get_description(),
            })
        return values

    def __unicode__(self):
        return "%s - %s (%s)" % (self.ext_id, self.name, self.source)
    
    class Meta:
        verbose_name_plural = "Societies"

UNIT_CHOICES = (
    ('mm','mm'),
    ('℃','℃'),
    ('',''),
)

class EnvironmentalVariable(models.Model):
    name = models.CharField(max_length=50, unique=True)
    units = models.CharField(max_length=10, choices=UNIT_CHOICES)

class EnvironmentalValue(models.Model):
    variable = models.ForeignKey('EnvironmentalVariable', related_name="values")
    value = models.FloatField(db_index=True)
    environmental = models.ForeignKey('Environmental', related_name="values")
    class Meta:
        unique_together = (
            ('variable','environmental')
        )
        index_together = [
            ['variable','value']
        ]

class Environmental(models.Model):
    # may be EA or Binford or ... something
    society = models.ForeignKey('Society', null=True, related_name="environmentals")
    reported_location = models.PointField()
    actual_location = models.PointField()<commit_msg>Add 'mo' to unit choices<commit_after># -*- coding: utf-8 -*-
from django.contrib.gis.db import models

# Originally from 'iso lat long.xlsx'.  This spreadsheet contains ISO Codes and their
# Locations.  Only iso codes from the 16th edition ethnologue were present.
# Other datasets references ISO Codes that were not present in 16th ed, so now
# this is loaded from the ethnologue, and locations are annotated later if known

class ISOCode(models.Model):
    iso_code = models.CharField('ISO Code', db_index=True, max_length=3)
    location = models.PointField(null=True) # only have locations for ISO codes in 16th ed ethnologue
    # For GeoDjango, must override the manager
    objects = models.GeoManager()
    def __unicode__(self):
        return "%s (%s)" % (self.iso_code, self.location)
    class Meta:
        verbose_name = "ISO Code"

SOCIETY_SOURCES = (
    ('EA', 'EA'),
    ('EA_Korotayev', 'EA_Korotayev'),
    ('EA_Bodarenko', 'EA_Bodarenko'),
    ('Binford', 'Binford'),
)

class Society(models.Model):
    ext_id = models.CharField('External ID', unique=True, max_length=10)
    name = models.CharField('Name', db_index=True, max_length=200)
    location = models.PointField('Location',null=True)
    source = models.CharField(max_length=16,choices=SOCIETY_SOURCES)
    iso_code = models.ForeignKey('ISOCode', null=True, related_name="societies")
    language = models.ForeignKey('Language', null=True, related_name="societies")

    def get_cultural_trait_data(self):
        """Returns the Ethnographic Atlas data for the given society"""
        values = []
        qset = self.variablecodedvalue_set.select_related('code').select_related('variable')
        for value in qset.order_by('variable__label').all():
            values.append({
                'label': value.variable.label,
                'name': value.variable.name,
                'code': value.coded_value,
                'description': value.get_description(),
            })
        return values

    def __unicode__(self):
        return "%s - %s (%s)" % (self.ext_id, self.name, self.source)
    
    class Meta:
        verbose_name_plural = "Societies"

UNIT_CHOICES = (
    ('mm','mm'),
    ('℃','℃'),
    ('mo','mo'),
    ('',''),
)

class EnvironmentalVariable(models.Model):
    name = models.CharField(max_length=50, unique=True)
    units = models.CharField(max_length=10, choices=UNIT_CHOICES)

class EnvironmentalValue(models.Model):
    variable = models.ForeignKey('EnvironmentalVariable', related_name="values")
    value = models.FloatField(db_index=True)
    environmental = models.ForeignKey('Environmental', related_name="values")
    class Meta:
        unique_together = (
            ('variable','environmental')
        )
        index_together = [
            ['variable','value']
        ]

class Environmental(models.Model):
    # may be EA or Binford or ... something
    society = models.ForeignKey('Society', null=True, related_name="environmentals")
    reported_location = models.PointField()
    actual_location = models.PointField()
{'fraction_non_alphanumeric': 0.1263952724885095, 'fraction_numerical': 0.00623768877216021, 'mean_word_length': 3.4604685212298683, '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': '6232990', 'n_tokens_mistral': 1880, 'n_tokens_neox': 1811, 'n_words': 432}