ogn-python/app/model/beacon.py

46 wiersze
1.3 KiB
Python
Czysty Zwykły widok Historia

2017-10-03 11:31:24 +00:00
from geoalchemy2.shape import to_shape
from geoalchemy2.types import Geometry
2015-10-24 21:13:21 +00:00
from sqlalchemy.ext.declarative import AbstractConcreteBase
2019-01-28 21:06:38 +00:00
from sqlalchemy.ext.hybrid import hybrid_property
2015-10-24 21:13:21 +00:00
from .geo import Location
2015-10-24 21:13:21 +00:00
2019-08-31 08:14:41 +00:00
from app import db
2015-10-24 21:13:21 +00:00
2019-02-10 12:10:19 +00:00
class Beacon(AbstractConcreteBase, db.Model):
2015-10-24 21:13:21 +00:00
# APRS data
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))
name = db.Column(db.String, primary_key=True, nullable=True)
dstcall = db.Column(db.String)
relay = db.Column(db.String)
receiver_name = db.Column(db.String(9), primary_key=True, nullable=True)
timestamp = db.Column(db.DateTime, primary_key=True, nullable=True)
2015-10-24 21:13:21 +00:00
symboltable = None
symbolcode = None
2019-02-10 12:25:24 +00:00
track = db.Column(db.SmallInteger)
ground_speed = db.Column(db.Float(precision=2))
2015-10-24 21:13:21 +00:00
comment = None
2018-09-03 17:58:35 +00:00
# Type information
2017-10-03 12:14:48 +00:00
beacon_type = None
aprs_type = None
2018-09-03 17:58:35 +00:00
# Debug information
2019-01-30 19:29:56 +00:00
raw_message = None
reference_timestamp = None
2019-01-29 22:06:35 +00:00
@hybrid_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)
2019-01-28 21:06:38 +00:00
2019-01-29 22:06:35 +00:00
@location.expression
def location(cls):
return cls.location_wkt