From 9c57bdd4c427c12bc530b9fc23e6b7d16f02f91f Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Wed, 29 Nov 2023 23:01:51 -0800 Subject: [PATCH] Update detection sensor log query to update in real time --- Meshtastic/Persistence/QueryCoreData.swift | 18 ------------------ .../Views/Nodes/DetectionSensorLog.swift | 5 ++++- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/Meshtastic/Persistence/QueryCoreData.swift b/Meshtastic/Persistence/QueryCoreData.swift index fa200d8a..32cbffc0 100644 --- a/Meshtastic/Persistence/QueryCoreData.swift +++ b/Meshtastic/Persistence/QueryCoreData.swift @@ -82,21 +82,3 @@ public func getWaypoint(id: Int64, context: NSManagedObjectContext) -> WaypointE } return WaypointEntity(context: context) } - -public func getDetectionSensorMessages(nodeNum: Int64?, context: NSManagedObjectContext) -> [MessageEntity] { - - let fetchDetectionMessagesPredicate: NSFetchRequest = NSFetchRequest.init(entityName: "MessageEntity") - fetchDetectionMessagesPredicate.predicate = NSPredicate(format: "portNum == %d", Int32(PortNum.detectionSensorApp.rawValue)) - - do { - let fetched = try context.fetch(fetchDetectionMessagesPredicate) as? [MessageEntity] ?? [] - if nodeNum == nil { - return fetched.reversed() - } - return fetched.filter { message in - return message.fromUser?.num == nodeNum! - }.reversed() - } catch { - return [] - } -} diff --git a/Meshtastic/Views/Nodes/DetectionSensorLog.swift b/Meshtastic/Views/Nodes/DetectionSensorLog.swift index b6d13c99..27fe7198 100644 --- a/Meshtastic/Views/Nodes/DetectionSensorLog.swift +++ b/Meshtastic/Views/Nodes/DetectionSensorLog.swift @@ -15,10 +15,13 @@ struct DetectionSensorLog: View { @State var isExporting = false @State var exportString = "" @ObservedObject var node: NodeInfoEntity + + @FetchRequest(sortDescriptors: [NSSortDescriptor(key: "messageTimestamp", ascending: false)], + predicate: NSPredicate(format: "portNum == %d", Int32(PortNum.detectionSensorApp.rawValue)), animation: .none) + private var detections: FetchedResults var body: some View { let oneDayAgo = Calendar.current.date(byAdding: .day, value: -1, to: Date()) - let detections = getDetectionSensorMessages(nodeNum: node.num, context: context) let chartData = detections .filter { $0.timestamp >= oneDayAgo! } .sorted { $0.timestamp < $1.timestamp }