Skip to content

Commit

Permalink
Introduce a new namedtuple type "FlightInfo".
Browse files Browse the repository at this point in the history
This dramatically improves performance of the map with many aircraft
by reducing the number of cells per aircraft.
  • Loading branch information
quentinmit committed Dec 23, 2018
1 parent 6b47f70 commit 6da8b77
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 48 deletions.
1 change: 1 addition & 0 deletions shinysdr/i/webstatic/client/widgets/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ define([
update(value, draw);
});
}
exports.SimpleElementWidget = SimpleElementWidget;

function Generic(config) {
SimpleElementWidget.call(this, config, undefined,
Expand Down
81 changes: 38 additions & 43 deletions shinysdr/plugins/flightradar24/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

from __future__ import absolute_import, division, print_function, unicode_literals

from collections import namedtuple
import json
import os.path

Expand Down Expand Up @@ -140,19 +141,35 @@ class IAircraft(Interface):
pass


FlightInfo = namedtuple('FlightInfo', [
'callsign', # ICAO ATC call signature
'registration',
'origin', # airport IATA code
'destination', # airport IATA code
'flight',
'squawk_code', # https://en.wikipedia.org/wiki/Transponder_(aeronautics)
'model', # ICAO aircraft type designator
])


empty_flight_info = FlightInfo(
None,
None,
None,
None,
None,
None,
None,
)


@implementer(IAircraft, ITelemetryObject)
class Aircraft(ExportedState):
def __init__(self, object_id):
"""Implements ITelemetryObject. object_id is the hex formatted address."""
self.__last_heard_time = None
self.__track = empty_track
self.__callsign = None
self.__registration = None
self.__origin = None
self.__destination = None
self.__flight = None
self.__squawk_code = None
self.__model = None
self.__flight_info = empty_flight_info

# not exported
def receive(self, message_wrapper):
Expand Down Expand Up @@ -205,13 +222,15 @@ def receive(self, message_wrapper):
self.__track = self.__track._replace(**new)

self.__last_heard_time = timestamp
self.__callsign = callsign
self.__registration = registration
self.__origin = origin
self.__destination = destination
self.__flight = flight
self.__squawk_code = squawk_code
self.__model = model
self.__flight_info = FlightInfo(
callsign=callsign,
registration=registration,
origin=origin,
destination=destination,
flight=flight,
squawk_code=squawk_code,
model=model,
)
self.state_changed()

def is_interesting(self):
Expand All @@ -222,8 +241,8 @@ def is_interesting(self):
return \
self.__track.latitude.value is not None or \
self.__track.longitude.value is not None or \
self.__call is not None or \
self.__aircraft_type is not None
self.__flight_info.callsign is not None or \
self.__flight_info.registration is not None

def get_object_expiry(self):
"""implement ITelemetryObject"""
Expand All @@ -233,33 +252,9 @@ def get_object_expiry(self):
def get_last_heard_time(self):
return self.__last_heard_time

@exported_value(type=six.text_type, changes='explicit', sort_key='020', label='Callsign')
def get_callsign(self):
return self.__callsign

@exported_value(type=six.text_type, changes='explicit', sort_key='030', label='Registration')
def get_registration(self):
return self.__registration

@exported_value(type=six.text_type, changes='explicit', sort_key='040', label='Origin')
def get_origin(self):
return self.__origin

@exported_value(type=six.text_type, changes='explicit', sort_key='050', label='Destination')
def get_destination(self):
return self.__destination

@exported_value(type=six.text_type, changes='explicit', sort_key='060', label='Flight')
def get_flight(self):
return self.__flight

@exported_value(type=six.text_type, changes='explicit', sort_key='070', label='Squawk Code')
def get_squawk_code(self):
return self.__squawk_code

@exported_value(type=six.text_type, changes='explicit', sort_key='080', label='Model')
def get_model(self):
return self.__model
@exported_value(type=FlightInfo, changes='explicit', sort_key='020')
def get_flight_info(self):
return self.__flight_info

@exported_value(type=Track, changes='explicit', sort_key='010', label='')
def get_track(self):
Expand Down
43 changes: 38 additions & 5 deletions shinysdr/plugins/flightradar24/client/flightradar24.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,47 @@ define([
renderTrackFeature,
} = import_map_core;
const {
SimpleElementWidget,
Block,
} = import_widgets_basic;

const exports = {};

function FlightInfoWidget(config) {
SimpleElementWidget.call(this, config, 'DIV',
function buildPanelForFlightInfo(container) {
return container.appendChild(document.createElement('DIV'));
},
function initEl(valueEl, target) {
/*
BOX451 / 3S451 (JFK / FRA)
B77L D-AALB
Squawk 1714
*/
function addDiv() {
let div = valueEl.appendChild(document.createElement('div'));
let textNode = document.createTextNode('');
div.appendChild(textNode);
return textNode;
}
var row1 = addDiv();
var row2 = addDiv();
var row3 = addDiv();
return function updateEl(flight_info) {
row1.data = `${flight_info.callsign} / ${flight_info.flight}`;
if (flight_info.origin || flight_info.destination) {
row1.data += ` (${flight_info.origin || '???'} / ${flight_info.destination || '???'})`;
}
row2.data = `${flight_info.model} ${flight_info.registration}`;
row3.data = `Squawk ${flight_info.squawk_code}`;
};
});
}

function AircraftWidget(config) {
Block.call(this, config, function (block, addWidget, ignore, setInsertion, setToDetails, getAppend) {
addWidget('track', widgets.TrackWidget);
// TODO: More compact rendering of cells.
addWidget('flight_info', FlightInfoWidget);
}, false);
}

Expand All @@ -52,10 +84,11 @@ define([
mapPluginConfig.addLayer('flightradar24', {
featuresCell: mapPluginConfig.index.implementing('shinysdr.plugins.flightradar24.IAircraft'),
featureRenderer: function renderAircraft(aircraft, dirty) {
var trackCell = aircraft.track;
var callsign = aircraft.callsign.depend(dirty);
var ident = aircraft.squawk_code.depend(dirty);
var altitude = trackCell.depend(dirty).altitude.value;
let trackCell = aircraft.track;
let flight_info = aircraft.flight_info.depend(dirty);
let callsign = flight_info.callsign;
let ident = flight_info.squawk_code;
let altitude = trackCell.depend(dirty).altitude.value;
var labelParts = [];
if (callsign !== null) {
labelParts.push(callsign.replace(/^ | $/g, ''));
Expand Down

0 comments on commit 6da8b77

Please sign in to comment.