kopia lustrzana https://github.com/glidernet/ogn-python
rodzic
84cb2d264f
commit
f812b0af4d
|
@ -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))
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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).\
|
||||
|
|
Ładowanie…
Reference in New Issue