Beispiel #1
0
class StreetNetworkBackend(db.Model, TimestampMixin):  # type: ignore
    __tablename__ = 'streetnetwork_backend'
    id = db.Column(db.Text, primary_key=True)
    klass = db.Column(db.Text, unique=False, nullable=False)
    discarded = db.Column(db.Boolean, nullable=False, default=False)
    args = db.Column(JSONB, server_default='{}')

    def __init__(self, id, json=None):
        self.id = id
        if json:
            self.from_json(json)

    def from_json(self, json):
        self.klass = json['klass']
        self.args = json.get('args', {})
        self.discarded = json.get('discarded', False)

    @classmethod
    def find_by_id(cls, id):
        return cls.query.filter_by(id=id).one()

    @classmethod
    def _not_discarded(cls):
        return cls.query.filter_by(discarded=False)

    @classmethod
    def all(cls):
        return cls._not_discarded().all()

    def last_update(self):
        return self.updated_at if self.updated_at else self.created_at
Beispiel #2
0
class RidesharingService(db.Model, TimestampMixin):  # type: ignore
    id = db.Column(db.Text, primary_key=True)
    klass = db.Column(db.Text, unique=False, nullable=False)
    discarded = db.Column(db.Boolean, nullable=False, default=False)
    args = db.Column(JSONB, server_default='{}')

    def __init__(self, id, json=None):
        self.id = id
        if json:
            self.from_json(json)

    def from_json(self, json):
        self.klass = json['klass']
        self.args = json['args']
        self.discarded = json[
            'discarded'] if 'discarded' in json else self.discarded

    @classmethod
    def find_by_id(cls, id):
        return cls.query.filter_by(id=id).one()

    @classmethod
    def _not_discarded(cls):
        return cls.query.filter_by(discarded=False)

    @classmethod
    def all(cls):
        return cls._not_discarded().all()

    def last_update(self):
        return self.updated_at if self.updated_at else self.created_at
Beispiel #3
0
class ExternalService(db.Model, TimestampMixin):  # type: ignore
    id = db.Column(db.Text, primary_key=True)
    klass = db.Column(db.Text, unique=False, nullable=False)
    discarded = db.Column(db.Boolean, nullable=False, default=False)
    navitia_service = db.Column(
        db.Enum('free_floatings',
                'vehicle_occupancies',
                name='navitia_service_type'),
        default=default_values.external_service,
        nullable=False,
    )
    args = db.Column(JSONB, server_default='{}')

    def __init__(self, id, json=None):
        self.id = id
        if json:
            self.from_json(json)

    def from_json(self, json):
        self.klass = json['klass']
        self.args = json['args']
        self.navitia_service = json[
            'navitia_service'] if 'navitia_service' in json else self.navitia_service
        self.discarded = json[
            'discarded'] if 'discarded' in json else self.discarded

    @classmethod
    def find_by_id(cls, id):
        return cls.query.filter_by(id=id).one()

    @classmethod
    def _not_discarded(cls):
        return cls.query.filter_by(discarded=False)

    @classmethod
    def all(cls):
        return cls._not_discarded().all()

    @classmethod
    def get_default(cls, navitia_service=None):
        return cls.query.filter_by(discarded=False,
                                   navitia_service=navitia_service).first()

    def last_update(self):
        return self.updated_at if self.updated_at else self.created_at
Beispiel #4
0
class BssProvider(db.Model, TimestampMixin):  # type: ignore
    id = db.Column(db.Text, primary_key=True)
    network = db.Column(db.Text, unique=False, nullable=False)
    klass = db.Column(db.Text, unique=False, nullable=False)
    timeout = db.Column(db.Interval,
                        nullable=False,
                        default=timedelta(seconds=2))
    discarded = db.Column(db.Boolean, nullable=False, default=False)
    args = db.Column(JSONB, server_default='{}')

    def __init__(self, id, json=None):
        self.id = id
        if json:
            self.from_json(json)

    def from_json(self, json):
        self.network = json['network']
        self.klass = json['klass']
        self.args = json['args']
        self.timeout = timedelta(
            seconds=json['timeout']) if 'timeout' in json else self.timeout
        self.discarded = json[
            'discarded'] if 'discarded' in json else self.discarded

    def __repr__(self):
        return '<BssProvider %r>' % self.id

    @classmethod
    def _not_discarded(cls):
        return cls.query.filter_by(discarded=False)

    @classmethod
    def all(cls):
        return cls._not_discarded().all()

    @classmethod
    def find_by_id(cls, id):
        return cls.query.filter_by(id=id).one()

    def last_update(self):
        return self.updated_at if self.updated_at else self.created_at

    def full_args(self):
        """
        generate args form jormungandr implementation of a providers
        """
        timeout = self.timeout.total_seconds() if self.timeout else 2
        args = {'network': self.network, 'timeout': timeout}
        if self.args:
            args.update(self.args)
        return args