Merge pull request #10 from Meisterschueler/master

Fixed Logbook
pull/12/merge
Meisterschueler 2015-11-25 20:25:33 +01:00
commit 6a84c0f9de
6 zmienionych plików z 33 dodań i 8 usunięć

Wyświetl plik

@ -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'

Wyświetl plik

@ -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()

Wyświetl plik

@ -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

Wyświetl plik

@ -9,11 +9,21 @@ 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...")
result = compute_takeoff_and_landing.delay()
counter = result.get()
print("New/recalculated takeoffs/landings: %s" % counter)
@manager.command
def show(airport_name, latitude, longitude, altitude):
"""Show a logbook for <airport_name> located at given position."""

Wyświetl plik

@ -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:

Wyświetl plik

@ -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