kopia lustrzana https://github.com/glidernet/ogn-python
celery: Add task update_beacon_receiver_distance
Replaces ogn.commands.dbutils.update_receiver_childspull/35/head
rodzic
d3c38924e2
commit
ae3788764d
|
@ -143,9 +143,12 @@ Only the command `logbook.compute` requires a running task server (celery) at th
|
|||
- `import_ddb` - Import registered devices from the ddb
|
||||
- `import_file` - Import registered devices from a local file
|
||||
- ogn.collect.receiver
|
||||
- `populate` - generate Receiver table (NOT IMPLEMENTED)
|
||||
- `populate` - Generate Receiver table (NOT IMPLEMENTED)
|
||||
- ogn.collect.logbook
|
||||
- `compute_takeoff_and_landing` - generate TakeoffLanding table
|
||||
- `compute_takeoff_and_landing` - Generate TakeoffLanding table
|
||||
- ogn.collect.heatmap
|
||||
- `update_beacon_receiver_distance_all` - Calculate the distance between aircraft and
|
||||
receiver for the last aircraft beacons
|
||||
|
||||
|
||||
## License
|
||||
|
|
|
@ -26,6 +26,7 @@ def close_db(signal, sender):
|
|||
|
||||
app = Celery('ogn.collect',
|
||||
include=["ogn.collect.database",
|
||||
"ogn.collect.logbook"])
|
||||
"ogn.collect.logbook",
|
||||
"ogn.collect.heatmap"])
|
||||
|
||||
app.config_from_envvar("OGN_CONFIG_MODULE")
|
||||
|
|
|
@ -1,13 +1,9 @@
|
|||
import os
|
||||
import importlib
|
||||
|
||||
from sqlalchemy import create_engine, and_, desc
|
||||
from sqlalchemy.sql import null
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
|
||||
from ogn.model import AircraftBeacon, ReceiverBeacon
|
||||
from ogn.utils import haversine_distance
|
||||
|
||||
|
||||
os.environ.setdefault('OGN_CONFIG_MODULE', 'config.default')
|
||||
|
||||
|
@ -16,33 +12,3 @@ engine = create_engine(config.SQLALCHEMY_DATABASE_URI, echo=False)
|
|||
|
||||
Session = sessionmaker(bind=engine)
|
||||
session = Session()
|
||||
|
||||
|
||||
def update_receiver_childs(name):
|
||||
last_receiver_beacon = session.query(ReceiverBeacon) \
|
||||
.filter(ReceiverBeacon.name == name) \
|
||||
.order_by(desc(ReceiverBeacon.timestamp)) \
|
||||
.first()
|
||||
|
||||
if (last_receiver_beacon is None):
|
||||
return
|
||||
|
||||
aircraft_beacons_query = session.query(AircraftBeacon) \
|
||||
.filter(and_(AircraftBeacon.timestamp > last_receiver_beacon.timestamp,
|
||||
AircraftBeacon.receiver_name == name,
|
||||
AircraftBeacon.radius == null()))
|
||||
|
||||
for aircraft_beacon in aircraft_beacons_query.all():
|
||||
location0 = (last_receiver_beacon.latitude, last_receiver_beacon.longitude)
|
||||
location1 = (aircraft_beacon.latitude, aircraft_beacon.longitude)
|
||||
alt0 = last_receiver_beacon.altitude
|
||||
alt1 = aircraft_beacon.altitude
|
||||
|
||||
(flat_distance, phi) = haversine_distance(location0, location1)
|
||||
theta = atan2(alt1 - alt0, flat_distance) * 180 / pi
|
||||
distance = sqrt(flat_distance**2 + (alt1 - alt0)**2)
|
||||
|
||||
aircraft_beacon.radius = distance
|
||||
aircraft_beacon.theta = theta
|
||||
aircraft_beacon.phi = phi
|
||||
session.commit()
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import logging
|
||||
|
||||
from ogn.gateway.client import ognGateway
|
||||
from ogn.commands.dbutils import session, update_receiver_childs
|
||||
from ogn.model import ReceiverBeacon
|
||||
from ogn.commands.dbutils import session
|
||||
from ogn.collect.heatmap import update_beacon_receiver_distance
|
||||
|
||||
from manager import Manager
|
||||
|
||||
|
@ -36,7 +36,7 @@ def run(aprs_user='anon-dev', logfile='main.log', loglevel='INFO'):
|
|||
|
||||
def process_beacon(beacon):
|
||||
if isinstance(beacon, ReceiverBeacon):
|
||||
update_receiver_childs(beacon.name)
|
||||
update_beacon_receiver_distance(beacon.name)
|
||||
session.add(beacon)
|
||||
session.commit()
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue