2019-03-10 14:58:10 +00:00
|
|
|
import datetime
|
2015-11-15 08:23:57 +00:00
|
|
|
|
2019-03-10 14:58:10 +00:00
|
|
|
from celery.utils.log import get_task_logger
|
2015-11-15 08:23:57 +00:00
|
|
|
|
2019-03-10 18:57:44 +00:00
|
|
|
from ogn_python.collect.takeoff_landings import update_entries as takeoff_update_entries
|
2015-11-15 08:23:57 +00:00
|
|
|
|
2019-03-10 14:58:10 +00:00
|
|
|
from ogn_python.collect.logbook import update_entries as logbook_update_entries
|
|
|
|
from ogn_python.collect.logbook import update_max_altitudes as logbook_update_max_altitudes
|
2015-11-15 18:31:58 +00:00
|
|
|
|
2019-03-10 18:57:44 +00:00
|
|
|
from ogn_python.collect.database import import_ddb as device_infos_import_ddb
|
2019-03-10 14:58:10 +00:00
|
|
|
from ogn_python.collect.database import update_country_code as receivers_update_country_code
|
2015-11-15 08:23:57 +00:00
|
|
|
|
2019-03-10 14:58:10 +00:00
|
|
|
from ogn_python import db
|
|
|
|
from ogn_python import celery
|
2015-11-15 08:23:57 +00:00
|
|
|
|
2015-11-15 18:31:58 +00:00
|
|
|
|
2019-03-10 14:58:10 +00:00
|
|
|
logger = get_task_logger(__name__)
|
2015-11-15 08:23:57 +00:00
|
|
|
|
|
|
|
|
2019-03-10 14:58:10 +00:00
|
|
|
@celery.task(name='update_takeoff_landings')
|
2019-03-18 19:41:58 +00:00
|
|
|
def update_takeoff_landings(last_minutes):
|
2019-03-10 14:58:10 +00:00
|
|
|
"""Compute takeoffs and landings."""
|
2016-01-29 01:34:12 +00:00
|
|
|
|
2019-03-18 19:41:58 +00:00
|
|
|
end = datetime.datetime.utcnow()
|
|
|
|
start = end - datetime.timedelta(minutes=last_minutes)
|
|
|
|
takeoff_update_entries(session=db.session, start=start, end=end, logger=logger)
|
2019-03-10 14:58:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
@celery.task(name='update_logbook_entries')
|
|
|
|
def update_logbook_entries():
|
|
|
|
"""Add/update logbook entries."""
|
|
|
|
|
|
|
|
today = datetime.datetime.today()
|
|
|
|
logbook_update_entries(session=db.session, date=today, logger=logger)
|
|
|
|
|
|
|
|
|
|
|
|
@celery.task(name='update_logbook_max_altitude')
|
2019-03-10 18:57:44 +00:00
|
|
|
def update_logbook_max_altitude():
|
2019-03-10 14:58:10 +00:00
|
|
|
"""Add max altitudes in logbook when flight is complete (takeoff and landing)."""
|
|
|
|
|
|
|
|
logbook_update_max_altitudes(session=db.session, logger=logger)
|
|
|
|
|
|
|
|
|
|
|
|
@celery.task(name='import_ddb')
|
|
|
|
def import_ddb():
|
|
|
|
"""Import registered devices from the DDB."""
|
|
|
|
|
2019-03-10 18:57:44 +00:00
|
|
|
device_infos_import_ddb(session=db.session, logger=logger)
|
2019-03-10 14:58:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
@celery.task(name='update_receivers_country_code')
|
|
|
|
def update_receivers_country_code():
|
|
|
|
"""Update country code in receivers table if None."""
|
|
|
|
|
|
|
|
receivers_update_country_code(session=db.session, logger=logger)
|
2019-03-18 07:37:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
@celery.task(name='purge_old_data')
|
2019-03-18 19:41:58 +00:00
|
|
|
def purge_old_data(max_hours):
|
2019-03-18 07:37:19 +00:00
|
|
|
"""Delete AircraftBeacons and ReceiverBeacons older than given 'age'."""
|
|
|
|
|
|
|
|
from ogn_python.model import AircraftBeacon, ReceiverBeacon
|
2019-03-18 19:41:58 +00:00
|
|
|
min_timestamp = datetime.datetime.utcnow() - datetime.timedelta(hours=max_hours)
|
2019-03-18 07:37:19 +00:00
|
|
|
db.session(AircraftBeacon) \
|
2019-03-18 19:41:58 +00:00
|
|
|
.filter(AircraftBeacon.timestamp < min_timestamp) \
|
2019-03-18 07:37:19 +00:00
|
|
|
.delete()
|
|
|
|
|
|
|
|
db.session(ReceiverBeacon) \
|
2019-03-18 19:41:58 +00:00
|
|
|
.filter(ReceiverBeacon.timestamp < min_timestamp) \
|
2019-03-18 07:37:19 +00:00
|
|
|
.delete()
|