Fix aircraft backfill
This commit is contained in:
@@ -235,31 +235,21 @@ export async function enrichAircraft(a) {
|
||||
// 2. Race the two external sources
|
||||
if(noRecord.includes(icao)) return { icao, ...a, type: 'unknown' };
|
||||
let found = await Promise.any([
|
||||
fetchHexDb(icao).then(resp => {
|
||||
console.log(`source1: ${icao}`, resp);
|
||||
return resp;
|
||||
}),
|
||||
scrapeHexDatabase(icao).then(resp => {
|
||||
console.log(`source2: ${icao}`, resp);
|
||||
return resp;
|
||||
}),
|
||||
fetchHexDb(icao),
|
||||
scrapeHexDatabase(icao),
|
||||
]).catch(() => null);
|
||||
|
||||
// Merge with any partial DB row we already have
|
||||
const merged = { ...row, ...found };
|
||||
if(!merged.aircraft) {
|
||||
if(!found) {
|
||||
noRecord.push(icao);
|
||||
return { icao, ...a, type: 'unknown' };
|
||||
}
|
||||
|
||||
// 3. Backfill manufacturer/model/engines from similar aircraft type in DB
|
||||
const merged = { ...row, ...found };
|
||||
if (merged.aircraft && (!merged.manufacturer || !merged.model)) {
|
||||
const similar = backfillFromSimilar(merged.aircraft);
|
||||
Object.assign(merged, { ...similar, ...merged }); // don't overwrite fetched data
|
||||
Object.assign(merged, similar);
|
||||
}
|
||||
|
||||
console.log(`Backfilling: ${icao}`, merged);
|
||||
|
||||
// 4. Save back to DB
|
||||
if (found) {
|
||||
db.prepare(`
|
||||
@@ -291,8 +281,7 @@ export async function enrichAircraft(a) {
|
||||
});
|
||||
}
|
||||
|
||||
const m = { icao, ...a, ...merged };
|
||||
return {...m, type: classifyAircraft(m) }
|
||||
return {icao, ...a, ...merged, type: classifyAircraft(merged) }
|
||||
}
|
||||
|
||||
export async function getADSB() {
|
||||
|
||||
Reference in New Issue
Block a user