From 08ffda1aa849e7f94b271754911dd69c03bd3132 Mon Sep 17 00:00:00 2001 From: Carlos Salaverria Date: Fri, 26 Aug 2016 14:25:25 -0500 Subject: [PATCH] Update aircraft db logic to include ICAO type information --- public_html/dbloader.js | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/public_html/dbloader.js b/public_html/dbloader.js index 7525195..fe70744 100644 --- a/public_html/dbloader.js +++ b/public_html/dbloader.js @@ -22,6 +22,7 @@ "use strict"; var _aircraft_cache = {}; +var _aircraft_type_cache = null; function getAircraftData(icao) { var defer; @@ -48,7 +49,7 @@ function request_from_db(icao, level, defer) { var subkey; if (dkey in data) { - defer.resolve(data[dkey]); + getIcaoAircraftTypeData(data[dkey], defer); return; } @@ -67,6 +68,34 @@ function request_from_db(icao, level, defer) { }); } +function getIcaoAircraftTypeData(aircraftData, defer) { + if (_aircraft_type_cache === null) { + $.getJSON("db/aircraft_types/icao_aircraft_types.json") + .done(function(typeLookupData) { + _aircraft_type_cache = typeLookupData; + }) + .always(function() { + lookupIcaoAircraftType(aircraftData, defer); + }); + } + else { + lookupIcaoAircraftType(aircraftData, defer); + } +} + +function lookupIcaoAircraftType(aircraftData, defer) { + if (_aircraft_type_cache !== null && "t" in aircraftData) { + var typeDesignator = aircraftData["t"].toUpperCase(); + if (typeDesignator in _aircraft_type_cache) { + var typeData = _aircraft_type_cache[typeDesignator]; + aircraftData.desc = typeData.desc; + aircraftData.wtc = typeData.wtc; + } + } + + defer.resolve(aircraftData); +} + var _request_count = 0; var _request_queue = []; var _request_cache = {};