MCPcopy
hub / github.com/cpaczek/skylight / enrich

Method enrich

server/src/datasource.ts:316–367  ·  view source on GitHub ↗
(ac: Aircraft, now: number)

Source from the content-addressed store, hash-verified

314 }
315
316 private enrich(ac: Aircraft, now: number): void {
317 // Instant table lookups first.
318 ac.typeName = lookupType(ac.typeCode);
319 ac.airline = lookupAirline(ac.flight);
320
321 // adsbdb fills gaps (route + better type), from cache when available.
322 const e = this.o.enricher.enrichSync(ac.hex, ac.flight, now);
323 if (e.route) {
324 ac.airline = ac.airline ?? e.route.airline;
325 ac.origin = e.route.origin ?? ac.origin;
326 ac.destination = e.route.destination ?? ac.destination;
327 ac.originName = e.route.originName ?? ac.originName;
328 ac.destName = e.route.destName ?? ac.destName;
329 ac.originLat = e.route.originLat ?? ac.originLat;
330 ac.originLon = e.route.originLon ?? ac.originLon;
331 ac.destLat = e.route.destLat ?? ac.destLat;
332 ac.destLon = e.route.destLon ?? ac.destLon;
333 }
334 if (e.aircraft) {
335 ac.typeName = ac.typeName ?? e.aircraft.typeName;
336 ac.registration = ac.registration ?? e.aircraft.registration;
337 }
338
339 // Sticky merge: once we've resolved something for this hex, never drop it
340 // back to undefined on a later snapshot (prevents label flicker).
341 const prev = this.sticky.get(ac.hex);
342 ac.typeName = ac.typeName ?? prev?.typeName;
343 ac.airline = ac.airline ?? prev?.airline;
344 ac.origin = ac.origin ?? prev?.origin;
345 ac.destination = ac.destination ?? prev?.destination;
346 ac.registration = ac.registration ?? prev?.registration;
347 ac.originName = ac.originName ?? prev?.originName;
348 ac.destName = ac.destName ?? prev?.destName;
349 ac.originLat = ac.originLat ?? prev?.originLat;
350 ac.originLon = ac.originLon ?? prev?.originLon;
351 ac.destLat = ac.destLat ?? prev?.destLat;
352 ac.destLon = ac.destLon ?? prev?.destLon;
353 this.sticky.set(ac.hex, {
354 typeName: ac.typeName,
355 airline: ac.airline,
356 origin: ac.origin,
357 destination: ac.destination,
358 registration: ac.registration,
359 originName: ac.originName,
360 destName: ac.destName,
361 originLat: ac.originLat,
362 originLon: ac.originLon,
363 destLat: ac.destLat,
364 destLon: ac.destLon,
365 lastSeen: now,
366 });
367 }
368
369 /** Drop sticky entries for aircraft long gone (keep the map small). */
370 private pruneSticky(now: number): void {

Callers 1

tickMethod · 0.95

Calls 5

lookupTypeFunction · 0.85
lookupAirlineFunction · 0.85
enrichSyncMethod · 0.80
setMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected