예제 #1
0
class ExceptionInfoModel(db.Model):
    __tablename__ = 'exceptioninfo'
    id = db.Column(db.Integer, primary_key=True)
    lastappeared_id = db.Column(db.String(50))
    exception_type = db.Column(db.String(255), nullable=False)
    start_time = db.Column(db.DateTime, nullable=False)
    end_time = db.Column(db.DateTime, nullable=False)
    reason = db.Column(db.String(255), nullable=False)
    lastmodified_time = db.Column(db.DateTime, nullable=False)

    def update(self, info):
        self.end_time = info["end_time"]
        self.reason = info["reason"]

    def dictRepr(self):
        info = {
            "id":
            self.id,
            "lastappeared_id ":
            self.lastappeared_id,
            "start_time":
            self.start_time.strftime("%Y-%m-%d %H:%M:%S"),
            "end_time":
            self.end_time.strftime("%Y-%m-%d %H:%M:%S"),
            "exception_type":
            self.exception_type,
            "reason":
            self.reason,
            "lastmodified_time":
            self.lastmodified_time.strftime("%Y-%m-%d %H:%M:%S")
        }
        return info
예제 #2
0
class NeighborhoodModel(db.Model):
    __bind_key__ = 'nyc'
    __tablename__ = 'nyc_neighborhoods'
    gid = db.Column(db.Integer, primary_key=True)
    boroname = db.Column(db.String(43))
    name = db.Column(db.String(64))
    geom = db.Column(Geometry(geometry_type='POINT', srid=26918))
예제 #3
0
class ObjectUseAirlineModel(db.Model):
    __tablename__ = 'object_use_airline'
    id = db.Column(db.Integer, primary_key=True)
    object_id = db.Column(db.String(50), nullable=False)
    flight_task_number = db.Column(db.String(50), nullable=False)
    pub_date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)

    airline_id = db.Column(db.Integer,
                           db.ForeignKey('airline.id'),
                           nullable=False)
예제 #4
0
class CarsModel(db.Model):
    __tablename__ = 'cars'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String())
    model = db.Column(db.String())
    doors = db.Column(db.Integer())

    def __init__(self, name, model, doors):
        self.name = name
        self.model = model
        self.doors = doors

    def __repr__(self):
        return f"<Car {self.name}>"
예제 #5
0
class AirLineModel(db.Model):
    __tablename__ = 'airline'

    id = db.Column(db.Integer, primary_key=True)
    airlinecode = db.Column(db.String(80), unique=True,
                            nullable=False)  #air line number
    airlinegps = db.Column(Geometry(geometry_type='LINESTRING', srid=4326),
                           nullable=False)
예제 #6
0
class ExceptionTypeModel(db.Model):
    __tablename__ = 'exceptiontype'
    lastappeared_id = db.Column(db.Integer,
                                db.ForeignKey('lastappeared.id',
                                              ondelete="CASCADE"),
                                primary_key=True)
    exceptiontype = db.Column(db.String())

    def dictRepr(self):
        return {
            "lastappeared_id": self.lastappeared_id,
            "exceptiontype": self.exceptiontype
        }
예제 #7
0
class ImportantRegion(db.Model):
    __tablename__ = 'importantregion'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50), unique=True, nullable=False)
    geom = db.Column(Geometry(geometry_type='POLYGON', srid=4326),
                     nullable=False)

    def dictRepr(self):
        p = json.loads(db.session.scalar(
            self.geom.ST_AsGeoJSON()))["coordinates"]
        return {
            "id": self.id,
            "name": self.name,
            "gps_points": [{
                'long': s[0],
                'lat': s[1]
            } for r in p for s in r]
        }
