Exemplo n.º 1
0
class FeedInfo(Base):
    """Information about the feed"""
    feed = models.ForeignKey('Feed')
    publisher_name = models.CharField(
        max_length=255,
        help_text="Full name of organization that publishes the feed.")
    publisher_url = models.URLField(
        help_text="URL of the feed publisher's organization.")
    lang = models.CharField(
        max_length=20,
        help_text="IETF BCP 47 language code for text in field.")
    start_date = models.DateField(
        null=True,
        blank=True,
        help_text="Date that feed starts providing reliable data.")
    end_date = models.DateField(
        null=True,
        blank=True,
        help_text="Date that feed stops providing reliable data.")
    version = models.CharField(max_length=255,
                               blank=True,
                               help_text="Version of feed.")

    def __unicode__(self):
        return u'%s-%s' % (self.feed.id, self.publisher_name)

    class Meta:
        db_table = 'multigtfs_feedinfo'
        app_label = 'multigtfs'
        verbose_name_plural = "feed info"

    _column_map = (('feed_publisher_name',
                    'publisher_name'), ('feed_publisher_url', 'publisher_url'),
                   ('feed_lang', 'lang'), ('feed_start_date', 'start_date'),
                   ('feed_end_date', 'end_date'), ('feed_version', 'version'))
Exemplo n.º 2
0
class Service(Base):
    """Dates that a route is active.

    Implements calendar.txt
    """

    feed = models.ForeignKey('Feed', on_delete=models.CASCADE)
    service_id = models.CharField(
        max_length=255,
        db_index=True,
        help_text="Unique identifier for service dates.")
    monday = models.BooleanField(default=True,
                                 help_text="Is the route active on Monday?")
    tuesday = models.BooleanField(default=True,
                                  help_text="Is the route active on Tuesday?")
    wednesday = models.BooleanField(
        default=True, help_text="Is the route active on Wednesday?")
    thursday = models.BooleanField(
        default=True, help_text="Is the route active on Thursday?")
    friday = models.BooleanField(default=True,
                                 help_text="Is the route active on Friday?")
    saturday = models.BooleanField(
        default=True, help_text="Is the route active on Saturday?")
    sunday = models.BooleanField(default=True,
                                 help_text="Is the route active on Sunday?")
    start_date = models.DateField(null=True, blank=True)
    end_date = models.DateField(null=True, blank=True)
    extra_data = JSONField(default={}, blank=True, null=True)

    def __str__(self):
        return "%d-%s" % (self.feed.id, self.service_id)

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

    # For Base import/export
    _column_map = (('service_id', 'service_id'), ('monday', 'monday'),
                   ('tuesday', 'tuesday'), ('wednesday', 'wednesday'),
                   ('thursday', 'thursday'), ('friday', 'friday'),
                   ('saturday', 'saturday'), ('sunday', 'sunday'),
                   ('start_date', 'start_date'), ('end_date', 'end_date'))
    _filename = 'calendar.txt'
    _sort_order = ('start_date', 'end_date')
    _unique_fields = ('service_id', )

    @classmethod
    def export_txt(cls, feed):
        '''Export records as calendar.txt'''

        # If no records with start/end dates, skip calendar.txt
        objects = cls.objects.in_feed(feed)

        if not objects.exclude(start_date__isnull=True,
                               end_date__isnull=True).exists():
            return None

        return super(Service, cls).export_txt(feed)
Exemplo n.º 3
0
class ServiceDate(Base):
    """Dates that a route is active."""

    service = models.ForeignKey('Service')
    date = models.DateField(
        help_text="Date that the service differs from the norm.")
    exception_type = models.IntegerField(
        default=1,
        choices=((1, 'Added'), (2, 'Removed')),
        help_text="Is service added or removed on this date?")
    extra_data = JSONField(default={}, blank=True, null=True)

    def __str__(self):
        return ("%d-%s %s %s" %
                (self.service.feed.id, self.service.service_id, self.date,
                 'Added' if self.exception_type == 1 else 'Removed'))

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

    # For Base import/export
    _column_map = (('service_id', 'service__service_id'), ('date', 'date'),
                   ('exception_type', 'exception_type'))
    _filename = 'calendar_dates.txt'
    _rel_to_feed = 'service__feed'
    _sort_order = ('date', 'exception_type')
    _unique_fields = ('service_id', 'date')
