kopia lustrzana https://github.com/glidernet/ogn-python
Change takeoff calculation range from date to (start,end)
rodzic
7e3c9a5cb0
commit
7c416b601a
|
@ -21,8 +21,9 @@ logger = get_task_logger(__name__)
|
||||||
def update_takeoff_landings():
|
def update_takeoff_landings():
|
||||||
"""Compute takeoffs and landings."""
|
"""Compute takeoffs and landings."""
|
||||||
|
|
||||||
today = datetime.datetime.today()
|
now = datetime.datetime.now()
|
||||||
takeoff_update_entries(session=db.session, date=today, logger=logger)
|
yesterday = now - datetime.timedelta(days=1)
|
||||||
|
takeoff_update_entries(session=db.session, start=yesterday, end=now, logger=logger)
|
||||||
|
|
||||||
|
|
||||||
@celery.task(name='update_logbook_entries')
|
@celery.task(name='update_logbook_entries')
|
||||||
|
|
|
@ -10,7 +10,7 @@ from ogn_python.utils import date_to_timestamps
|
||||||
from ogn_python import app
|
from ogn_python import app
|
||||||
|
|
||||||
|
|
||||||
def update_entries(session, date, logger=None):
|
def update_entries(session, start, end, logger=None):
|
||||||
"""Compute takeoffs and landings."""
|
"""Compute takeoffs and landings."""
|
||||||
|
|
||||||
if logger is None:
|
if logger is None:
|
||||||
|
@ -18,10 +18,14 @@ def update_entries(session, date, logger=None):
|
||||||
|
|
||||||
logger.info("Compute takeoffs and landings.")
|
logger.info("Compute takeoffs and landings.")
|
||||||
|
|
||||||
|
# considered time interval should not exceed a complete day
|
||||||
|
if end - start > timedelta(days=1):
|
||||||
|
logger.warn("timeinterval start='{}' and end='{}' is too big.".format(start, end))
|
||||||
|
|
||||||
# check if we have any airport
|
# check if we have any airport
|
||||||
airports_query = session.query(Airport).limit(1)
|
airports_query = session.query(Airport).limit(1)
|
||||||
if not airports_query.all():
|
if not airports_query.all():
|
||||||
app.logger.warn("Cannot calculate takeoff and landings without any airport! Please import airports first.")
|
logger.warn("Cannot calculate takeoff and landings without any airport! Please import airports first.")
|
||||||
return
|
return
|
||||||
|
|
||||||
# takeoff / landing detection is based on 3 consecutive points all below a certain altitude AGL
|
# takeoff / landing detection is based on 3 consecutive points all below a certain altitude AGL
|
||||||
|
@ -32,11 +36,7 @@ def update_entries(session, date, logger=None):
|
||||||
max_agl = 100 # takeoff / landing must not exceed this altitude AGL
|
max_agl = 100 # takeoff / landing must not exceed this altitude AGL
|
||||||
|
|
||||||
# limit time range to given date
|
# limit time range to given date
|
||||||
if date is not None:
|
filters = [between(AircraftBeacon.timestamp, start, end)]
|
||||||
(start, end) = date_to_timestamps(date)
|
|
||||||
filters = [between(AircraftBeacon.timestamp, start, end)]
|
|
||||||
else:
|
|
||||||
filters = []
|
|
||||||
|
|
||||||
# get beacons for selected day, one per device_id and timestamp
|
# get beacons for selected day, one per device_id and timestamp
|
||||||
sq = session.query(AircraftBeacon) \
|
sq = session.query(AircraftBeacon) \
|
||||||
|
|
|
@ -28,7 +28,8 @@ def compute_takeoff_landing(start, end):
|
||||||
pbar = tqdm(days)
|
pbar = tqdm(days)
|
||||||
for single_date in pbar:
|
for single_date in pbar:
|
||||||
pbar.set_description(datetime.strftime(single_date, '%Y-%m-%d'))
|
pbar.set_description(datetime.strftime(single_date, '%Y-%m-%d'))
|
||||||
result = takeoff_landings_update_entries(session=db.session, date=single_date)
|
(start, end) = date_to_timestamps(single_date)
|
||||||
|
result = takeoff_landings_update_entries(session=db.session, start=start, end=end)
|
||||||
|
|
||||||
|
|
||||||
@user_cli.command('compute_logbook')
|
@user_cli.command('compute_logbook')
|
||||||
|
|
Ładowanie…
Reference in New Issue