<commit_before># -*- coding: utf-8 -*-

from sqlalchemy.dialects import postgresql
from sqlalchemy.types import String, Integer, DateTime, Interval
from geoalchemy2.types import Geometry
from geoalchemy2.elements import WKTElement
from geoalchemy2.shape import to_shape

from skylines.database import db
from .geo import Location


class Trace(db.Model):
    """
    This table saves the locations and visiting times of the turnpoints
    of an optimized Flight.
    """

    __tablename__ = "traces"

    id = db.Column(Integer, autoincrement=True, primary_key=True)

    flight_id = db.Column(
        Integer, db.ForeignKey("flights.id", ondelete="CASCADE"), nullable=False
    )
    flight = db.relationship(
        "Flight", innerjoin=True, backref=db.backref("traces", passive_deletes=True)
    )

    contest_type = db.Column(String, nullable=False)
    trace_type = db.Column(String, nullable=False)

    # the optimized distance in meters
    distance = db.Column(Integer)
    duration = db.Column(Interval)

    times = db.Column(postgresql.ARRAY(DateTime), nullable=False)
    _locations = db.Column(
        "locations", Geometry("LINESTRING", srid=4326), nullable=False
    )

    @property
    def speed(self):
        if self.distance is None or self.duration is None:
            return None

        return float(self.distance) / self.duration.total_seconds()

    @property<commit_msg>model/trace: Fix `flight` backref cascading<commit_after># -*- coding: utf-8 -*-

from sqlalchemy.dialects import postgresql
from sqlalchemy.types import String, Integer, DateTime, Interval
from geoalchemy2.types import Geometry
from geoalchemy2.elements import WKTElement
from geoalchemy2.shape import to_shape

from skylines.database import db
from .geo import Location


class Trace(db.Model):
    """
    This table saves the locations and visiting times of the turnpoints
    of an optimized Flight.
    """

    __tablename__ = "traces"

    id = db.Column(Integer, autoincrement=True, primary_key=True)

    flight_id = db.Column(
        Integer, db.ForeignKey("flights.id", ondelete="CASCADE"), nullable=False
    )
    flight = db.relationship(
        "Flight",
        innerjoin=True,
        backref=db.backref(
            "traces", passive_deletes=True, cascade="all, delete, delete-orphan"
        ),
    )

    contest_type = db.Column(String, nullable=False)
    trace_type = db.Column(String, nullable=False)

    # the optimized distance in meters
    distance = db.Column(Integer)
    duration = db.Column(Interval)

    times = db.Column(postgresql.ARRAY(DateTime), nullable=False)
    _locations = db.Column(
        "locations", Geometry("LINESTRING", srid=4326), nullable=False
    )

    @property
    def speed(self):
        if self.distance is None or self.duration is None:
            return None

        return float(self.distance) / self.duration.total_seconds()

    @property
{'fraction_non_alphanumeric': 0.09948542024013722, 'fraction_numerical': 0.005488850771869639, 'mean_word_length': 3.3652694610778444, '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': '4003104', 'n_tokens_mistral': 921, 'n_tokens_neox': 858, 'n_words': 227}