<commit_before>from django.core.urlresolvers import reverse
from django.conf import settings
from django.contrib.gis.db import models

from leaderboard.locations.projected_geos import (
    ProjectedPoint,
    ProjectedPolygon,
    ProjectedMultiPolygon,
)


class CountryQuerySet(models.query.GeoQuerySet):
    """
    A queryset for Countries which will annotate
    the number of observations made in that country.
    """

    def annotate_observations(self):
        return self.annotate(
            observations=models.Sum('contributorrank__observations'),
        ).filter(observations__gt=0)


class CountryManager(models.GeoManager):
    """
    A model manager for Countries which allows you to
    query countries which are closest to a point.
    """

    def get_queryset(self):
        return CountryQuerySet(self.model, using=self._db)

    def nearest_to_point(self, point):
        country = self.get_queryset().distance(point).order_by('distance')[:1]

        if country.exists():
            return country.get()


class Country(models.Model):
    """
    A country as defined by:
    https://docs.djangoproject.com/en/1.8/ref/contrib/gis/
    tutorial/#defining-a-geographic-model
    """

    name = models.CharField(max_length=50)
    area = models.IntegerField()
    pop2005 = models.IntegerField('Population 2005')
    fips = models.CharField('FIPS Code', max_length=2)
    iso2 = models.CharField('2 Digit ISO', max_length=2, unique=True)
    iso3 = models.CharField('3 Digit ISO', max_length=3, unique=True)
    un = models.IntegerField('United Nations Code')
    region = models.IntegerField('Region Code')
    subregion = models.IntegerField('Sub-Region Code')
    lon = models.FloatField()
    lat = models.FloatField()
    geometry = models.MultiPolygonField(srid=settings.PROJECTION_SRID)

    objects = CountryManager()

    def __unicode__(self):
        return self.name
<commit_msg>Order countries by name<commit_after>from django.core.urlresolvers import reverse
from django.conf import settings
from django.contrib.gis.db import models

from leaderboard.locations.projected_geos import (
    ProjectedPoint,
    ProjectedPolygon,
    ProjectedMultiPolygon,
)


class CountryQuerySet(models.query.GeoQuerySet):
    """
    A queryset for Countries which will annotate
    the number of observations made in that country.
    """

    def annotate_observations(self):
        return self.annotate(
            observations=models.Sum('contributorrank__observations'),
        ).filter(observations__gt=0)


class CountryManager(models.GeoManager):
    """
    A model manager for Countries which allows you to
    query countries which are closest to a point.
    """

    def get_queryset(self):
        return CountryQuerySet(self.model, using=self._db)

    def nearest_to_point(self, point):
        country = self.get_queryset().distance(point).order_by('distance')[:1]

        if country.exists():
            return country.get()


class Country(models.Model):
    """
    A country as defined by:
    https://docs.djangoproject.com/en/1.8/ref/contrib/gis/
    tutorial/#defining-a-geographic-model
    """

    name = models.CharField(max_length=50)
    area = models.IntegerField()
    pop2005 = models.IntegerField('Population 2005')
    fips = models.CharField('FIPS Code', max_length=2)
    iso2 = models.CharField('2 Digit ISO', max_length=2, unique=True)
    iso3 = models.CharField('3 Digit ISO', max_length=3, unique=True)
    un = models.IntegerField('United Nations Code')
    region = models.IntegerField('Region Code')
    subregion = models.IntegerField('Sub-Region Code')
    lon = models.FloatField()
    lat = models.FloatField()
    geometry = models.MultiPolygonField(srid=settings.PROJECTION_SRID)

    objects = CountryManager()

    class Meta:
        ordering = ('name',)

    def __unicode__(self):
        return self.name

{'fraction_non_alphanumeric': 0.10554699537750385, 'fraction_numerical': 0.01078582434514638, 'mean_word_length': 3.4976905311778292, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '1055367', 'n_tokens_mistral': 1194, 'n_tokens_neox': 1136, 'n_words': 263}