pull/52/head
Konstantin Gründger 2016-06-02 19:53:53 +02:00
rodzic 894cf3183b
commit cb28d56cea
4 zmienionych plików z 61 dodań i 65 usunięć

Wyświetl plik

@ -104,7 +104,7 @@ def compute_takeoff_and_landing():
sq2.c.device_id,
Airport.id) \
.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))
# ... and save them

Wyświetl plik

@ -48,11 +48,11 @@ def update_receivers():
# ... and update altitude, lastseen, version and platform
update_count = app.session.query(Receiver) \
.filter(Receiver.name == receivers_to_update.columns.name) \
.update({"altitude": receivers_to_update.columns.altitude,
"lastseen": receivers_to_update.columns.lastseen,
"version": receivers_to_update.columns.version,
"platform": receivers_to_update.columns.platform})
.filter(Receiver.name == receivers_to_update.columns.name) \
.update({"altitude": receivers_to_update.columns.altitude,
"lastseen": receivers_to_update.columns.lastseen,
"version": receivers_to_update.columns.version,
"platform": receivers_to_update.columns.platform})
# add new receivers
empty_sq = app.session.query(ReceiverBeacon.name,
@ -88,8 +88,8 @@ def update_receivers():
.subquery()
added_count = app.session.query(Receiver) \
.filter(Receiver.name == firstseen_null_query.columns.name) \
.update({'firstseen': firstseen_null_query.columns.firstseen})
.filter(Receiver.name == firstseen_null_query.columns.name) \
.update({'firstseen': firstseen_null_query.columns.firstseen})
# update country code if None
unknown_country_query = app.session.query(Receiver) \

Wyświetl plik

@ -49,60 +49,59 @@ def show(airport_name, utc_delta_hours=0, date=None):
sq = session.query(
TakeoffLanding.device_id,
func.lag(TakeoffLanding.device_id)
.over(
order_by=and_(func.date(TakeoffLanding.timestamp+utc_timedelta),
TakeoffLanding.device_id,
TakeoffLanding.timestamp+utc_timedelta))
.over(order_by=and_(func.date(TakeoffLanding.timestamp + utc_timedelta),
TakeoffLanding.device_id,
TakeoffLanding.timestamp + utc_timedelta))
.label('device_id_prev'),
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.timestamp+utc_timedelta))
TakeoffLanding.timestamp + utc_timedelta))
.label('device_id_next'),
(TakeoffLanding.timestamp+utc_timedelta).label('timestamp'),
(TakeoffLanding.timestamp + utc_timedelta).label('timestamp'),
func.lag(TakeoffLanding.timestamp)
.over(order_by=and_(func.date(TakeoffLanding.timestamp+utc_timedelta),
TakeoffLanding.device_id,
TakeoffLanding.timestamp+utc_timedelta))
.label('timestamp_prev'),
func.lead(TakeoffLanding.timestamp+utc_timedelta)
.over(order_by=and_(func.date(TakeoffLanding.timestamp+utc_timedelta),
TakeoffLanding.device_id,
TakeoffLanding.timestamp+utc_timedelta))
.label('timestamp_next'),
.over(order_by=and_(func.date(TakeoffLanding.timestamp + utc_timedelta),
TakeoffLanding.device_id,
TakeoffLanding.timestamp + utc_timedelta))
.label('timestamp_prev'),
func.lead(TakeoffLanding.timestamp + utc_timedelta)
.over(order_by=and_(func.date(TakeoffLanding.timestamp + utc_timedelta),
TakeoffLanding.device_id,
TakeoffLanding.timestamp + utc_timedelta))
.label('timestamp_next'),
TakeoffLanding.track,
func.lag(TakeoffLanding.track)
.over(order_by=and_(func.date(TakeoffLanding.timestamp+utc_timedelta),
TakeoffLanding.device_id,
TakeoffLanding.timestamp+utc_timedelta))
.label('track_prev'),
.over(order_by=and_(func.date(TakeoffLanding.timestamp + utc_timedelta),
TakeoffLanding.device_id,
TakeoffLanding.timestamp + utc_timedelta))
.label('track_prev'),
func.lead(TakeoffLanding.track)
.over(order_by=and_(func.date(TakeoffLanding.timestamp+utc_timedelta),
TakeoffLanding.device_id,
TakeoffLanding.timestamp+utc_timedelta))
.label('track_next'),
.over(order_by=and_(func.date(TakeoffLanding.timestamp + utc_timedelta),
TakeoffLanding.device_id,
TakeoffLanding.timestamp + utc_timedelta))
.label('track_next'),
TakeoffLanding.is_takeoff,
func.lag(TakeoffLanding.is_takeoff)
.over(order_by=and_(func.date(TakeoffLanding.timestamp+utc_timedelta),
TakeoffLanding.device_id,
TakeoffLanding.timestamp+utc_timedelta))
.label('is_takeoff_prev'),
.over(order_by=and_(func.date(TakeoffLanding.timestamp + utc_timedelta),
TakeoffLanding.device_id,
TakeoffLanding.timestamp + utc_timedelta))
.label('is_takeoff_prev'),
func.lead(TakeoffLanding.is_takeoff)
.over(order_by=and_(func.date(TakeoffLanding.timestamp+utc_timedelta),
TakeoffLanding.device_id,
TakeoffLanding.timestamp+utc_timedelta))
.label('is_takeoff_next'),
.over(order_by=and_(func.date(TakeoffLanding.timestamp + utc_timedelta),
TakeoffLanding.device_id,
TakeoffLanding.timestamp + utc_timedelta))
.label('is_takeoff_next'),
TakeoffLanding.airport_id,
func.lag(TakeoffLanding.airport_id)
.over(order_by=and_(func.date(TakeoffLanding.timestamp+utc_timedelta),
TakeoffLanding.device_id,
TakeoffLanding.timestamp+utc_timedelta))
.label('airport_id_prev'),
.over(order_by=and_(func.date(TakeoffLanding.timestamp + utc_timedelta),
TakeoffLanding.device_id,
TakeoffLanding.timestamp + utc_timedelta))
.label('airport_id_prev'),
func.lead(TakeoffLanding.airport_id)
.over(order_by=and_(func.date(TakeoffLanding.timestamp+utc_timedelta),
TakeoffLanding.device_id,
TakeoffLanding.timestamp+utc_timedelta))
.label('airport_id_next')) \
.over(order_by=and_(func.date(TakeoffLanding.timestamp + utc_timedelta),
TakeoffLanding.device_id,
TakeoffLanding.timestamp + utc_timedelta))
.label('airport_id_next')) \
.filter(*or_args) \
.subquery()
@ -164,26 +163,24 @@ def show(airport_name, utc_delta_hours=0, date=None):
.filter(sq.c.airport_id == airport.id)
# unite all
union_query = complete_flight_query.union(
split_start_query,
split_landing_query,
only_landings_query,
only_starts_query) \
union_query = complete_flight_query.union(split_start_query,
split_landing_query,
only_landings_query,
only_starts_query) \
.subquery()
# get aircraft and airport informations and sort all entries by the reference time
takeoff_airport = aliased(Airport, name='takeoff_airport')
landing_airport = aliased(Airport, name='landing_airport')
logbook_query = session.query(
union_query.c.reftime,
union_query.c.takeoff,
union_query.c.takeoff_track,
takeoff_airport,
union_query.c.landing,
union_query.c.landing_track,
landing_airport,
union_query.c.duration,
Device) \
logbook_query = session.query(union_query.c.reftime,
union_query.c.takeoff,
union_query.c.takeoff_track,
takeoff_airport,
union_query.c.landing,
union_query.c.landing_track,
landing_airport,
union_query.c.duration,
Device) \
.outerjoin(Device, union_query.c.device_id == Device.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) \

Wyświetl plik

@ -1,6 +1,5 @@
from sqlalchemy import Boolean, Column, Float, Integer, DateTime, ForeignKey
from sqlalchemy.orm import relationship
from geoalchemy2.types import Geometry
from geoalchemy2.shape import to_shape
from .base import Base
@ -32,4 +31,4 @@ class TakeoffLanding(Base):
return None
coords = to_shape(self.location_wkt)
return Location(lat=coords.y, lon=coords.x)
return Location(lat=coords.y, lon=coords.x)