kopia lustrzana https://github.com/glidernet/ogn-python
UI modifications
rodzic
f8ad9763fd
commit
c6aed1a105
|
@ -2,21 +2,10 @@ from app.main import bp
|
||||||
from app.model import Airport, Sender, Receiver
|
from app.model import Airport, Sender, Receiver
|
||||||
|
|
||||||
from flask import url_for
|
from flask import url_for
|
||||||
import time
|
|
||||||
import datetime
|
import datetime
|
||||||
import math
|
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()
|
@bp.app_template_filter()
|
||||||
def to_html_link(obj):
|
def to_html_link(obj):
|
||||||
if isinstance(obj, Airport):
|
if isinstance(obj, Airport):
|
||||||
|
|
|
@ -8,6 +8,7 @@ from .sender_position import SenderPosition
|
||||||
from .receiver_position import ReceiverPosition
|
from .receiver_position import ReceiverPosition
|
||||||
from .receiver_status import ReceiverStatus
|
from .receiver_status import ReceiverStatus
|
||||||
from .receiver import Receiver
|
from .receiver import Receiver
|
||||||
|
from .receiver_state import ReceiverState
|
||||||
from .takeoff_landing import TakeoffLanding
|
from .takeoff_landing import TakeoffLanding
|
||||||
from .airport import Airport
|
from .airport import Airport
|
||||||
from .logbook import Logbook
|
from .logbook import Logbook
|
||||||
|
|
|
@ -6,6 +6,7 @@ from .geo import Location
|
||||||
from app import db
|
from app import db
|
||||||
|
|
||||||
from .airport import Airport
|
from .airport import Airport
|
||||||
|
from .receiver_state import ReceiverState
|
||||||
|
|
||||||
|
|
||||||
class Receiver(db.Model):
|
class Receiver(db.Model):
|
||||||
|
@ -44,6 +45,16 @@ class Receiver(db.Model):
|
||||||
coords = to_shape(self.location_wkt)
|
coords = to_shape(self.location_wkt)
|
||||||
return Location(lat=coords.y, lon=coords.x)
|
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):
|
def airports_nearby(self):
|
||||||
query = (
|
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))
|
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))
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
import enum
|
||||||
|
|
||||||
|
|
||||||
|
class ReceiverState(enum.Enum):
|
||||||
|
# lower number == more trustworthy
|
||||||
|
OK = 0
|
||||||
|
ZOMBIE = 1
|
||||||
|
UNKNOWN = 2
|
||||||
|
OFFLINE = 3
|
|
@ -25,11 +25,17 @@
|
||||||
<table class="datatable table table-striped table-bordered">
|
<table class="datatable table table-striped table-bordered">
|
||||||
<tr>
|
<tr>
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
|
<th>Status</th>
|
||||||
|
<th>Version</th>
|
||||||
|
<th>Platform</th>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
{% for receiver in airport.receivers %}
|
{% for receiver in airport.receivers %}
|
||||||
<tr>
|
<tr>
|
||||||
<td><a href="{{ url_for('main.receiver_detail', receiver_id=receiver.id) }}">{{ receiver.name }}</a></td>
|
<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>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
|
@ -48,7 +54,7 @@
|
||||||
{% for sender in senders %}
|
{% for sender in senders %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ sender|to_html_link|safe }}</td>
|
<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.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>
|
<td>{% if sender.software_version is not none %}{{ sender.software_version }}{% else %}-{% endif %}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
|
@ -38,6 +38,7 @@
|
||||||
<tr>
|
<tr>
|
||||||
<th></th>
|
<th></th>
|
||||||
<th></th>
|
<th></th>
|
||||||
|
<th colspan="2">Aircraft</th>
|
||||||
<th colspan="2">Airport</th>
|
<th colspan="2">Airport</th>
|
||||||
<th colspan="2">Time UTC</th>
|
<th colspan="2">Time UTC</th>
|
||||||
<th></th>
|
<th></th>
|
||||||
|
@ -46,6 +47,8 @@
|
||||||
<tr>
|
<tr>
|
||||||
<th>#</th>
|
<th>#</th>
|
||||||
<th>Date</th>
|
<th>Date</th>
|
||||||
|
<th>Registration</th>
|
||||||
|
<th>Type</th>
|
||||||
<th>Takeoff</th>
|
<th>Takeoff</th>
|
||||||
<th>Landing</th>
|
<th>Landing</th>
|
||||||
<th>Takeoff</th>
|
<th>Takeoff</th>
|
||||||
|
@ -60,6 +63,8 @@
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ loop.index }}</td>
|
<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>{% 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.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.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>
|
<td>{% if entry.takeoff_timestamp is not none %} {{ entry.takeoff_timestamp.strftime('%H:%M') }} {% endif %}</td>
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
<table class="datatable table table-striped table-bordered">
|
<table class="datatable table table-striped table-bordered">
|
||||||
<tr>
|
<tr>
|
||||||
<th>#</th>
|
<th>#</th>
|
||||||
<th>Aircraft</th>
|
<th>Registration</th>
|
||||||
<th>Type</th>
|
<th>Type</th>
|
||||||
<th colspan="2">Takeoff</th>
|
<th colspan="2">Takeoff</th>
|
||||||
<th colspan="2">Landing</th>
|
<th colspan="2">Landing</th>
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
<tr><td>Platform:</td><td>{{ receiver.platform if receiver.platform else '-' }}</td></tr>
|
<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>First seen:</td><td>{{ receiver.firstseen }}</td></tr>
|
||||||
<tr><td>Last seen:</td><td>{{ receiver.lastseen }}</td></tr>
|
<tr><td>Last seen:</td><td>{{ receiver.lastseen }}</td></tr>
|
||||||
|
<tr><td>State:</td><td>{{ receiver.state.name }}</td></tr>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
<td>{{ receiver|to_html_link|safe }}</td>
|
<td>{{ receiver|to_html_link|safe }}</td>
|
||||||
<td>{{ receiver.airport|to_html_link|safe }}</td>
|
<td>{{ receiver.airport|to_html_link|safe }}</td>
|
||||||
<td>{{ receiver.altitude|int }} m</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.version if receiver.version else '-' }}</td>
|
||||||
<td>{{ receiver.platform if receiver.platform else '-' }}</td>
|
<td>{{ receiver.platform if receiver.platform else '-' }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
Ładowanie…
Reference in New Issue