kopia lustrzana https://github.com/glidernet/ogn-python
Flake8 fixes
rodzic
894cf3183b
commit
cb28d56cea
|
@ -104,7 +104,7 @@ def compute_takeoff_and_landing():
|
||||||
sq2.c.device_id,
|
sq2.c.device_id,
|
||||||
Airport.id) \
|
Airport.id) \
|
||||||
.filter(and_(func.ST_DFullyWithin(sq2.c.location, Airport.location_wkt, airport_radius),
|
.filter(and_(func.ST_DFullyWithin(sq2.c.location, Airport.location_wkt, airport_radius),
|
||||||
between(sq2.c.altitude, Airport.altitude-airport_delta, Airport.altitude+airport_delta))) \
|
between(sq2.c.altitude, Airport.altitude - airport_delta, Airport.altitude + airport_delta))) \
|
||||||
.filter(between(Airport.style, 2, 5))
|
.filter(between(Airport.style, 2, 5))
|
||||||
|
|
||||||
# ... and save them
|
# ... and save them
|
||||||
|
|
|
@ -48,11 +48,11 @@ def update_receivers():
|
||||||
|
|
||||||
# ... and update altitude, lastseen, version and platform
|
# ... and update altitude, lastseen, version and platform
|
||||||
update_count = app.session.query(Receiver) \
|
update_count = app.session.query(Receiver) \
|
||||||
.filter(Receiver.name == receivers_to_update.columns.name) \
|
.filter(Receiver.name == receivers_to_update.columns.name) \
|
||||||
.update({"altitude": receivers_to_update.columns.altitude,
|
.update({"altitude": receivers_to_update.columns.altitude,
|
||||||
"lastseen": receivers_to_update.columns.lastseen,
|
"lastseen": receivers_to_update.columns.lastseen,
|
||||||
"version": receivers_to_update.columns.version,
|
"version": receivers_to_update.columns.version,
|
||||||
"platform": receivers_to_update.columns.platform})
|
"platform": receivers_to_update.columns.platform})
|
||||||
|
|
||||||
# add new receivers
|
# add new receivers
|
||||||
empty_sq = app.session.query(ReceiverBeacon.name,
|
empty_sq = app.session.query(ReceiverBeacon.name,
|
||||||
|
@ -88,8 +88,8 @@ def update_receivers():
|
||||||
.subquery()
|
.subquery()
|
||||||
|
|
||||||
added_count = app.session.query(Receiver) \
|
added_count = app.session.query(Receiver) \
|
||||||
.filter(Receiver.name == firstseen_null_query.columns.name) \
|
.filter(Receiver.name == firstseen_null_query.columns.name) \
|
||||||
.update({'firstseen': firstseen_null_query.columns.firstseen})
|
.update({'firstseen': firstseen_null_query.columns.firstseen})
|
||||||
|
|
||||||
# update country code if None
|
# update country code if None
|
||||||
unknown_country_query = app.session.query(Receiver) \
|
unknown_country_query = app.session.query(Receiver) \
|
||||||
|
|
|
@ -49,60 +49,59 @@ def show(airport_name, utc_delta_hours=0, date=None):
|
||||||
sq = session.query(
|
sq = session.query(
|
||||||
TakeoffLanding.device_id,
|
TakeoffLanding.device_id,
|
||||||
func.lag(TakeoffLanding.device_id)
|
func.lag(TakeoffLanding.device_id)
|
||||||
.over(
|
.over(order_by=and_(func.date(TakeoffLanding.timestamp + utc_timedelta),
|
||||||
order_by=and_(func.date(TakeoffLanding.timestamp+utc_timedelta),
|
TakeoffLanding.device_id,
|
||||||
TakeoffLanding.device_id,
|
TakeoffLanding.timestamp + utc_timedelta))
|
||||||
TakeoffLanding.timestamp+utc_timedelta))
|
|
||||||
.label('device_id_prev'),
|
.label('device_id_prev'),
|
||||||
func.lead(TakeoffLanding.device_id)
|
func.lead(TakeoffLanding.device_id)
|
||||||
.over(order_by=and_(func.date(TakeoffLanding.timestamp+utc_timedelta),
|
.over(order_by=and_(func.date(TakeoffLanding.timestamp + utc_timedelta),
|
||||||
TakeoffLanding.device_id,
|
TakeoffLanding.device_id,
|
||||||
TakeoffLanding.timestamp+utc_timedelta))
|
TakeoffLanding.timestamp + utc_timedelta))
|
||||||
.label('device_id_next'),
|
.label('device_id_next'),
|
||||||
(TakeoffLanding.timestamp+utc_timedelta).label('timestamp'),
|
(TakeoffLanding.timestamp + utc_timedelta).label('timestamp'),
|
||||||
func.lag(TakeoffLanding.timestamp)
|
func.lag(TakeoffLanding.timestamp)
|
||||||
.over(order_by=and_(func.date(TakeoffLanding.timestamp+utc_timedelta),
|
.over(order_by=and_(func.date(TakeoffLanding.timestamp + utc_timedelta),
|
||||||
TakeoffLanding.device_id,
|
TakeoffLanding.device_id,
|
||||||
TakeoffLanding.timestamp+utc_timedelta))
|
TakeoffLanding.timestamp + utc_timedelta))
|
||||||
.label('timestamp_prev'),
|
.label('timestamp_prev'),
|
||||||
func.lead(TakeoffLanding.timestamp+utc_timedelta)
|
func.lead(TakeoffLanding.timestamp + utc_timedelta)
|
||||||
.over(order_by=and_(func.date(TakeoffLanding.timestamp+utc_timedelta),
|
.over(order_by=and_(func.date(TakeoffLanding.timestamp + utc_timedelta),
|
||||||
TakeoffLanding.device_id,
|
TakeoffLanding.device_id,
|
||||||
TakeoffLanding.timestamp+utc_timedelta))
|
TakeoffLanding.timestamp + utc_timedelta))
|
||||||
.label('timestamp_next'),
|
.label('timestamp_next'),
|
||||||
TakeoffLanding.track,
|
TakeoffLanding.track,
|
||||||
func.lag(TakeoffLanding.track)
|
func.lag(TakeoffLanding.track)
|
||||||
.over(order_by=and_(func.date(TakeoffLanding.timestamp+utc_timedelta),
|
.over(order_by=and_(func.date(TakeoffLanding.timestamp + utc_timedelta),
|
||||||
TakeoffLanding.device_id,
|
TakeoffLanding.device_id,
|
||||||
TakeoffLanding.timestamp+utc_timedelta))
|
TakeoffLanding.timestamp + utc_timedelta))
|
||||||
.label('track_prev'),
|
.label('track_prev'),
|
||||||
func.lead(TakeoffLanding.track)
|
func.lead(TakeoffLanding.track)
|
||||||
.over(order_by=and_(func.date(TakeoffLanding.timestamp+utc_timedelta),
|
.over(order_by=and_(func.date(TakeoffLanding.timestamp + utc_timedelta),
|
||||||
TakeoffLanding.device_id,
|
TakeoffLanding.device_id,
|
||||||
TakeoffLanding.timestamp+utc_timedelta))
|
TakeoffLanding.timestamp + utc_timedelta))
|
||||||
.label('track_next'),
|
.label('track_next'),
|
||||||
TakeoffLanding.is_takeoff,
|
TakeoffLanding.is_takeoff,
|
||||||
func.lag(TakeoffLanding.is_takeoff)
|
func.lag(TakeoffLanding.is_takeoff)
|
||||||
.over(order_by=and_(func.date(TakeoffLanding.timestamp+utc_timedelta),
|
.over(order_by=and_(func.date(TakeoffLanding.timestamp + utc_timedelta),
|
||||||
TakeoffLanding.device_id,
|
TakeoffLanding.device_id,
|
||||||
TakeoffLanding.timestamp+utc_timedelta))
|
TakeoffLanding.timestamp + utc_timedelta))
|
||||||
.label('is_takeoff_prev'),
|
.label('is_takeoff_prev'),
|
||||||
func.lead(TakeoffLanding.is_takeoff)
|
func.lead(TakeoffLanding.is_takeoff)
|
||||||
.over(order_by=and_(func.date(TakeoffLanding.timestamp+utc_timedelta),
|
.over(order_by=and_(func.date(TakeoffLanding.timestamp + utc_timedelta),
|
||||||
TakeoffLanding.device_id,
|
TakeoffLanding.device_id,
|
||||||
TakeoffLanding.timestamp+utc_timedelta))
|
TakeoffLanding.timestamp + utc_timedelta))
|
||||||
.label('is_takeoff_next'),
|
.label('is_takeoff_next'),
|
||||||
TakeoffLanding.airport_id,
|
TakeoffLanding.airport_id,
|
||||||
func.lag(TakeoffLanding.airport_id)
|
func.lag(TakeoffLanding.airport_id)
|
||||||
.over(order_by=and_(func.date(TakeoffLanding.timestamp+utc_timedelta),
|
.over(order_by=and_(func.date(TakeoffLanding.timestamp + utc_timedelta),
|
||||||
TakeoffLanding.device_id,
|
TakeoffLanding.device_id,
|
||||||
TakeoffLanding.timestamp+utc_timedelta))
|
TakeoffLanding.timestamp + utc_timedelta))
|
||||||
.label('airport_id_prev'),
|
.label('airport_id_prev'),
|
||||||
func.lead(TakeoffLanding.airport_id)
|
func.lead(TakeoffLanding.airport_id)
|
||||||
.over(order_by=and_(func.date(TakeoffLanding.timestamp+utc_timedelta),
|
.over(order_by=and_(func.date(TakeoffLanding.timestamp + utc_timedelta),
|
||||||
TakeoffLanding.device_id,
|
TakeoffLanding.device_id,
|
||||||
TakeoffLanding.timestamp+utc_timedelta))
|
TakeoffLanding.timestamp + utc_timedelta))
|
||||||
.label('airport_id_next')) \
|
.label('airport_id_next')) \
|
||||||
.filter(*or_args) \
|
.filter(*or_args) \
|
||||||
.subquery()
|
.subquery()
|
||||||
|
|
||||||
|
@ -164,26 +163,24 @@ def show(airport_name, utc_delta_hours=0, date=None):
|
||||||
.filter(sq.c.airport_id == airport.id)
|
.filter(sq.c.airport_id == airport.id)
|
||||||
|
|
||||||
# unite all
|
# unite all
|
||||||
union_query = complete_flight_query.union(
|
union_query = complete_flight_query.union(split_start_query,
|
||||||
split_start_query,
|
split_landing_query,
|
||||||
split_landing_query,
|
only_landings_query,
|
||||||
only_landings_query,
|
only_starts_query) \
|
||||||
only_starts_query) \
|
|
||||||
.subquery()
|
.subquery()
|
||||||
|
|
||||||
# get aircraft and airport informations and sort all entries by the reference time
|
# get aircraft and airport informations and sort all entries by the reference time
|
||||||
takeoff_airport = aliased(Airport, name='takeoff_airport')
|
takeoff_airport = aliased(Airport, name='takeoff_airport')
|
||||||
landing_airport = aliased(Airport, name='landing_airport')
|
landing_airport = aliased(Airport, name='landing_airport')
|
||||||
logbook_query = session.query(
|
logbook_query = session.query(union_query.c.reftime,
|
||||||
union_query.c.reftime,
|
union_query.c.takeoff,
|
||||||
union_query.c.takeoff,
|
union_query.c.takeoff_track,
|
||||||
union_query.c.takeoff_track,
|
takeoff_airport,
|
||||||
takeoff_airport,
|
union_query.c.landing,
|
||||||
union_query.c.landing,
|
union_query.c.landing_track,
|
||||||
union_query.c.landing_track,
|
landing_airport,
|
||||||
landing_airport,
|
union_query.c.duration,
|
||||||
union_query.c.duration,
|
Device) \
|
||||||
Device) \
|
|
||||||
.outerjoin(Device, union_query.c.device_id == Device.id) \
|
.outerjoin(Device, union_query.c.device_id == Device.id) \
|
||||||
.outerjoin(takeoff_airport, union_query.c.takeoff_airport_id == takeoff_airport.id) \
|
.outerjoin(takeoff_airport, union_query.c.takeoff_airport_id == takeoff_airport.id) \
|
||||||
.outerjoin(landing_airport, union_query.c.landing_airport_id == landing_airport.id) \
|
.outerjoin(landing_airport, union_query.c.landing_airport_id == landing_airport.id) \
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
from sqlalchemy import Boolean, Column, Float, Integer, DateTime, ForeignKey
|
from sqlalchemy import Boolean, Column, Float, Integer, DateTime, ForeignKey
|
||||||
from sqlalchemy.orm import relationship
|
from sqlalchemy.orm import relationship
|
||||||
from geoalchemy2.types import Geometry
|
|
||||||
from geoalchemy2.shape import to_shape
|
from geoalchemy2.shape import to_shape
|
||||||
|
|
||||||
from .base import Base
|
from .base import Base
|
||||||
|
@ -32,4 +31,4 @@ class TakeoffLanding(Base):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
coords = to_shape(self.location_wkt)
|
coords = to_shape(self.location_wkt)
|
||||||
return Location(lat=coords.y, lon=coords.x)
|
return Location(lat=coords.y, lon=coords.x)
|
||||||
|
|
Ładowanie…
Reference in New Issue