Add airport_detail page

pull/78/head
Konstantin Gründger 2019-03-23 20:46:27 +01:00
rodzic f5701db672
commit a598a736d9
6 zmienionych plików z 82 dodań i 42 usunięć

Wyświetl plik

@ -3,6 +3,7 @@ from sqlalchemy.ext.hybrid import hybrid_property
from ogn_python import db
from .device_info import DeviceInfo
class Device(db.Model):
__tablename__ = 'devices'

Wyświetl plik

@ -65,16 +65,16 @@ def receiver_detail():
.filter(Receiver.id == sel_receiver_id) \
.one()
near_airports = db.session.query(Airport, func.st_distancesphere(Airport.location_wkt, Receiver.location_wkt).label('distance')) \
.filter(and_(Receiver.id == sel_receiver_id), func.st_contains(func.st_buffer(Receiver.location_wkt, 0.5), Airport.location_wkt)) \
airport = db.session.query(Airport) \
.filter(and_(Receiver.id == sel_receiver_id,
func.st_contains(func.st_buffer(Receiver.location_wkt, 0.5), Airport.location_wkt),
func.st_distance_sphere(Airport.location_wkt, Receiver.location_wkt) < 1000)) \
.filter(Airport.style.in_((2,4,5))) \
.order_by(func.st_distancesphere(Airport.location_wkt, Receiver.location_wkt)) \
.limit(10)
return render_template('receiver_detail.html',
title='Receiver Detail',
receiver=receiver,
near_airports=near_airports)
airport=airport.first())
@app.route('/airports.html', methods=['GET', 'POST'])
@ -92,19 +92,31 @@ def airports():
.group_by(Airport.id) \
.order_by(Airport.name)
else:
airports = db.session.query(Airport) \
.filter(or_(Logbook.takeoff_airport_id == Airport.id, Logbook.landing_airport_id == Airport.id)) \
.group_by(Airport.id) \
.order_by(Airport.name)
airports = []
page = request.args.get('page', 1, type=int)
return render_template('airports.html', sel_country=sel_country, countries=countries_in_logbook, airports=airports)
return render_template('airports.html',
sel_country=sel_country,
countries=countries_in_logbook,
airports=airports)
@app.route('/airport.html')
def airport():
pass
@app.route('/airport_detail.html')
def airport_detail():
sel_airport = request.args.get('airport')
airport = db.session.query(Airport) \
.filter(Airport.id == sel_airport)
devices = db.session.query(Device).join(Logbook) \
.filter(Logbook.takeoff_airport_id == sel_airport) \
.order_by(Device.address)
return render_template('airport_detail.html',
title='Airport Detail',
airport=airport.one(),
devices=devices)
@app.route('/logbook.html', methods=['GET', 'POST'])
@ -182,6 +194,7 @@ def logbook():
dates=dates,
logbook=logbook)
@app.route('/statistics.html')
def statistics():
receiverstats = db.session.query(ReceiverStats) \
@ -191,6 +204,7 @@ def statistics():
# Backend routes for other sites
@app.route('/live.html')
def live():
return render_template('ogn_live.jinja')

Wyświetl plik

@ -0,0 +1,44 @@
{% extends "base.html" %}
{% block content %}
<div class="container">
<div class="panel panel-success">
<div class="panel-heading"><h3 class="panel-title">Airport Details</h3></div>
<table class="datatable table table-striped table-bordered">
<tr><td>Name:</td><td><img src="{{ url_for('static', filename='img/Transparent.gif') }}" class="flag flag-{{ airport.country_code|lower }}" alt="{{ airport.country_code }}"/> {{ airport.name }}</td></tr>
<tr><td>Code:</td><td>{{ airport.code }}</td></tr>
<tr><td>Altitude:</td><td>{{ airport.altitude|int }} m</td></tr>
<tr><td>Style:</td><td>{{ airport.style }}</td></tr>
<tr><td>Description:</td><td>{{ airport.description }}</td></tr>
<tr><td>Runway Direction:</td><td>{{ airport.runway_direction }}</td></tr>
<tr><td>Runway Length:</td><td>{{ airport.runway_length }} m</td></tr>
<tr><td>Frequency:</td><td>{{ airport.frequency }} MHz</td></tr>
</table>
</div>
<div class="panel panel-success">
<div class="panel-heading"><h3 class="panel-title">Seen Devices</h3></div>
<table class="datatable table table-striped table-bordered">
<tr>
<th>Address</th>
<th>Registration</th>
<th>Last takeoff/landing</th>
<th>Software version</th>
</tr>
{% for device in devices %}
<tr>
<td><a href="{{ url_for('device_detail', id=device.id) }}">{{ device.address }}</a></td>
<td>{% if device.info is none %}-{% else %}{{ device.info.registration }}{% endif %}</a></td>
<td>{% if device.takeoff_landings %}{% set last_action = device.takeoff_landings|last %}{% if last_action.is_takeoff == True %}↗{% else %}↘{% endif %} @ {{ last_action.timestamp.strftime('%Y-%m-%d %H:%M:%S') }}{% endif %}
<td>{{ device.software_version }}</td>
</tr>
{% endfor %}
</table>
</div>
</div>
{% endblock %}

