mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
Update detection sensor log query to update in real time
This commit is contained in:
parent
6c2e3cd316
commit
9c57bdd4c4
2 changed files with 4 additions and 19 deletions
|
|
@ -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<NSFetchRequestResult> = 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 []
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<MessageEntity>
|
||||
|
||||
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 }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue