2017-10-03 11:31:24 +00:00
|
|
|
from geoalchemy2.shape import to_shape
|
|
|
|
from geoalchemy2.types import Geometry
|
2018-12-08 19:04:41 +00:00
|
|
|
from sqlalchemy import Column, Float, String, Integer, DateTime, ForeignKey
|
|
|
|
from sqlalchemy.orm import relationship, backref
|
2015-11-15 10:59:52 +00:00
|
|
|
|
|
|
|
from .base import Base
|
2016-04-24 17:34:25 +00:00
|
|
|
from .geo import Location
|
2015-11-15 10:59:52 +00:00
|
|
|
|
|
|
|
|
2015-11-16 19:09:26 +00:00
|
|
|
class Receiver(Base):
|
2018-01-11 07:35:07 +00:00
|
|
|
__tablename__ = "receivers"
|
2015-11-15 10:59:52 +00:00
|
|
|
|
|
|
|
id = Column(Integer, primary_key=True)
|
2016-04-24 17:34:25 +00:00
|
|
|
|
|
|
|
location_wkt = Column('location', Geometry('POINT', srid=4326))
|
2018-01-21 20:06:27 +00:00
|
|
|
altitude = Column(Float(precision=2))
|
2016-04-24 17:34:25 +00:00
|
|
|
|
2018-10-21 15:34:03 +00:00
|
|
|
name = Column(String(9), index=True)
|
2015-11-15 10:59:52 +00:00
|
|
|
firstseen = Column(DateTime, index=True)
|
|
|
|
lastseen = Column(DateTime, index=True)
|
|
|
|
version = Column(String)
|
|
|
|
platform = Column(String)
|
2016-04-24 17:34:25 +00:00
|
|
|
|
2018-12-08 19:04:41 +00:00
|
|
|
# Relations
|
|
|
|
country_id = Column(Integer, ForeignKey('countries.gid', ondelete='SET NULL'), index=True)
|
|
|
|
country = relationship('Country', foreign_keys=[country_id], backref=backref('receivers', order_by='Receiver.name.asc()'))
|
|
|
|
|
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)
|