kopia lustrzana https://github.com/glidernet/ogn-python
Calculate distance between aircraft_beacon and receiver
rodzic
ca1dba3e23
commit
061c3e253e
|
@ -172,7 +172,7 @@ def update_devices():
|
|||
|
||||
@manager.command
|
||||
def update_receivers():
|
||||
"""Add/update_receivers entries in receiver table and update_receivers foreign keys in aircraft beacons and receiver beacons."""
|
||||
"""Add/update_receivers entries in receiver table and update receivers foreign keys and distance in aircraft beacons and update foreign keys in receiver beacons."""
|
||||
# Create missing Receiver from ReceiverBeacon
|
||||
available_receivers = session.query(Receiver.name) \
|
||||
.subquery()
|
||||
|
@ -240,7 +240,8 @@ def update_receivers():
|
|||
# Update relations to aircraft beacons
|
||||
update_aircraft_beacons = session.query(AircraftBeacon) \
|
||||
.filter(and_(AircraftBeacon.receiver_id == null(), AircraftBeacon.receiver_name == Receiver.name)) \
|
||||
.update({AircraftBeacon.receiver_id: Receiver.id},
|
||||
.update({AircraftBeacon.receiver_id: Receiver.id,
|
||||
AircraftBeacon.distance: func.ST_Distance_Sphere(AircraftBeacon.location_wkt, Receiver.location_wkt)},
|
||||
synchronize_session='fetch')
|
||||
|
||||
# Update relations to receiver beacons
|
||||
|
|
|
@ -38,6 +38,9 @@ class AircraftBeacon(Beacon):
|
|||
|
||||
status = Column(SmallInteger, index=True)
|
||||
|
||||
# Calculated values
|
||||
distance = Column(Float)
|
||||
|
||||
# Relations
|
||||
receiver_id = Column(Integer, ForeignKey('receiver.id', ondelete='SET NULL'), index=True)
|
||||
receiver = relationship('Receiver', foreign_keys=[receiver_id])
|
||||
|
|
Ładowanie…
Reference in New Issue