kopia lustrzana https://github.com/glidernet/ogn-python
Added stats tasks
rodzic
5fa988a245
commit
b25257f697
|
@ -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 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.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 db
|
||||||
from ogn_python import celery
|
from ogn_python import celery
|
||||||
|
|
||||||
|
@ -70,3 +72,16 @@ def purge_old_data(max_hours):
|
||||||
.delete()
|
.delete()
|
||||||
|
|
||||||
db.session.commit()
|
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)
|
|
@ -5,7 +5,7 @@ SQLALCHEMY_TRACK_MODIFICATIONS = False
|
||||||
CELERY_BROKER_URL = 'redis://localhost:6379/0'
|
CELERY_BROKER_URL = 'redis://localhost:6379/0'
|
||||||
CELERY_RESULT_BACKEND = 'redis://localhost:6379/0'
|
CELERY_RESULT_BACKEND = 'redis://localhost:6379/0'
|
||||||
|
|
||||||
|
from celery.schedules import crontab
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
CELERYBEAT_SCHEDULE = {
|
CELERYBEAT_SCHEDULE = {
|
||||||
|
@ -30,6 +30,16 @@ CELERYBEAT_SCHEDULE = {
|
||||||
'task': 'update_logbook_max_altitude',
|
'task': 'update_logbook_max_altitude',
|
||||||
'schedule': timedelta(minutes=1),
|
'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': {
|
#'purge_old_data': {
|
||||||
# 'task': 'purge_old_data',
|
# 'task': 'purge_old_data',
|
||||||
# 'schedule': timedelta(minutes=10),
|
# 'schedule': timedelta(minutes=10),
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="{{ url_for('static', filename='css/flags/flags.css') }}"/>
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
|
||||||
<div class="panel panel-success">
|
<div class="panel panel-success">
|
||||||
|
|
|
@ -47,7 +47,7 @@
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ loop.index }}</td>
|
<td>{{ loop.index }}</td>
|
||||||
<td><a href="{{ url_for('device_detail', id=entry.device.id) }}">{% if entry.device.info is none %}{{ entry.device.address }}{% else %}{{ entry.device.info.registration }}{% endif %}</a></td>
|
<td><a href="{{ url_for('device_detail', id=entry.device.id) }}">{% if entry.device.info is none %}{{ entry.device.address }}{% else %}{{ entry.device.info.registration }}{% endif %}</a></td>
|
||||||
<td>{% if entry.device.info is none %}(?){% else %}{{ entry.device.info.aircraft }}{% endif %}</td>
|
<td>{% if entry.device.info is none %}-{% else %}{{ entry.device.info.aircraft }}{% endif %}</td>
|
||||||
<td>{% if entry.takeoff_timestamp is not none and entry.takeoff_airport.id|string() == sel_airport %} {{ entry.takeoff_timestamp.strftime('%H:%M') }} {% endif %}</td>
|
<td>{% if entry.takeoff_timestamp is not none and entry.takeoff_airport.id|string() == sel_airport %} {{ entry.takeoff_timestamp.strftime('%H:%M') }} {% endif %}</td>
|
||||||
<td>{% if entry.takeoff_track is not none and entry.takeoff_airport.id|string() == sel_airport %} {{ '%02d' | format(entry.takeoff_track/10) }} {% endif %}</td>
|
<td>{% if entry.takeoff_track is not none and entry.takeoff_airport.id|string() == sel_airport %} {{ '%02d' | format(entry.takeoff_track/10) }} {% endif %}</td>
|
||||||
<td>{% if entry.landing_timestamp is not none and entry.landing_airport.id|string() == sel_airport %} {{ entry.landing_timestamp.strftime('%H:%M') }} {% endif %}</td>
|
<td>{% if entry.landing_timestamp is not none and entry.landing_airport.id|string() == sel_airport %} {{ entry.landing_timestamp.strftime('%H:%M') }} {% endif %}</td>
|
||||||
|
|
Ładowanie…
Reference in New Issue