From ae3788764d78c6f71a259a31070be8d19519014f Mon Sep 17 00:00:00 2001 From: "Fabian P. Schmidt" Date: Fri, 29 Jan 2016 05:25:35 +0100 Subject: [PATCH] celery: Add task update_beacon_receiver_distance Replaces ogn.commands.dbutils.update_receiver_childs --- README.md | 7 +++++-- ogn/collect/celery.py | 3 ++- ogn/commands/dbutils.py | 36 +----------------------------------- ogn/gateway/manage.py | 6 +++--- 4 files changed, 11 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index 87b6e3d..7248912 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/ogn/collect/celery.py b/ogn/collect/celery.py index 816e90b..6ef5479 100644 --- a/ogn/collect/celery.py +++ b/ogn/collect/celery.py @@ -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") diff --git a/ogn/commands/dbutils.py b/ogn/commands/dbutils.py index 99bfaf3..3e4a3c4 100644 --- a/ogn/commands/dbutils.py +++ b/ogn/commands/dbutils.py @@ -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() diff --git a/ogn/gateway/manage.py b/ogn/gateway/manage.py index 063cd17..7820edf 100644 --- a/ogn/gateway/manage.py +++ b/ogn/gateway/manage.py @@ -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()