Use utc_timedelta only for splitting of takeoff and landing

pull/56/head
Konstantin Gründger 2016-06-28 20:00:24 +02:00
rodzic 76b5827778
commit 998cbf4990
1 zmienionych plików z 25 dodań i 25 usunięć

Wyświetl plik

@ -49,58 +49,58 @@ 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(order_by=and_(func.date(TakeoffLanding.timestamp + utc_timedelta), .over(order_by=and_(func.date(TakeoffLanding.timestamp),
TakeoffLanding.device_id, TakeoffLanding.device_id,
TakeoffLanding.timestamp + utc_timedelta)) TakeoffLanding.timestamp))
.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),
TakeoffLanding.device_id, TakeoffLanding.device_id,
TakeoffLanding.timestamp + utc_timedelta)) TakeoffLanding.timestamp))
.label('device_id_next'), .label('device_id_next'),
(TakeoffLanding.timestamp + utc_timedelta).label('timestamp'), (TakeoffLanding.timestamp).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),
TakeoffLanding.device_id, TakeoffLanding.device_id,
TakeoffLanding.timestamp + utc_timedelta)) TakeoffLanding.timestamp))
.label('timestamp_prev'), .label('timestamp_prev'),
func.lead(TakeoffLanding.timestamp + utc_timedelta) func.lead(TakeoffLanding.timestamp)
.over(order_by=and_(func.date(TakeoffLanding.timestamp + utc_timedelta), .over(order_by=and_(func.date(TakeoffLanding.timestamp),
TakeoffLanding.device_id, TakeoffLanding.device_id,
TakeoffLanding.timestamp + utc_timedelta)) TakeoffLanding.timestamp))
.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),
TakeoffLanding.device_id, TakeoffLanding.device_id,
TakeoffLanding.timestamp + utc_timedelta)) TakeoffLanding.timestamp))
.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),
TakeoffLanding.device_id, TakeoffLanding.device_id,
TakeoffLanding.timestamp + utc_timedelta)) TakeoffLanding.timestamp))
.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),
TakeoffLanding.device_id, TakeoffLanding.device_id,
TakeoffLanding.timestamp + utc_timedelta)) TakeoffLanding.timestamp))
.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),
TakeoffLanding.device_id, TakeoffLanding.device_id,
TakeoffLanding.timestamp + utc_timedelta)) TakeoffLanding.timestamp))
.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),
TakeoffLanding.device_id, TakeoffLanding.device_id,
TakeoffLanding.timestamp + utc_timedelta)) TakeoffLanding.timestamp))
.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),
TakeoffLanding.device_id, TakeoffLanding.device_id,
TakeoffLanding.timestamp + utc_timedelta)) TakeoffLanding.timestamp))
.label('airport_id_next')) \ .label('airport_id_next')) \
.filter(*or_args) \ .filter(*or_args) \
.subquery() .subquery()
@ -113,7 +113,7 @@ def show(airport_name, utc_delta_hours=0, date=None):
label('duration', sq.c.timestamp_next - sq.c.timestamp)) \ label('duration', sq.c.timestamp_next - sq.c.timestamp)) \
.filter(and_(sq.c.is_takeoff == true(), sq.c.is_takeoff_next == false())) \ .filter(and_(sq.c.is_takeoff == true(), sq.c.is_takeoff_next == false())) \
.filter(sq.c.device_id == sq.c.device_id_next) \ .filter(sq.c.device_id == sq.c.device_id_next) \
.filter(func.date(sq.c.timestamp_next) == func.date(sq.c.timestamp)) \ .filter(func.date(sq.c.timestamp_next + utc_timedelta) == func.date(sq.c.timestamp + utc_timedelta)) \
.filter(or_(sq.c.airport_id == airport.id, .filter(or_(sq.c.airport_id == airport.id,
sq.c.airport_id_next == airport.id)) sq.c.airport_id_next == airport.id))
@ -125,7 +125,7 @@ def show(airport_name, utc_delta_hours=0, date=None):
null().label('duration')) \ null().label('duration')) \
.filter(and_(sq.c.is_takeoff == true(), sq.c.is_takeoff_next == false())) \ .filter(and_(sq.c.is_takeoff == true(), sq.c.is_takeoff_next == false())) \
.filter(sq.c.device_id == sq.c.device_id_next) \ .filter(sq.c.device_id == sq.c.device_id_next) \
.filter(func.date(sq.c.timestamp_next) != func.date(sq.c.timestamp)) \ .filter(func.date(sq.c.timestamp_next + utc_timedelta) != func.date(sq.c.timestamp + utc_timedelta)) \
.filter(and_(sq.c.airport_id == airport.id, .filter(and_(sq.c.airport_id == airport.id,
sq.c.airport_id_next == airport.id)) sq.c.airport_id_next == airport.id))
@ -136,7 +136,7 @@ def show(airport_name, utc_delta_hours=0, date=None):
null().label('duration')) \ null().label('duration')) \
.filter(and_(sq.c.is_takeoff == true(), sq.c.is_takeoff_next == false())) \ .filter(and_(sq.c.is_takeoff == true(), sq.c.is_takeoff_next == false())) \
.filter(sq.c.device_id == sq.c.device_id_next) \ .filter(sq.c.device_id == sq.c.device_id_next) \
.filter(func.date(sq.c.timestamp_next) != func.date(sq.c.timestamp)) \ .filter(func.date(sq.c.timestamp_next + utc_timedelta) != func.date(sq.c.timestamp + utc_timedelta)) \
.filter(and_(sq.c.airport_id == airport.id, .filter(and_(sq.c.airport_id == airport.id,
sq.c.airport_id_next == airport.id)) sq.c.airport_id_next == airport.id))