Wyświetl plik

@ -24,14 +24,14 @@
<tr>
<th>#</th>
<th>Name</th>
<th>Country</th>
<th>Logbook (takeoff and landings)</th>
</tr>
{% for airport in airports %}
<tr>
<td>{{ loop.index }}
<td><a href="{{ url_for('logbook', airport=airport.id) }}">{{ airport.name }}</a></td>
<td><img src="{{ url_for('static', filename='img/Transparent.gif') }}" class="flag flag-{{ airport.country_code|lower }}" alt="{{ airport.country_code }}"/></td>
<td><img src="{{ url_for('static', filename='img/Transparent.gif') }}" class="flag flag-{{ airport.country_code|lower }}" alt="{{ airport.country_code }}"/> <a href="{{ url_for('airport_detail', airport=airport.id) }}">{{ airport.name }}</a></td>
<td><a href="{{ url_for('logbook', airport=airport.id) }}">Logbook</a></td>
</tr>
{% endfor %}
</table>

Wyświetl plik

@ -51,7 +51,7 @@
<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_track is not none and entry.landing_airport.id|string() == sel_airport %} {{ '%02d' | format(entry.landing_track/10) }} {% endif %}</td>
<td>{% if entry.max_altitude is not none %}{{ entry.max_altitude - entry.takeoff_airport.altitude }} m{% endif %}</td>
<td>{% if entry.max_altitude is not none %}{{ '%0.1f'|format(entry.max_altitude - entry.takeoff_airport.altitude) }} m{% endif %}</td>
<td>
{% if entry.takeoff_airport is not none and entry.takeoff_airport.id|string() != sel_airport %}Take Off: <a href="{{ url_for('logbook', airport=entry.takeoff_airport.id) }}">{{ entry.takeoff_airport.name }}</a>
{% elif entry.landing_airport is not none and entry.landing_airport.id|string() != sel_airport %}Landing: <a href="{{ url_for('logbook', airport=entry.landing_airport.id) }}">{{ entry.landing_airport.name }}</a>

Wyświetl plik

@ -11,6 +11,12 @@
<div class="panel-heading"><h3 class="panel-title">Receiver Details</h3></div>
<table class="datatable table table-striped table-bordered">
<tr><td>Name:</td><td><img src="{{ url_for('static', filename='img/Transparent.gif') }}" class="flag flag-{{ receiver.country.iso2|lower }}" alt="{{ receiver.country.iso2 }}"/> {{ receiver.name }}</td></tr>
<tr><td>Airport:</td>
<td>{% if airport is not none %}<img src="{{ url_for('static', filename='img/Transparent.gif') }}" class="flag flag-{{ airport.country_code|lower }}" alt="{{ airport.country_code }}"/>
{% if airport.takeoff_landings %}<a href="{{ url_for('logbook', airport=airport.id) }}">{{ airport.name }}</a>{% else %}{{ airport.name }}{% endif %}
{% else %}-{% endif %}
</td>
</tr>
<tr><td>Version:</td><td>{{ receiver.version }}</td></tr>
<tr><td>Platform:</td><td>{{ receiver.platform }}</td></tr>
<tr><td>First seen:</td><td>{{ receiver.firstseen }}</td></tr>
@ -18,31 +24,6 @@
</table>
</div>
<div class="panel panel-success">
<div class="panel-heading"><h3 class="panel-title">Nearby Airports</h3></div>
<table class="datatable table table-striped table-bordered">
<thead>
<tr>
<th>Name</th>
<th>Distance</th>
</tr>
</thead>
<tbody>
{% for tupel in near_airports %}
{% set airport = tupel[0] %}
{% set distance = tupel[1] %}
<tr>
<td><img src="{{ url_for('static', filename='img/Transparent.gif') }}" class="flag flag-{{ airport.country_code|lower }}" alt="{{ airport.country_code }}"/> {% if airport.takeoff_landings %}<a href="{{ url_for('logbook', airport=airport.id) }}">{{ airport.name }}</a>{% else %}{{ airport.name }}{% endif %}</td>
<td>{{ '%0.1f'|format(distance/1000) }} km</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endblock %}