UI modifications

pull/78/head
Konstantin Gründger 2020-11-24 20:26:28 +01:00
rodzic f8ad9763fd
commit c6aed1a105
9 zmienionych plików z 36 dodań i 14 usunięć

Wyświetl plik

@ -2,21 +2,10 @@ from app.main import bp
from app.model import Airport, Sender, Receiver
from flask import url_for
import time
import datetime
import math
@bp.app_template_filter()
def timestamp_to_status(timestamp):
if datetime.datetime.utcnow() - timestamp < datetime.timedelta(minutes=10):
return 'OK'
elif datetime.datetime.utcnow() - timestamp < datetime.timedelta(hours=1):
return '<b>?</b>'
else:
return '<b>OFFLINE</b>'
@bp.app_template_filter()
def to_html_link(obj):
if isinstance(obj, Airport):

Wyświetl plik

@ -8,6 +8,7 @@ from .sender_position import SenderPosition
from .receiver_position import ReceiverPosition
from .receiver_status import ReceiverStatus
from .receiver import Receiver
from .receiver_state import ReceiverState
from .takeoff_landing import TakeoffLanding
from .airport import Airport
from .logbook import Logbook

Wyświetl plik

@ -6,6 +6,7 @@ from .geo import Location
from app import db
from .airport import Airport
from .receiver_state import ReceiverState
class Receiver(db.Model):
@ -44,6 +45,16 @@ class Receiver(db.Model):
coords = to_shape(self.location_wkt)
return Location(lat=coords.y, lon=coords.x)
@property
def state(self):
import datetime
if datetime.datetime.utcnow() - self.lastseen < datetime.timedelta(minutes=10):
return ReceiverState.OK if len(self.statistics) > 0 else ReceiverState.ZOMBIE
elif datetime.datetime.utcnow() - self.lastseen < datetime.timedelta(hours=1):
return ReceiverState.UNKNOWN
else:
return ReceiverState.OFFLINE
def airports_nearby(self):
query = (
db.session.query(Airport, db.func.st_distance_sphere(self.location_wkt, Airport.location_wkt), db.func.st_azimuth(self.location_wkt, Airport.location_wkt))

Wyświetl plik

@ -0,0 +1,9 @@
import enum
class ReceiverState(enum.Enum):
# lower number == more trustworthy
OK = 0
ZOMBIE = 1
UNKNOWN = 2
OFFLINE = 3

Wyświetl plik

@ -25,11 +25,17 @@
<table class="datatable table table-striped table-bordered">
<tr>
<th>Name</th>
<th>Status</th>
<th>Version</th>
<th>Platform</th>
</tr>
{% for receiver in airport.receivers %}
<tr>
<td><a href="{{ url_for('main.receiver_detail', receiver_id=receiver.id) }}">{{ receiver.name }}</a></td>
<td>{{ receiver.state.name }}</td>
<td>{{ receiver.version if receiver.version else '-' }}</td>
<td>{{ receiver.platform if receiver.platform else '-' }}</td>
</tr>
{% endfor %}
</table>
@ -48,7 +54,7 @@
{% for sender in senders %}
<tr>
<td>{{ sender|to_html_link|safe }}</td>
<td>{% if sender.takeoff_landings %}{% set last_action = sender.takeoff_landings|last %}{% if last_action.is_takeoff == db.true() %}↗{% else %}↘{% endif %} @ {{ last_action.timestamp.strftime('%Y-%m-%d %H:%M:%S') }}{% endif %}
<td>{% if sender.takeoff_landings %}{% set last_action = sender.takeoff_landings|last %}{% if last_action.is_takeoff %}↗{% else %}↘{% endif %} @ {{ last_action.timestamp.strftime('%Y-%m-%d %H:%M:%S') }}{% endif %}
<td>{% if sender.hardware_version is not none %}{{ sender.hardware_version }}{% else %}-{% endif %}</td>
<td>{% if sender.software_version is not none %}{{ sender.software_version }}{% else %}-{% endif %}</td>
</tr>

Wyświetl plik

@ -38,6 +38,7 @@
<tr>
<th></th>
<th></th>
<th colspan="2">Aircraft</th>
<th colspan="2">Airport</th>
<th colspan="2">Time UTC</th>
<th></th>
@ -46,6 +47,8 @@
<tr>
<th>#</th>
<th>Date</th>
<th>Registration</th>
<th>Type</th>
<th>Takeoff</th>
<th>Landing</th>
<th>Takeoff</th>
@ -60,6 +63,8 @@
<tr>
<td>{{ loop.index }}</td>
<td>{% if ns.mydate != entry.reference_timestamp.strftime('%Y-%m-%d') %}{% set ns.mydate = entry.reference_timestamp.strftime('%Y-%m-%d') %}{{ ns.mydate }}{% endif %}</td>
<td>{{ entry.sender|to_html_link|safe }}</td>
<td>{% if entry.sender.infos|length > 0 and entry.sender.infos[0].aircraft|length %}{{ entry.sender.infos[0].aircraft }}{% else %}-{% endif %}</td>
<td>{% if entry.takeoff_airport is not none %}<a href="{{ url_for('main.logbooks', country=entry.takeoff_airport.country_code, airport_id=entry.takeoff_airport.id, date=entry.reference_timestamp.strftime('%Y-%m-%d')) }}">{{ entry.takeoff_airport.name }}</a>{% endif %}</td>
<td>{% if entry.landing_airport is not none %}<a href="{{ url_for('main.logbooks', country=entry.landing_airport.country_code, airport_id=entry.landing_airport.id, date=entry.reference_timestamp.strftime('%Y-%m-%d')) }}">{{ entry.landing_airport.name }}</a>{% endif %}</td>
<td>{% if entry.takeoff_timestamp is not none %} {{ entry.takeoff_timestamp.strftime('%H:%M') }} {% endif %}</td>

Wyświetl plik

@ -41,7 +41,7 @@
<table class="datatable table table-striped table-bordered">
<tr>
<th>#</th>
<th>Aircraft</th>
<th>Registration</th>
<th>Type</th>
<th colspan="2">Takeoff</th>
<th colspan="2">Landing</th>

Wyświetl plik

@ -23,6 +23,7 @@
<tr><td>Platform:</td><td>{{ receiver.platform if receiver.platform else '-' }}</td></tr>
<tr><td>First seen:</td><td>{{ receiver.firstseen }}</td></tr>
<tr><td>Last seen:</td><td>{{ receiver.lastseen }}</td></tr>
<tr><td>State:</td><td>{{ receiver.state.name }}</td></tr>
</table>
</div>

Wyświetl plik

@ -39,7 +39,7 @@
<td>{{ receiver|to_html_link|safe }}</td>
<td>{{ receiver.airport|to_html_link|safe }}</td>
<td>{{ receiver.altitude|int }} m</td>
<td>{{ receiver.lastseen|timestamp_to_status|safe }}</td>
<td>{{ receiver.state.name }}</td>
<td>{{ receiver.version if receiver.version else '-' }}</td>
<td>{{ receiver.platform if receiver.platform else '-' }}</td>
</tr>