2017-10-03 11:31:24 +00:00
|
|
|
from geoalchemy2.shape import to_shape
|
|
|
|
from geoalchemy2.types import Geometry
|
2015-11-15 10:59:52 +00:00
|
|
|
|
2016-04-24 17:34:25 +00:00
|
|
|
from .geo import Location
|
2015-11-15 10:59:52 +00:00
|
|
|
|
2019-08-31 08:14:41 +00:00
|
|
|
from app import db
|
2015-11-15 10:59:52 +00:00
|
|
|
|
2019-02-10 12:10:19 +00:00
|
|
|
|
|
|
|
class Receiver(db.Model):
|
2018-01-11 07:35:07 +00:00
|
|
|
__tablename__ = "receivers"
|
2015-11-15 10:59:52 +00:00
|
|
|
|
2020-05-15 17:01:17 +00:00
|
|
|
name = db.Column(db.String(9), primary_key=True)
|
2019-08-31 08:14:41 +00:00
|
|
|
location_wkt = db.Column("location", Geometry("POINT", srid=4326))
|
2019-02-10 12:25:24 +00:00
|
|
|
altitude = db.Column(db.Float(precision=2))
|
2016-04-24 17:34:25 +00:00
|
|
|
|
2019-02-10 12:25:24 +00:00
|
|
|
firstseen = db.Column(db.DateTime, index=True)
|
|
|
|
lastseen = db.Column(db.DateTime, index=True)
|
2020-05-15 17:01:17 +00:00
|
|
|
timestamp = db.Column(db.DateTime, index=True)
|
2019-02-10 12:25:24 +00:00
|
|
|
version = db.Column(db.String)
|
|
|
|
platform = db.Column(db.String)
|
2016-04-24 17:34:25 +00:00
|
|
|
|
2018-12-08 19:04:41 +00:00
|
|
|
# Relations
|
2019-08-31 08:14:41 +00:00
|
|
|
country_id = db.Column(db.Integer, db.ForeignKey("countries.gid", ondelete="SET NULL"), index=True)
|
|
|
|
country = db.relationship("Country", foreign_keys=[country_id], backref=db.backref("receivers", order_by="Receiver.name.asc()"))
|
2018-12-08 19:04:41 +00:00
|
|
|
|
2016-04-24 17:34:25 +00:00
|
|
|
@property
|
|
|
|
def location(self):
|
|
|
|
if self.location_wkt is None:
|
|
|
|
return None
|
|
|
|
|
|
|
|
coords = to_shape(self.location_wkt)
|
|
|
|
return Location(lat=coords.y, lon=coords.x)
|