kopia lustrzana https://github.com/glidernet/ogn-python
Logbook: recalculate last 5 minutes
rodzic
ceca97b47c
commit
82efb81fba
|
@ -36,6 +36,7 @@ def update_ddb_from_file():
|
||||||
.delete()
|
.delete()
|
||||||
|
|
||||||
devices = get_ddb('ogn/custom_ddb.txt')
|
devices = get_ddb('ogn/custom_ddb.txt')
|
||||||
|
logger.debug("New Devices: %s" % str(devices))
|
||||||
|
|
||||||
app.session.bulk_save_objects(devices)
|
app.session.bulk_save_objects(devices)
|
||||||
app.session.commit()
|
app.session.commit()
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
from celery.utils.log import get_task_logger
|
from celery.utils.log import get_task_logger
|
||||||
from ogn.collect.celery import app
|
from ogn.collect.celery import app
|
||||||
|
@ -16,14 +16,24 @@ logger = get_task_logger(__name__)
|
||||||
|
|
||||||
@app.task
|
@app.task
|
||||||
def compute_takeoff_and_landing():
|
def compute_takeoff_and_landing():
|
||||||
|
logger.info("Compute takeoffs and landings.")
|
||||||
|
|
||||||
takeoff_speed = 30
|
takeoff_speed = 30
|
||||||
landing_speed = 30
|
landing_speed = 30
|
||||||
|
|
||||||
# get last takeoff_landing time as starting point for the following search
|
# calculate the time where the computation starts
|
||||||
last_takeoff_landing_query = app.session.query(func.max(TakeoffLanding.timestamp))
|
last_takeoff_landing_query = app.session.query(func.max(TakeoffLanding.timestamp))
|
||||||
last_takeoff_landing = last_takeoff_landing_query.one()[0]
|
last_takeoff_landing = last_takeoff_landing_query.one()[0]
|
||||||
if last_takeoff_landing is None:
|
if last_takeoff_landing is None:
|
||||||
|
# if the table is empty
|
||||||
last_takeoff_landing = datetime(2015, 1, 1, 0, 0, 0)
|
last_takeoff_landing = datetime(2015, 1, 1, 0, 0, 0)
|
||||||
|
else:
|
||||||
|
# we get the beacons async. to be safe we delete takeoffs/landings from last 5 minutes and recalculate from then
|
||||||
|
# alternative: takeoff/landing has a primary key (timestamp,address)
|
||||||
|
last_takeoff_landing = last_takeoff_landing - timedelta(minutes=5)
|
||||||
|
app.session.query(TakeoffLanding) \
|
||||||
|
.filter(TakeoffLanding.timestamp > last_takeoff_landing) \
|
||||||
|
.delete()
|
||||||
|
|
||||||
# make a query with current, previous and next position, so we can detect takeoffs and landings
|
# make a query with current, previous and next position, so we can detect takeoffs and landings
|
||||||
sq = app.session.query(
|
sq = app.session.query(
|
||||||
|
@ -75,5 +85,9 @@ def compute_takeoff_and_landing():
|
||||||
|
|
||||||
# ... and save them
|
# ... and save them
|
||||||
ins = insert(TakeoffLanding).from_select((TakeoffLanding.address, TakeoffLanding.timestamp, TakeoffLanding.latitude, TakeoffLanding.longitude, TakeoffLanding.track, TakeoffLanding.ground_speed, TakeoffLanding.altitude, TakeoffLanding.is_takeoff), takeoff_landing_query)
|
ins = insert(TakeoffLanding).from_select((TakeoffLanding.address, TakeoffLanding.timestamp, TakeoffLanding.latitude, TakeoffLanding.longitude, TakeoffLanding.track, TakeoffLanding.ground_speed, TakeoffLanding.altitude, TakeoffLanding.is_takeoff), takeoff_landing_query)
|
||||||
app.session.execute(ins)
|
result = app.session.execute(ins)
|
||||||
|
counter = result.rowcount
|
||||||
app.session.commit()
|
app.session.commit()
|
||||||
|
logger.debug("New/recalculated takeoffs and landings: %s" % counter)
|
||||||
|
|
||||||
|
return counter
|
||||||
|
|
|
@ -19,7 +19,9 @@ manager = Manager()
|
||||||
def compute():
|
def compute():
|
||||||
"""Compute takeoffs and landings."""
|
"""Compute takeoffs and landings."""
|
||||||
print("Compute takeoffs and landings...")
|
print("Compute takeoffs and landings...")
|
||||||
compute_takeoff_and_landing.delay()
|
result = compute_takeoff_and_landing.delay()
|
||||||
|
counter = result.get()
|
||||||
|
print("New/recalculated takeoffs/landings: %s" % counter)
|
||||||
|
|
||||||
|
|
||||||
@manager.command
|
@manager.command
|
||||||
|
|
Ładowanie…
Reference in New Issue