From cdaa3f52fa318d6367a6c5b6cbc78c587ad2cf49 Mon Sep 17 00:00:00 2001 From: jason Date: Thu, 11 Jan 2024 13:07:51 +0800 Subject: [PATCH] feat:log alert --- HDFwear/Home/Model/NewGpsModel.swift | 28 +++++++++++++++++++++++++++- HDFwear/Home/Model/NewSleepModel.swift | 43 +++++++++++++++++++++++++++++++++++++++++-- HDFwear/Mine/MineViewController.swift | 45 ++++++++++++++++++++++++++++++++++----------- 3 files changed, 102 insertions(+), 14 deletions(-) diff --git a/HDFwear/Home/Model/NewGpsModel.swift b/HDFwear/Home/Model/NewGpsModel.swift index e97f24b..d4eee33 100644 --- a/HDFwear/Home/Model/NewGpsModel.swift +++ b/HDFwear/Home/Model/NewGpsModel.swift @@ -37,12 +37,37 @@ class NewGpsModel: NSObject { } var exerciseType: Int = 0 + var startTimeInterval: TimeInterval = 0 var startTime: Date? var locationCount: Int = 0 var locations: [LocationPoint] = [] + + override var description: String { + let dateFormatter = DateFormatter() + dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss" + dateFormatter.timeZone = TimeZone.current + + var description = "NewGpsModel\n" + description += "Exercise Type: \(exerciseType)\n" + description += "Start TimeInterval: \(startTimeInterval)\n" + description += "Start Time: \(dateFormatter.string(from: startTime ?? Date()))\n" + description += "Location Count: \(locationCount)\n" + + if !locations.isEmpty { + description += "Locations:\n" + for (index, location) in locations.enumerated() { + description += " Location \(index + 1):\n" + description += " Longitude: \(location.longitude)\n" + description += " Latitude: \(location.latitude)\n" + } + } + + return description + } - init(exerciseType: Int, startTime: Date? = nil, locationCount: Int, locations: [LocationPoint]) { + init(exerciseType: Int,startTimeInterval: TimeInterval, startTime: Date? = nil, locationCount: Int, locations: [LocationPoint]) { self.exerciseType = exerciseType + self.startTimeInterval = startTimeInterval self.startTime = startTime self.locationCount = locationCount self.locations = locations @@ -55,6 +80,7 @@ class NewGpsModel: NSObject { } gpsModel.exerciseType = Int(data[0]) let combinedUInt32 = data[1..<5].reduce(0) { ($0 << 8) + UInt32($1) } + gpsModel.startTimeInterval = TimeInterval(combinedUInt32) gpsModel.startTime = Date(timeIntervalSince1970: TimeInterval(combinedUInt32)) gpsModel.locationCount = Int(data[5..<9].reduce(0) { ($0 << 8) + UInt32($1) }) var arr = [LocationPoint]() diff --git a/HDFwear/Home/Model/NewSleepModel.swift b/HDFwear/Home/Model/NewSleepModel.swift index fde70d4..4d753dd 100644 --- a/HDFwear/Home/Model/NewSleepModel.swift +++ b/HDFwear/Home/Model/NewSleepModel.swift @@ -20,12 +20,15 @@ class NewSleepModel: NSObject { struct SleepFragment { var sleepStatus: NewSleepStatus + var startTimeInterval: TimeInterval var startTime: Date? var duration: UInt32 } struct NapFragment { + var startTimeInterval: TimeInterval var startTime: Date? + var endTimeInterval: TimeInterval var endTime: Date? var duration: UInt32 } @@ -35,6 +38,42 @@ class NewSleepModel: NSObject { var sleepFragments: [SleepFragment] = [] var napFragments: [NapFragment] = [] + override var description: String { + let dateFormatter = DateFormatter() + dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss" + dateFormatter.timeZone = TimeZone.current + + var description = "NewSleepModel\n" + description += "Sleep Type: \(sleepType)\n" + description += "Sleep Fragment Count: \(sleepFragmentCount)\n" + + + if !sleepFragments.isEmpty { + description += "Sleep Fragments:\n" + for (index, fragment) in sleepFragments.enumerated() { + description += " Fragment \(index + 1):\n" + description += " Status: \(fragment.sleepStatus)\n" + description += " Start TimeInterval: \(fragment.startTimeInterval)\n" + description += " Start Time: \(dateFormatter.string(from: fragment.startTime ?? Date()))\n" + description += " Duration: \(fragment.duration) seconds\n" + } + } + + if !napFragments.isEmpty { + description += "Nap Fragments:\n" + for (index, fragment) in napFragments.enumerated() { + description += " Fragment \(index + 1):\n" + description += " Start TimeInterval: \(fragment.startTimeInterval)\n" + description += " Start Time: \(dateFormatter.string(from:fragment.startTime ?? Date()))\n" + description += " End TimeInterval: \(fragment.endTimeInterval)\n" + description += " End Time: \(dateFormatter.string(from:fragment.endTime ?? Date()))\n" + description += " Duration: \(fragment.duration) seconds\n" + } + } + + return description + } + init(sleepType: NewSleepType, sleepFragmentCount: Int, sleepFragments: [SleepFragment], napFragments: [NapFragment]) { self.sleepType = sleepType self.sleepFragmentCount = sleepFragmentCount @@ -80,7 +119,7 @@ class NewSleepModel: NSObject { let startTime = Date(timeIntervalSince1970: TimeInterval(combinedUInt32)) let duration = UInt32(data[index + 5..