Пример #1
0
class Frequency(Base):
    """Description of a trip that repeats without fixed stop times"""
    trip = models.ForeignKey('Trip')
    start_time = SecondsField(
        help_text="Time that the service begins at the specified frequency")
    end_time = SecondsField(
        help_text="Time that the service ends at the specified frequency")
    headway_secs = models.IntegerField(
        help_text="Time in seconds before returning to same stop")
    exact_times = models.CharField(
        max_length=1,
        blank=True,
        choices=((0, 'Trips are not exactly scheduled'),
                 (1, 'Trips are exactly scheduled from start time')),
        help_text="Should frequency-based trips be exactly scheduled?")
    extra_data = JSONField(default={}, blank=True, null=True)

    def __str__(self):
        return str(self.trip)

    class Meta:
        db_table = 'frequency'
        app_label = 'multigtfs'
        verbose_name_plural = "frequencies"

    # For Base import/export
    _column_map = (('trip_id', 'trip__trip_id'), ('start_time', 'start_time'),
                   ('end_time', 'end_time'), ('headway_secs', 'headway_secs'),
                   ('exact_times', 'exact_times'))
    _filename = 'frequencies.txt'
    _rel_to_feed = 'trip__route__feed'
    _unique_fields = ('trip_id', 'start_time')
Пример #2
0
class StopTime(Base):
    """A specific stop on a route on a trip.

    This implements stop_times.txt in the GTFS feed
    """
    trip = models.ForeignKey(Trip, on_delete=models.CASCADE)
    stop = models.ForeignKey(Stop, on_delete=models.CASCADE)
    arrival_time = SecondsField(
        default=None, null=True, blank=True,
        help_text="Arrival time. Must be set for end stops of trip.")
    departure_time = SecondsField(
        default=None, null=True, blank=True,
        help_text='Departure time. Must be set for end stops of trip.')
    stop_sequence = models.IntegerField()
    stop_headsign = models.CharField(
        max_length=255, blank=True,
        help_text="Sign text that identifies the stop for passengers")
    pickup_type = models.CharField(
        max_length=1, blank=True,
        choices=(('0', 'Regularly scheduled pickup'),
                 ('1', 'No pickup available'),
                 ('2', 'Must phone agency to arrange pickup'),
                 ('3', 'Must coordinate with driver to arrange pickup')),
        help_text="How passengers are picked up")
    drop_off_type = models.CharField(
        max_length=1, blank=True,
        choices=(('0', 'Regularly scheduled drop off'),
                 ('1', 'No drop off available'),
                 ('2', 'Must phone agency to arrange drop off'),
                 ('3', 'Must coordinate with driver to arrange drop off')),
        help_text="How passengers are picked up")
    shape_dist_traveled = models.FloatField(
        "shape distance traveled",
        null=True, blank=True,
        help_text='Distance of stop from start of shape')
    extra_data = JSONField(default={}, blank=True, null=True)

    def __str__(self):
        return "%s-%s-%s" % (self.trip, self.stop.stop_id, self.stop_sequence)

    class Meta:
        db_table = 'stop_time'
        app_label = 'multigtfs'

    _column_map = (
        ('trip_id', 'trip__trip_id'),
        ('arrival_time', 'arrival_time'),
        ('departure_time', 'departure_time'),
        ('stop_id', 'stop__stop_id'),
        ('stop_sequence', 'stop_sequence'),
        ('stop_headsign', 'stop_headsign'),
        ('pickup_type', 'pickup_type'),
        ('drop_off_type', 'drop_off_type'),
        ('shape_dist_traveled', 'shape_dist_traveled')
    )
    _filename = 'stop_times.txt'
    _rel_to_feed = 'trip__route__feed'
    _sort_order = ('trip__trip_id', 'stop_sequence')
    _unique_fields = ('trip_id', 'stop_sequence')
Пример #3
0
class SecondsFieldTest(TestCase):
    def setUp(self):
        self.f = SecondsField()

    def test_to_python_int(self):
        self.assertEqual(Seconds(400), self.f.to_python(400))

    def test_to_python_Seconds(self):
        self.assertEqual(Seconds(500), self.f.to_python(Seconds(500)))

    def test_to_python_seconds_string(self):
        self.assertEqual(Seconds(500), self.f.to_python('500'))

    def test_to_python_hm_string(self):
        self.assertEqual(Seconds(3660), self.f.to_python('01:01'))

    def test_to_python_hms_string(self):
        self.assertEqual(Seconds(3661), self.f.to_python('01:01:01'))

    def test_to_python_too_many_colons(self):
        self.assertRaises(ValueError, self.f.to_python, '01:01:01:01')

    def test_to_python_none(self):
        self.assertIsNone(self.f.to_python(None))

    def test_to_python_empty_string(self):
        self.assertIsNone(self.f.to_python(''))

    def test_prep_db_value_Seconds(self):
        self.assertEqual(500, self.f.get_prep_value(Seconds(500)))

    def test_prep_db_value_None(self):
        self.assertIsNone(self.f.get_prep_value(None))
Пример #4
0
class SecondsFieldTest(TestCase):

    def setUp(self):
        self.f = SecondsField()

    def test_to_python_int(self):
        self.assertEqual(Seconds(400), self.f.to_python(400))

    def test_to_python_Seconds(self):
        self.assertEqual(Seconds(500), self.f.to_python(Seconds(500)))

    def test_to_python_seconds_string(self):
        self.assertEqual(Seconds(500), self.f.to_python('500'))

    def test_to_python_hm_string(self):
        self.assertEqual(Seconds(3660), self.f.to_python('01:01'))

    def test_to_python_hms_string(self):
        self.assertEqual(Seconds(3661), self.f.to_python('01:01:01'))

    def test_to_python_too_many_colons(self):
        self.assertRaises(ValueError, self.f.to_python, '01:01:01:01')

    def test_to_python_none(self):
        self.assertIsNone(self.f.to_python(None))

    def test_to_python_empty_string(self):
        self.assertIsNone(self.f.to_python(''))

    def test_prep_db_value_Seconds(self):
        self.assertEqual(500, self.f.get_prep_value(Seconds(500)))

    def test_prep_db_value_None(self):
        self.assertIsNone(self.f.get_prep_value(None))
Пример #5
0
 def setUp(self):
     self.f = SecondsField()
Пример #6
0
 def setUp(self):
     self.f = SecondsField()