2016-04-24 17:34:25 +00:00
|
|
|
from sqlalchemy import Column, String, Integer, DateTime
|
2016-05-22 05:23:22 +00:00
|
|
|
from sqlalchemy.orm import relationship
|
2016-04-24 17:34:25 +00:00
|
|
|
from geoalchemy2.types import Geometry
|
|
|
|
from geoalchemy2.shape import to_shape
|
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):
|
|
|
|
__tablename__ = "receiver"
|
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))
|
2015-11-15 10:59:52 +00:00
|
|
|
altitude = Column(Integer)
|
2016-04-24 17:34:25 +00:00
|
|
|
|
|
|
|
name = Column(String(9))
|
2015-11-15 10:59:52 +00:00
|
|
|
firstseen = Column(DateTime, index=True)
|
|
|
|
lastseen = Column(DateTime, index=True)
|
|
|
|
country_code = Column(String(2))
|
|
|
|
version = Column(String)
|
|
|
|
platform = Column(String)
|
2016-04-24 17:34:25 +00:00
|
|
|
|
2016-05-22 05:23:22 +00:00
|
|
|
# Relations
|
|
|
|
aircraft_beacons = relationship('AircraftBeacon')
|
|
|
|
receiver_beacons = relationship('ReceiverBeacon')
|
|
|
|
|
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)
|