This commit is contained in:
parent
9865ce0e9e
commit
6f3b1dd936
@ -239,26 +239,57 @@ function readAI(f, apts) {
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
const aircraftLookup = {};
|
||||
|
||||
dat.trafficlist.aircraft.map(n => {
|
||||
try {
|
||||
if(aircraftLookup[n['required-aircraft']] === undefined) {
|
||||
aircraftLookup[n['required-aircraft']] = [];
|
||||
}
|
||||
aircraftLookup[n['required-aircraft']].push(n.airline);
|
||||
aircraftLookup[n['required-aircraft']] = aircraftLookup[n['required-aircraft']].filter((v, i, a) => a.indexOf(v) === i);
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
//debugger;
|
||||
});
|
||||
|
||||
|
||||
logger('info', 'Traffic', dat.trafficlist.flight);
|
||||
|
||||
logger('info', "Departure flights " + dat.trafficlist.flight.length);
|
||||
|
||||
var merged = new Array();
|
||||
// Flat list. Each flight departing or landing counts as one.
|
||||
var merged = [];
|
||||
|
||||
var airports = {};
|
||||
|
||||
|
||||
dat.trafficlist.flight.map(n => {
|
||||
merged.push(n.departure.port);
|
||||
merged.push(n.departure.port);
|
||||
merged.push(n.arrival.port);
|
||||
|
||||
if(airports[n.departure.port] === undefined) {
|
||||
airports[n.departure.port] = [];
|
||||
}
|
||||
if(airports[n.arrival.port] === undefined) {
|
||||
airports[n.arrival.port] = [];
|
||||
}
|
||||
airports[n.departure.port] = airports[n.departure.port].concat(aircraftLookup[n['required-aircraft']]);
|
||||
airports[n.departure.port] = airports[n.departure.port].filter((v, i, a) => a.indexOf(v) === i)
|
||||
airports[n.arrival.port] = airports[n.arrival.port].concat(aircraftLookup[n['required-aircraft']]);
|
||||
airports[n.arrival.port] = airports[n.arrival.port].filter((v, i, a) => a.indexOf(v) === i)
|
||||
}).sort();
|
||||
|
||||
//debugger;
|
||||
var counts = {};
|
||||
for (var i = 0; i < merged.length; i++) {
|
||||
counts[merged[i]] = 1 + (counts[merged[i]] || 0);
|
||||
}
|
||||
|
||||
asyncForEach(Object.keys(counts), async key => {
|
||||
logger('info', key);
|
||||
await store(key, airline[1], counts[key]);
|
||||
asyncForEach(Object.keys(counts), async icao => {
|
||||
logger('info', icao);
|
||||
await store(icao, airports[icao], counts[icao]);
|
||||
}).then(t => {
|
||||
logger('info', "Finished");
|
||||
resolve();
|
||||
@ -290,7 +321,7 @@ function readAI(f, apts) {
|
||||
* @param {*} value
|
||||
*/
|
||||
|
||||
function store(icao, airline, value) {
|
||||
function store(icao, airlines, value) {
|
||||
var promise = new Promise(function (resolve, reject) {
|
||||
logger('info', "Airport " + icao + " has " + value + " new flights");
|
||||
// Make a request to get a record by key from the object store
|
||||
@ -300,18 +331,18 @@ function store(icao, airline, value) {
|
||||
var objectStoreRequest = index.get(icao);
|
||||
|
||||
objectStoreRequest.onsuccess = function (event) {
|
||||
logger('info', 'Stored ', event);
|
||||
logger('info', 'Store Request', event);
|
||||
var feature = objectStoreRequest.result;
|
||||
if (!feature) {
|
||||
feature = createFeature(icao);
|
||||
}
|
||||
feature.properties.flights += value;
|
||||
logger('info', "Airline : ", airline);
|
||||
if (!feature.properties.airlines.includes(airline)) {
|
||||
feature.properties.airlines.push(airline);
|
||||
feature.properties.airlines.sort();
|
||||
}
|
||||
logger('info', "ICAO : " + feature.properties.icao + " Flights : " + feature.properties.flights);
|
||||
logger('info', "Airlines : ", JSON.stringify(airlines));
|
||||
//debugger;
|
||||
feature.properties.airlines = feature.properties.airlines.concat(airlines);
|
||||
feature.properties.airlines = feature.properties.airlines.filter((v, i, a) => a.indexOf(v) === i)
|
||||
feature.properties.airlines.sort()
|
||||
// Create another request that inserts the item back into the database
|
||||
var updateAirportRequest = objectStore.put(feature);
|
||||
|
||||
@ -320,16 +351,16 @@ function store(icao, airline, value) {
|
||||
|
||||
// When this new request succeeds, run the displayData() function again to update the display
|
||||
updateAirportRequest.onsuccess = function (event) {
|
||||
logger('info', "Stored", event);
|
||||
logger('info', "Updated Success", event);
|
||||
resolve();
|
||||
};
|
||||
updateAirportRequest.onerror = function (event) {
|
||||
logger('info', "Error storing ", event);
|
||||
logger('info', "Error updating ", event);
|
||||
reject(event);
|
||||
};
|
||||
};
|
||||
objectStoreRequest.onerror = function (event) {
|
||||
logger('info', "Error " + event);
|
||||
logger('info', "Error reading" + event);
|
||||
reject(event);
|
||||
};
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user