diff --git a/ogn/collect/database.py b/ogn/collect/database.py index 4697fe5..c62fc2b 100644 --- a/ogn/collect/database.py +++ b/ogn/collect/database.py @@ -34,5 +34,6 @@ def import_file(path='tests/custom_ddb.txt'): """Import registered devices from a local file.""" logger.info("Import registered devices from '{}'...".format(path)) - counter = update_devices(app.session, AddressOrigin.user_defined, get_ddb(path)) + counter = update_devices(app.session, AddressOrigin.user_defined, + get_ddb(path)) logger.info("Imported {} devices.".format(counter)) diff --git a/ogn/collect/logbook.py b/ogn/collect/logbook.py index 99b5889..4595e97 100644 --- a/ogn/collect/logbook.py +++ b/ogn/collect/logbook.py @@ -41,6 +41,12 @@ def compute_takeoff_and_landing(): AircraftBeacon.timestamp, func.lag(AircraftBeacon.timestamp).over(order_by=and_(AircraftBeacon.address, AircraftBeacon.timestamp)).label('timestamp_prev'), func.lead(AircraftBeacon.timestamp).over(order_by=and_(AircraftBeacon.address, AircraftBeacon.timestamp)).label('timestamp_next'), + AircraftBeacon.name, + func.lag(AircraftBeacon.name).over(order_by=and_(AircraftBeacon.address, AircraftBeacon.timestamp)).label('name_prev'), + func.lead(AircraftBeacon.name).over(order_by=and_(AircraftBeacon.address, AircraftBeacon.timestamp)).label('name_next'), + AircraftBeacon.receiver_name, + func.lag(AircraftBeacon.receiver_name).over(order_by=and_(AircraftBeacon.address, AircraftBeacon.timestamp)).label('receiver_name_prev'), + func.lead(AircraftBeacon.receiver_name).over(order_by=and_(AircraftBeacon.address, AircraftBeacon.timestamp)).label('receiver_name_next'), AircraftBeacon.location_wkt, func.lag(AircraftBeacon.location_wkt).over(order_by=and_(AircraftBeacon.address, AircraftBeacon.timestamp)).label('location_wkt_prev'), func.lead(AircraftBeacon.location_wkt).over(order_by=and_(AircraftBeacon.address, AircraftBeacon.timestamp)).label('location_wkt_next'), @@ -60,6 +66,8 @@ def compute_takeoff_and_landing(): # find takeoffs and landings (look at the trigger_speed) takeoff_landing_query = app.session.query( sq.c.address, + sq.c.name, + sq.c.receiver_name, sq.c.timestamp, sq.c.location, sq.c.track, @@ -76,8 +84,8 @@ def compute_takeoff_and_landing(): sq.c.ground_speed_next < landing_speed))) \ .order_by(func.date(sq.c.timestamp), sq.c.timestamp) - # ... and save them - ins = insert(TakeoffLanding).from_select((TakeoffLanding.address, TakeoffLanding.timestamp, TakeoffLanding.location_wkt, TakeoffLanding.track, TakeoffLanding.ground_speed, TakeoffLanding.altitude, TakeoffLanding.is_takeoff), takeoff_landing_query) + # ... and save the + ins = insert(TakeoffLanding).from_select((TakeoffLanding.address, TakeoffLanding.name, TakeoffLanding.receiver_name, TakeoffLanding.timestamp, TakeoffLanding.location_wkt, TakeoffLanding.track, TakeoffLanding.ground_speed, TakeoffLanding.altitude, TakeoffLanding.is_takeoff), takeoff_landing_query) result = app.session.execute(ins) counter = result.rowcount app.session.commit() diff --git a/ogn/commands/logbook.py b/ogn/commands/logbook.py index 18847d5..720574e 100644 --- a/ogn/commands/logbook.py +++ b/ogn/commands/logbook.py @@ -36,7 +36,7 @@ def show(airport_name): return delta_altitude = 200 - delta_radius = 10 + delta_radius = 0.01 # degree! # make a query with current, previous and next "takeoff_landing" event, so we can find complete flights sq = session.query( @@ -87,6 +87,7 @@ def show(airport_name): .label('is_takeoff_next')) \ .filter(func.ST_DFullyWithin(TakeoffLanding.location_wkt, Airport.location_wkt, delta_radius)) \ .filter(TakeoffLanding.altitude < Airport.altitude + delta_altitude) \ + .filter(Airport.name == airport.name) \ .subquery() # find complete flights (with takeoff and landing) with duration < 1 day diff --git a/ogn/commands/showreceiver.py b/ogn/commands/showreceiver.py index 1d8c374..9a30512 100644 --- a/ogn/commands/showreceiver.py +++ b/ogn/commands/showreceiver.py @@ -18,8 +18,9 @@ def list_all(): sq = session.query(distinct(ReceiverBeacon.name).label('name'), func.max(ReceiverBeacon.timestamp).label('lastseen'), - func.count(ReceiverBeacon.name).label('messages_count') - ).filter(ReceiverBeacon.timestamp > timestamp_24h_ago).group_by(ReceiverBeacon.name).subquery() + func.count(ReceiverBeacon.name).label('messages_count')) \ + .filter(ReceiverBeacon.timestamp > timestamp_24h_ago) \ + .group_by(ReceiverBeacon.name).subquery() query = session.query(Receiver, sq.c.messages_count).\ filter(Receiver.name == sq.c.name).\