1- import { rdsGetSingle } from "@sr24/db/redis" ;
2- import type { FIRFeature , SimAwareTraconFeature } from "@sr24/types/db" ;
31import type { ControllerDelta , ControllerLong , ControllerMerged , ControllerShort , PilotLong } from "@sr24/types/interface" ;
42import type { VatsimData } from "@sr24/types/vatsim" ;
53import { haversineDistance } from "./utils/helpers.js" ;
4+ import { findPrefixMatch , reduceCallsign } from "./utils/sectors.js" ;
65
76let cached : ControllerMerged [ ] = [ ] ;
87let updated : ControllerMerged [ ] = [ ] ;
@@ -12,6 +11,7 @@ export async function mapControllers(vatsimData: VatsimData, pilotsLong: PilotLo
1211 const controllersLong : ControllerLong [ ] = vatsimData . controllers
1312 . map ( ( controller ) => {
1413 if ( controller . facility === 0 && ! controller . callsign . includes ( "OBS" ) ) return null ;
14+ if ( controller . frequency === "199.998" ) return null ;
1515 return {
1616 callsign : controller . callsign ,
1717 frequency : parseFrequencyToKHz ( controller . frequency ) ,
@@ -169,35 +169,9 @@ function getConnectionsCount(vatsimData: VatsimData, controllersLong: Controller
169169 }
170170}
171171
172- const firPrefixes : Map < string , string > = new Map ( ) ;
173- const traconPrefixes : Map < string , string > = new Map ( ) ;
174-
175172async function mergeControllers ( controllersLong : ControllerLong [ ] ) : Promise < ControllerMerged [ ] > {
176- await updateFeaturesFromRedis ( ) ;
177-
178173 const merged = new Map < string , ControllerMerged > ( ) ;
179174
180- const reduceCallsign = ( callsign : string ) : string [ ] => {
181- const parts = callsign . split ( "_" ) ;
182- const levels : string [ ] = [ ] ;
183-
184- for ( let i = parts . length ; i > 0 ; i -- ) {
185- levels . push ( parts . slice ( 0 , i ) . join ( "_" ) ) ;
186- }
187-
188- return levels ;
189- } ;
190-
191- const findPrefixMatch = ( levels : string [ ] , facility : number ) : string | null => {
192- const lookup = facility === 6 ? firPrefixes : traconPrefixes ;
193-
194- for ( const lvl of levels ) {
195- const match = lookup . get ( lvl ) ;
196- if ( match ) return match ;
197- }
198- return null ;
199- } ;
200-
201175 for ( const c of controllersLong ) {
202176 let id : string | null = null ;
203177 let facility : ControllerMerged [ "facility" ] | null = null ;
@@ -248,49 +222,3 @@ async function mergeControllers(controllersLong: ControllerLong[]): Promise<Cont
248222
249223 return Array . from ( merged . values ( ) ) ;
250224}
251-
252- let currentFirsVersion : string | null = null ;
253- let currentTraconsVersion : string | null = null ;
254-
255- async function updateFeaturesFromRedis ( ) : Promise < void > {
256- const firsVersion = await rdsGetSingle ( "static_firs:version" ) ;
257- const traconsVersion = await rdsGetSingle ( "static_tracons:version" ) ;
258-
259- if ( currentFirsVersion !== firsVersion ) {
260- const features = ( await rdsGetSingle ( "static_firs:all" ) ) as FIRFeature [ ] | undefined ;
261- if ( features ) {
262- firPrefixes . clear ( ) ;
263- features . forEach ( ( f ) => {
264- const prefix = f . properties . callsign_prefix ;
265- const id = f . properties . id ;
266- if ( prefix === "" ) {
267- firPrefixes . set ( id , id ) ;
268- } else {
269- firPrefixes . set ( prefix , id ) ;
270- }
271- } ) ;
272-
273- currentFirsVersion = firsVersion ;
274- }
275- }
276-
277- if ( currentTraconsVersion !== traconsVersion ) {
278- const features = ( await rdsGetSingle ( "static_tracons:all" ) ) as SimAwareTraconFeature [ ] | undefined ;
279- if ( features ) {
280- traconPrefixes . clear ( ) ;
281- features . forEach ( ( f ) => {
282- const prefixes = f . properties . prefix ;
283-
284- if ( typeof prefixes === "string" ) {
285- traconPrefixes . set ( prefixes , f . properties . id ) ;
286- } else {
287- prefixes . forEach ( ( prefix ) => {
288- traconPrefixes . set ( prefix , f . properties . id ) ;
289- } ) ;
290- }
291- } ) ;
292-
293- currentTraconsVersion = traconsVersion ;
294- }
295- }
296- }
0 commit comments