diff --git a/ogn_python/collect/celery.py b/ogn_python/collect/celery.py index d940240..2e5928a 100644 --- a/ogn_python/collect/celery.py +++ b/ogn_python/collect/celery.py @@ -10,6 +10,8 @@ from ogn_python.collect.logbook import update_max_altitudes as logbook_update_ma from ogn_python.collect.database import import_ddb as device_infos_import_ddb from ogn_python.collect.database import update_country_code as receivers_update_country_code +from ogn_python.collect.stats import create_device_stats, update_device_stats_jumps, create_receiver_stats, create_relation_stats, update_qualities + from ogn_python import db from ogn_python import celery @@ -69,4 +71,17 @@ def purge_old_data(max_hours): .filter(ReceiverBeacon.timestamp < min_timestamp) \ .delete() - db.session.commit() \ No newline at end of file + db.session.commit() + + +@celery.task(name='update_stats') +def update_stats(day_offset): + """Update stats of the current day.""" + + date = datetime.datetime.today() + datetime.timedelta(days=day_offset) + + create_device_stats(session=db.session, date=date) + update_device_stats_jumps(session=db.session, date=date) + create_receiver_stats(session=db.session, date=date) + create_relation_stats(session=db.session, date=date) + update_qualities(session=db.session, date=date) \ No newline at end of file diff --git a/ogn_python/config/default.py b/ogn_python/config/default.py index a7cc024..b991790 100644 --- a/ogn_python/config/default.py +++ b/ogn_python/config/default.py @@ -5,7 +5,7 @@ SQLALCHEMY_TRACK_MODIFICATIONS = False CELERY_BROKER_URL = 'redis://localhost:6379/0' CELERY_RESULT_BACKEND = 'redis://localhost:6379/0' - +from celery.schedules import crontab from datetime import timedelta CELERYBEAT_SCHEDULE = { @@ -30,6 +30,16 @@ CELERYBEAT_SCHEDULE = { 'task': 'update_logbook_max_altitude', 'schedule': timedelta(minutes=1), }, + 'update-stats-hourly': { + 'task': 'update_stats', + 'schedule': timedelta(hours=1), + 'kwargs': {'day_offset': 0}, + }, + 'update-stats-daily': { + 'task': 'update_stats', + 'schedule': crontab(hour=0, minute=5), + 'kwargs': {'day_offset': -1}, + }, #'purge_old_data': { # 'task': 'purge_old_data', # 'schedule': timedelta(minutes=10), diff --git a/ogn_python/templates/airport_detail.html b/ogn_python/templates/airport_detail.html index 7088b42..5ccf638 100644 --- a/ogn_python/templates/airport_detail.html +++ b/ogn_python/templates/airport_detail.html @@ -2,6 +2,8 @@ {% block content %} + +
diff --git a/ogn_python/templates/logbook.html b/ogn_python/templates/logbook.html index 9908690..c844e49 100644 --- a/ogn_python/templates/logbook.html +++ b/ogn_python/templates/logbook.html @@ -47,7 +47,7 @@ {{ loop.index }} {% if entry.device.info is none %}{{ entry.device.address }}{% else %}{{ entry.device.info.registration }}{% endif %} - {% if entry.device.info is none %}(?){% else %}{{ entry.device.info.aircraft }}{% endif %} + {% if entry.device.info is none %}-{% else %}{{ entry.device.info.aircraft }}{% endif %} {% if entry.takeoff_timestamp is not none and entry.takeoff_airport.id|string() == sel_airport %} {{ entry.takeoff_timestamp.strftime('%H:%M') }} {% endif %} {% if entry.takeoff_track is not none and entry.takeoff_airport.id|string() == sel_airport %} {{ '%02d' | format(entry.takeoff_track/10) }} {% endif %} {% if entry.landing_timestamp is not none and entry.landing_airport.id|string() == sel_airport %} {{ entry.landing_timestamp.strftime('%H:%M') }} {% endif %}