diff --git a/README.md b/README.md index ad5a219..193ce9c 100644 --- a/README.md +++ b/README.md @@ -58,11 +58,12 @@ For best performance you should use [TimescaleDB](https://www.timescale.com), wh 8. Get world elevation data (needed for AGL calculation) Sources: There are many sources for DEM data. It is important that the spatial reference system (SRID) is the same as the database which is 4326. - The [GMTED2010 Viewer](https://topotools.cr.usgs.gov/gmted_viewer/viewer.htm) provides data for the world. Just download the data you need. + The [GMTED2010 Viewer](https://topotools.cr.usgs.gov/gmted_viewer/viewer.htm) provides data for the world with SRID 4326. Just download the data you need. + For Europe we can get the DEM as GeoTIFF files from the [European Environment Agency](https://land.copernicus.eu/imagery-in-situ/eu-dem/eu-dem-v1.1). Because the SRID of these files is 3035 and we want 4326 we have to convert them (next step) -9. Convert the elevation data into correct SRID +9. Optional: Convert the elevation data into correct SRID We convert elevation from one SRID (here: 3035) to target SRID (4326): diff --git a/ogn_python/collect/celery.py b/ogn_python/collect/celery.py index 2a14eb7..516af20 100644 --- a/ogn_python/collect/celery.py +++ b/ogn_python/collect/celery.py @@ -18,12 +18,11 @@ logger = get_task_logger(__name__) @celery.task(name='update_takeoff_landings') -def update_takeoff_landings(): +def update_takeoff_landings(delta): """Compute takeoffs and landings.""" - now = datetime.datetime.now() - yesterday = now - datetime.timedelta(days=1) - takeoff_update_entries(session=db.session, start=yesterday, end=now, logger=logger) + now = datetime.datetime.utcnow() + takeoff_update_entries(session=db.session, start=now-delta, end=now, logger=logger) @celery.task(name='update_logbook_entries') @@ -53,3 +52,18 @@ def update_receivers_country_code(): """Update country code in receivers table if None.""" receivers_update_country_code(session=db.session, logger=logger) + + +@celery.task(name='purge_old_data') +def purge_old_data(age): + """Delete AircraftBeacons and ReceiverBeacons older than given 'age'.""" + + from ogn_python.model import AircraftBeacon, ReceiverBeacon + now = datetime.datetime.utcnow() + db.session(AircraftBeacon) \ + .filter(AircraftBeacon.timestamp < now - age) \ + .delete() + + db.session(ReceiverBeacon) \ + .filter(ReceiverBeacon.timestamp < now - age) \ + .delete() diff --git a/ogn_python/config/default.py b/ogn_python/config/default.py index facf942..150d624 100644 --- a/ogn_python/config/default.py +++ b/ogn_python/config/default.py @@ -11,7 +11,7 @@ from datetime import timedelta CELERYBEAT_SCHEDULE = { 'update-ddb': { 'task': 'import_ddb', - 'schedule': timedelta(minutes=1), + 'schedule': timedelta(hours=1), }, 'update-country-codes': { 'task': 'update_receivers_country_code', @@ -20,6 +20,7 @@ CELERYBEAT_SCHEDULE = { 'update-takeoff-and-landing': { 'task': 'update_takeoff_landings', 'schedule': timedelta(minutes=1), + 'kwargs': {'delta': timedelta(minutes=10)} }, 'update-logbook': { 'task': 'update_logbook_entries', @@ -29,4 +30,9 @@ CELERYBEAT_SCHEDULE = { 'task': 'update_logbook_max_altitude', 'schedule': timedelta(minutes=1), }, + #'purge_old_data': { + # 'task': 'purge_old_data', + # 'schedule': timedelta(minutes=10), + # 'kwargs': {'age': timedelta(days=2)} + #}, }