<commit_before>from django.db import models
from django.contrib.gis.db import models
from django.contrib.gis.geos import GEOSGeometry, Polygon

from django_enumfield import enum

from .excerpt import Excerpt


class BoundingGeometryType(enum.Enum):
    BOUNDINGBOX = 0
    # POLYGON = 1


class BoundingGeometry(models.Model):
    @staticmethod
    def create_from_bounding_box_coordinates(north, east, south, west):
        bounding_geometry = BoundingGeometry()
        bounding_geometry.type = BoundingGeometryType.BOUNDINGBOX
        polygon = Polygon([
            GEOSGeometry('POINT(%s %s)' % (west, south)),
            GEOSGeometry('POINT(%s %s)' % (west, north)),
            GEOSGeometry('POINT(%s %s)' % (east, north)),
            GEOSGeometry('POINT(%s %s)' % (east, south)),
            GEOSGeometry('POINT(%s %s)' % (west, south))
        ])
        bounding_geometry.geometry = GEOSGeometry(polygon)
        return bounding_geometry

    type = enum.EnumField(BoundingGeometryType, default=BoundingGeometryType.BOUNDINGBOX)
    geometry = models.GeometryField(srid=4326, blank=True, null=True, spatial_index=True)

    # django admin inline mode needs relation from BoundingGeometry to Excerpt -> inverse relation does not work
    excerpt = models.OneToOneField(Excerpt, null=True)

    # overriding the default manager with a GeoManager instance.
    # required to perform spatial queries
    objects = models.GeoManager()

    def __str__(self):
        geometry_type = 'Bounding box' if (self.type == BoundingGeometryType.BOUNDINGBOX) else 'Polygon'
        points = []
        for coordinates in self.geometry[0]:
            points.append('(' + ', '.join(list(str(round(coordinate, 5)) for coordinate in coordinates)) + ')')
        return geometry_type + ': ' + ', '.join(points)<commit_msg>refactoring: use idiomatic form of python list comprehension<commit_after>from django.db import models
from django.contrib.gis.db import models
from django.contrib.gis.geos import GEOSGeometry, Polygon

from django_enumfield import enum

from .excerpt import Excerpt


class BoundingGeometryType(enum.Enum):
    BOUNDINGBOX = 0
    # POLYGON = 1


class BoundingGeometry(models.Model):
    @staticmethod
    def create_from_bounding_box_coordinates(north, east, south, west):
        bounding_geometry = BoundingGeometry()
        bounding_geometry.type = BoundingGeometryType.BOUNDINGBOX
        polygon = Polygon([
            GEOSGeometry('POINT(%s %s)' % (west, south)),
            GEOSGeometry('POINT(%s %s)' % (west, north)),
            GEOSGeometry('POINT(%s %s)' % (east, north)),
            GEOSGeometry('POINT(%s %s)' % (east, south)),
            GEOSGeometry('POINT(%s %s)' % (west, south))
        ])
        bounding_geometry.geometry = GEOSGeometry(polygon)
        return bounding_geometry

    type = enum.EnumField(BoundingGeometryType, default=BoundingGeometryType.BOUNDINGBOX)
    geometry = models.GeometryField(srid=4326, blank=True, null=True, spatial_index=True)

    # django admin inline mode needs relation from BoundingGeometry to Excerpt -> inverse relation does not work
    excerpt = models.OneToOneField(Excerpt, null=True)

    # overriding the default manager with a GeoManager instance.
    # required to perform spatial queries
    objects = models.GeoManager()

    def __str__(self):
        geometry_type = 'Bounding box' if (self.type == BoundingGeometryType.BOUNDINGBOX) else 'Polygon'
        points = []
        for coordinates in self.geometry[0]:
            points.append('(' + ', '.join([str(round(coordinate, 5)) for coordinate in coordinates]) + ')')
        return geometry_type + ': ' + ', '.join(points)
{'fraction_non_alphanumeric': 0.10863054723659134, 'fraction_numerical': 0.004356112169888375, 'mean_word_length': 3.547029702970297, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '5929208', 'n_tokens_mistral': 1108, 'n_tokens_neox': 1030, 'n_words': 268}