diff options
| author | Arturs Artamonovs <arturs.artamonovs@protonmail.com> | 2026-09-24 10:18:00 +0100 |
|---|---|---|
| committer | Arturs Artamonovs <arturs.artamonovs@protonmail.com> | 2026-09-24 10:18:00 +0100 |
| commit | 056ee0c3355db995d7ea571e0635ebe8b09bf8ee (patch) | |
| tree | 484a084eea788516c2395106c11f2f5f80e10bc4 /LearnMapKit | |
| parent | ed53ed83b71f2f3005d8b52ad005aeff1f59e39c (diff) | |
| download | ADSBDecoder-056ee0c3355db995d7ea571e0635ebe8b09bf8ee.tar.gz ADSBDecoder-056ee0c3355db995d7ea571e0635ebe8b09bf8ee.zip | |
expired flights get removed, and when stalled get grayed out
Diffstat (limited to 'LearnMapKit')
| -rw-r--r-- | LearnMapKit/ContentView.swift | 3 | ||||
| -rw-r--r-- | LearnMapKit/FlighState.swift | 43 |
2 files changed, 27 insertions, 19 deletions
diff --git a/LearnMapKit/ContentView.swift b/LearnMapKit/ContentView.swift index 4d597f6..8f8f3e9 100644 --- a/LearnMapKit/ContentView.swift +++ b/LearnMapKit/ContentView.swift @@ -41,7 +41,8 @@ struct ContentView: View { RoundedRectangle(cornerRadius: 10) .fill(.background) RoundedRectangle(cornerRadius: 10) - .stroke(.secondary,lineWidth: 5) + .stroke(flightState.isStaled(flight) ? .gray : .secondary, lineWidth: 5) + .animation(.easeInOut(duration: 0.4), value: flightState.isStaled(flight)) Image(systemName:"airplane.circle.fill") .resizable() .frame(width:20,height: 20) diff --git a/LearnMapKit/FlighState.swift b/LearnMapKit/FlighState.swift index 9bb6782..9f26578 100644 --- a/LearnMapKit/FlighState.swift +++ b/LearnMapKit/FlighState.swift @@ -13,13 +13,10 @@ class FlightTracker: Identifiable { var last_time_seen: Int = 0 var ICAOaddress = 0 var ICAOName_avaliable = false - //@Published var ICAOName = "" var ICAOName = "" var Position_avaliable = false @Published var long:Double = 0.0 - //var long:Double = 0.0 @Published var lat:Double = 0.0 - //var lat:Double = 0.0 var FromTo_avaliable = false var flightFrom:String = "" var flightTo:String = "" @@ -52,14 +49,18 @@ class FlightState: ObservableObject { @Published var flight:[FlightTracker] = [] //configuration options - var sourceFile = false + var sourceFile = true var default_file_path = "/Users/jackyjack/Downloads/2024_05_27_raw_adsb.txt" var process_per_second = 120 - var sourceDump1090Server = true + var sourceDump1090Server = false var dump1090address = "X.X.X.X" var dump1090port = 12345 + //flight expiration + var staleAfterSeconds: Int = 120 + var expireAfterSeconds: Int = 300 + init() { print("Init") var count = 0 @@ -185,12 +186,7 @@ class FlightState: ObservableObject { ) { _ in //print("Timer drain queue") //print("\(ADSBClient.msgarray.message_array.count)") - /*if ADSBClient.msgarray.message_array.count > 0 { - print(ADSBClient.msgarray.message_array.count) - for i in 0..<ADSBClient.msgarray.message_array.count { - print(ADSBClient.msgarray.message_array.popLast()!,terminator: "") - } - }*/ + //when there is data drain the queue and update flight states if ADSBClient.adsb_tag_stream.getCount() > 0 { //print("Process onse a second") for _ in 0..<ADSBClient.adsb_tag_stream.getCount() { @@ -209,6 +205,8 @@ class FlightState: ObservableObject { } } } + //if there is no data in queue, do tasks like remove expired flights + self.removeExpiredFlight() } /* DispatchQueue.global(qos: .background).async { @@ -327,14 +325,23 @@ class FlightState: ObservableObject { //loop over and if expired then remove func removeExpiredFlight() { - /* - for (address,el) in self.flight { - //if on the map more then 1 minute - if el.last_time_seen+60 < Int(Date().timeIntervalSince1970) { - self.flight.removeValue(forKey: address) - } + let now = Int(Date().timeIntervalSince1970) + flight.removeAll { now - $0.last_time_seen > expireAfterSeconds } + idx_flight.removeAll(keepingCapacity: true) + + //rebuild index + for (index, f) in flight.enumerated() { + idx_flight[f.ICAOaddress] = index } - */ + } + + func flightAge(_ ft: FlightTracker) -> Int { + let now: Int = Int(Date().timeIntervalSince1970) + return max(0, now - ft.last_time_seen) + } + + func isStaled(_ ft: FlightTracker) -> Bool { + return flightAge(ft) >= self.staleAfterSeconds } } |