예제 #8
0
class LastappearedModel(db.Model):
    __tablename__ = 'lastappeared'

    def defaultDate():
        return datetime.now().date()

    def defaultTime():
        return datetime.now().time()

    id = db.Column(db.Integer, primary_key=True)
    object_id = db.Column(db.String(50), nullable=False)
    lastmodified_date = db.Column(db.Date, nullable=False, default=defaultDate)
    lastmodified_time = db.Column(db.Time, nullable=False, default=defaultTime)
    gps_point = db.Column(Geometry(geometry_type='POINTM', srid=4326),
                          nullable=False)
    exception_type = db.relationship('ExceptionTypeModel',
                                     uselist=False,
                                     backref='lastappeared',
                                     lazy=True,
                                     cascade="all, delete",
                                     passive_deletes=True)
    machine_type = db.relationship('MachineTypeModel',
                                   uselist=False,
                                   backref='lastappeared',
                                   lazy=True,
                                   cascade="all, delete",
                                   passive_deletes=True)
    object_trajactory = db.relationship('ObjectTrajactoryModel',
                                        uselist=False,
                                        backref='lastappeared',
                                        lazy=True,
                                        cascade="all, delete",
                                        passive_deletes=True)
    __table_args__ = (db.UniqueConstraint('object_id', 'lastmodified_date'), )

    def __init__(self, **kwargs):
        if "lastmodified_time" in kwargs.keys() and type(
                kwargs["lastmodified_time"]) is str:
            lastmodified_date_time_str = kwargs["lastmodified_time"]
            kwargs["lastmodified_date_time"] = datetime.strptime(
                lastmodified_date_time_str, "%Y-%m-%d %H:%M:%S")
        else:
            kwargs["lastmodified_date_time"] = datetime.now()
        if "lastmodified_date" not in kwargs.keys() or type(
                kwargs["lastmodified_date"]) is str:
            kwargs["lastmodified_date"] = kwargs[
                "lastmodified_date_time"].date()
        if "lastmodified_time" not in kwargs.keys() or type(
                kwargs["lastmodified_time"]) is str:
            kwargs["lastmodified_time"] = kwargs[
                "lastmodified_date_time"].time()
        if "lat" in kwargs.keys() and "long" in kwargs.keys(
        ) and "gps_point" not in kwargs.keys():
            kwargs["gps_point"] = 'SRID=4326;POINTM({} {} {})'.format(
                kwargs["long"], kwargs["lat"],
                datetime.timestamp(kwargs["lastmodified_date_time"]))
            del kwargs["lat"]
            del kwargs["long"]
        del kwargs["lastmodified_date_time"]

        super(LastappearedModel, self).__init__(**kwargs)

    def update(self, body):
        if "lastmodified_time" in body.keys() and type(
                body["lastmodified_time"]) is str:
            lastmodified_date_time_str = body["lastmodified_time"]
            lastmodified_date_time = datetime.strptime(
                lastmodified_date_time_str, "%Y-%m-%d %H:%M:%S")
        else:
            lastmodified_date_time = datetime.now()
        self.lastmodified_date = lastmodified_date_time.date()
        self.lastmodified_time = lastmodified_date_time.time()
        if "lat" in body.keys() and "long" in body.keys():
            self.gps_point = 'SRID=4326;POINTM({} {} {})'.format(
                body["long"], body["lat"],
                datetime.timestamp(lastmodified_date_time))

    def lat(self):
        return db.session.scalar(self.gps_point.ST_Y())

    def long(self):
        return db.session.scalar(self.gps_point.ST_X())

    def M(self):
        return db.session.scalar(self.gps_point.ST_M())

    def dictRepr(self):
        info = {
            "id": self.id,
            "object_id": self.object_id,
            "lastmodified_date": self.lastmodified_date.strftime("%Y-%m-%d"),
            "lastmodified_time": self.lastmodified_time.strftime("%H:%M:%S"),
            "long": self.long(),
            "lat": self.lat(),
            "M": self.M()
        }
        if self.exception_type is not None:
            info["exception_type"] = self.exception_type.exceptiontype
        if self.machine_type is not None:
            info["machine_type"] = self.machine_type.machinetype

        return info
예제 #9
0
class Geometries3Model(db.Model):
    __bind_key__ = 'nyc'
    __tablename__ = 'geometries3'
    name = db.Column(db.String(64), primary_key=True)
    geom = db.Column(Geometry(geometry_type='LINESTRINGM', srid=4326))