Exemplo n.º 4
0
class Service(Base):
    """Dates that a route is active."""

    feed = models.ForeignKey('Feed')
    service_id = models.CharField(
        max_length=255,
        db_index=True,
        help_text="Unique identifier for service dates.")
    monday = models.BooleanField(default=True,
                                 help_text="Is the route active on Monday?")
    tuesday = models.BooleanField(default=True,
                                  help_text="Is the route active on Tuesday?")
    wednesday = models.BooleanField(
        default=True, help_text="Is the route active on Wednesday?")
    thursday = models.BooleanField(
        default=True, help_text="Is the route active on Thursday?")
    friday = models.BooleanField(default=True,
                                 help_text="Is the route active on Friday?")
    saturday = models.BooleanField(
        default=True, help_text="Is the route active on Saturday?")
    sunday = models.BooleanField(default=True,
                                 help_text="Is the route active on Sunday?")
    start_date = models.DateField(
        default=datetime.strptime('18991231', '%Y%m%d'))
    end_date = models.DateField(
        default=datetime.strptime('21000101', '%Y%m%d'))

    def __unicode__(self):
        return u"%d-%s" % (self.feed.id, self.service_id)

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

    # For Base import/export
    _column_map = (('service_id', 'service_id'), ('monday', 'monday'),
                   ('tuesday', 'tuesday'), ('wednesday', 'wednesday'),
                   ('thursday', 'thursday'), ('friday', 'friday'),
                   ('saturday', 'saturday'), ('sunday', 'sunday'),
                   ('start_date', 'start_date'), ('end_date', 'end_date'))
    _sort_order = ('start_date', 'end_date')

    # support commonly out-of-date GTFS feed data
    # {'old csv name': 'django field name'}
    _legacy_format = {
        'service_name': 'service_id',
    }
Exemplo n.º 5
0
class Service(Base):
    """Dates that a route is active."""

    feed = models.ForeignKey('Feed')
    service_id = models.CharField(
        max_length=255,
        db_index=True,
        help_text="Unique identifier for service dates.")
    monday = models.BooleanField(default=True,
                                 help_text="Is the route active on Monday?")
    tuesday = models.BooleanField(default=True,
                                  help_text="Is the route active on Tuesday?")
    wednesday = models.BooleanField(
        default=True, help_text="Is the route active on Wednesday?")
    thursday = models.BooleanField(
        default=True, help_text="Is the route active on Thursday?")
    friday = models.BooleanField(default=True,
                                 help_text="Is the route active on Friday?")
    saturday = models.BooleanField(
        default=True, help_text="Is the route active on Saturday?")
    sunday = models.BooleanField(default=True,
                                 help_text="Is the route active on Sunday?")
    start_date = models.DateField()
    end_date = models.DateField()
    extra_data = JSONField(default={}, blank=True, null=True)

    def __str__(self):
        return "%d-%s" % (self.feed.id, self.service_id)

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

    # For Base import/export
    _column_map = (('service_id', 'service_id'), ('monday', 'monday'),
                   ('tuesday', 'tuesday'), ('wednesday', 'wednesday'),
                   ('thursday', 'thursday'), ('friday', 'friday'),
                   ('saturday', 'saturday'), ('sunday', 'sunday'),
                   ('start_date', 'start_date'), ('end_date', 'end_date'))
    _filename = 'calendar.txt'
    _sort_order = ('start_date', 'end_date')
    _unique_fields = ('service_id', )
class FeedInfo(Base):
    """Information about the feed

    Implements feed_info.txt in the GTFS feed.
    """
    feed = models.ForeignKey('Feed', on_delete=models.CASCADE)
    publisher_name = models.CharField(
        max_length=255,
        help_text="Full name of organization that publishes the feed.")
    publisher_url = models.URLField(
        help_text="URL of the feed publisher's organization.")
    lang = models.CharField(
        "language",
        max_length=20,
        help_text="IETF BCP 47 language code for text in field.")
    start_date = models.DateField(
        null=True,
        blank=True,
        help_text="Date that feed starts providing reliable data.")
    end_date = models.DateField(
        null=True,
        blank=True,
        help_text="Date that feed stops providing reliable data.")
    version = models.CharField(max_length=255,
                               blank=True,
                               help_text="Version of feed.")
    extra_data = JSONField(default={}, blank=True, null=True)

    def __str__(self):
        return '%s-%s' % (self.feed.id, self.publisher_name)

    class Meta:
        db_table = 'feed_info'
        app_label = 'multigtfs'
        verbose_name_plural = "feed info"

    _column_map = (('feed_publisher_name',
                    'publisher_name'), ('feed_publisher_url', 'publisher_url'),
                   ('feed_lang', 'lang'), ('feed_start_date', 'start_date'),
                   ('feed_end_date', 'end_date'), ('feed_version', 'version'))
    _filename = 'feed_info.txt'
    _unique_fields = ('feed_publisher_name', )