From 6ce599fbb0d22e5536c4f096082f007df2194c9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Gru=CC=88ndger?= Date: Tue, 24 Nov 2015 20:06:06 +0100 Subject: [PATCH 1/4] Changed port for unfiltered beacons --- ogn/gateway/settings.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ogn/gateway/settings.py b/ogn/gateway/settings.py index d311da2..0273c48 100644 --- a/ogn/gateway/settings.py +++ b/ogn/gateway/settings.py @@ -1,7 +1,7 @@ APRS_SERVER_HOST = 'aprs.glidernet.org' -APRS_SERVER_PORT = 14580 +APRS_SERVER_PORT = 10152 APRS_APP_NAME = 'ogn-gateway-python' APRS_APP_VER = '0.2' -APRS_FILTER = 'r/50.0000/10.0000/5000' +APRS_FILTER = '' APRS_KEEPALIVE_TIME = 240 From e5b771fc19c3f8508a9b4b67c9de9fa7c84e9320 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Gru=CC=88ndger?= Date: Tue, 24 Nov 2015 20:07:20 +0100 Subject: [PATCH 2/4] Add failed line to parser exception --- ogn/gateway/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ogn/gateway/__init__.py b/ogn/gateway/__init__.py index 2a12b37..5a6e4ec 100644 --- a/ogn/gateway/__init__.py +++ b/ogn/gateway/__init__.py @@ -58,10 +58,10 @@ class ognGateway: try: beacon = parse_aprs(line) except AprsParseError: - logger.error('AprsParseError', exc_info=True) + logger.error('AprsParseError while parsing line: %s' % line, exc_info=True) return except OgnParseError: - logger.error('OgnParseError', exc_info=True) + logger.error('OgnParseError while parsing line: ' % line, exc_info=True) return if beacon is not None: From ceca97b47c5596c0fcdb0e1128b0fa9b692b4db1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Gru=CC=88ndger?= Date: Tue, 24 Nov 2015 21:00:31 +0100 Subject: [PATCH 3/4] Added logbook to manage.py --- ogn/collect/celery.py | 2 +- ogn/commands/logbook.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ogn/collect/celery.py b/ogn/collect/celery.py index bc89364..dd8f289 100644 --- a/ogn/collect/celery.py +++ b/ogn/collect/celery.py @@ -9,7 +9,7 @@ from celery.signals import worker_init, worker_shutdown app = Celery('ogn.collect', broker='redis://localhost:6379/0', backend='redis://localhost:6379/0', - include=["ogn.collect.fetchddb"]) + include=["ogn.collect.fetchddb", "ogn.collect.logbook"]) DB_URI = 'sqlite:///beacons.db' diff --git a/ogn/commands/logbook.py b/ogn/commands/logbook.py index 7b2484a..116409c 100644 --- a/ogn/commands/logbook.py +++ b/ogn/commands/logbook.py @@ -9,11 +9,19 @@ from sqlalchemy.sql.expression import true, false, label from ogn.model import Device, TakeoffLanding from ogn.commands.dbutils import session +from ogn.collect.logbook import compute_takeoff_and_landing from manager import Manager manager = Manager() +@manager.command +def compute(): + """Compute takeoffs and landings.""" + print("Compute takeoffs and landings...") + compute_takeoff_and_landing.delay() + + @manager.command def show(airport_name, latitude, longitude, altitude): """Show a logbook for located at given position.""" From 82efb81fbae6f632fab2e43cc926033d095d9d3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Gru=CC=88ndger?= Date: Tue, 24 Nov 2015 23:29:27 +0100 Subject: [PATCH 4/4] Logbook: recalculate last 5 minutes --- ogn/collect/fetchddb.py | 1 + ogn/collect/logbook.py | 20 +++++++++++++++++--- ogn/commands/logbook.py | 4 +++- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/ogn/collect/fetchddb.py b/ogn/collect/fetchddb.py index f228ed2..6b6fc57 100644 --- a/ogn/collect/fetchddb.py +++ b/ogn/collect/fetchddb.py @@ -36,6 +36,7 @@ def update_ddb_from_file(): .delete() devices = get_ddb('ogn/custom_ddb.txt') + logger.debug("New Devices: %s" % str(devices)) app.session.bulk_save_objects(devices) app.session.commit() diff --git a/ogn/collect/logbook.py b/ogn/collect/logbook.py index 59e835e..a0d51f1 100644 --- a/ogn/collect/logbook.py +++ b/ogn/collect/logbook.py @@ -1,6 +1,6 @@ from __future__ import absolute_import -from datetime import datetime +from datetime import datetime, timedelta from celery.utils.log import get_task_logger from ogn.collect.celery import app @@ -16,14 +16,24 @@ logger = get_task_logger(__name__) @app.task def compute_takeoff_and_landing(): + logger.info("Compute takeoffs and landings.") + takeoff_speed = 30 landing_speed = 30 - # get last takeoff_landing time as starting point for the following search + # calculate the time where the computation starts last_takeoff_landing_query = app.session.query(func.max(TakeoffLanding.timestamp)) last_takeoff_landing = last_takeoff_landing_query.one()[0] if last_takeoff_landing is None: + # if the table is empty last_takeoff_landing = datetime(2015, 1, 1, 0, 0, 0) + else: + # we get the beacons async. to be safe we delete takeoffs/landings from last 5 minutes and recalculate from then + # alternative: takeoff/landing has a primary key (timestamp,address) + last_takeoff_landing = last_takeoff_landing - timedelta(minutes=5) + app.session.query(TakeoffLanding) \ + .filter(TakeoffLanding.timestamp > last_takeoff_landing) \ + .delete() # make a query with current, previous and next position, so we can detect takeoffs and landings sq = app.session.query( @@ -75,5 +85,9 @@ def compute_takeoff_and_landing(): # ... and save them ins = insert(TakeoffLanding).from_select((TakeoffLanding.address, TakeoffLanding.timestamp, TakeoffLanding.latitude, TakeoffLanding.longitude, TakeoffLanding.track, TakeoffLanding.ground_speed, TakeoffLanding.altitude, TakeoffLanding.is_takeoff), takeoff_landing_query) - app.session.execute(ins) + result = app.session.execute(ins) + counter = result.rowcount app.session.commit() + logger.debug("New/recalculated takeoffs and landings: %s" % counter) + + return counter diff --git a/ogn/commands/logbook.py b/ogn/commands/logbook.py index 116409c..35f079c 100644 --- a/ogn/commands/logbook.py +++ b/ogn/commands/logbook.py @@ -19,7 +19,9 @@ manager = Manager() def compute(): """Compute takeoffs and landings.""" print("Compute takeoffs and landings...") - compute_takeoff_and_landing.delay() + result = compute_takeoff_and_landing.delay() + counter = result.get() + print("New/recalculated takeoffs/landings: %s" % counter) @manager.command