Commit cdaa3f52fa318d6367a6c5b6cbc78c587ad2cf49

Authored by jason
1 parent da360092

feat:log alert

HDFwear/Home/Model/NewGpsModel.swift
@@ -37,12 +37,37 @@ class NewGpsModel: NSObject { @@ -37,12 +37,37 @@ class NewGpsModel: NSObject {
37 } 37 }
38 38
39 var exerciseType: Int = 0 39 var exerciseType: Int = 0
  40 + var startTimeInterval: TimeInterval = 0
40 var startTime: Date? 41 var startTime: Date?
41 var locationCount: Int = 0 42 var locationCount: Int = 0
42 var locations: [LocationPoint] = [] 43 var locations: [LocationPoint] = []
  44 +
  45 + override var description: String {
  46 + let dateFormatter = DateFormatter()
  47 + dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
  48 + dateFormatter.timeZone = TimeZone.current
  49 +
  50 + var description = "NewGpsModel\n"
  51 + description += "Exercise Type: \(exerciseType)\n"
  52 + description += "Start TimeInterval: \(startTimeInterval)\n"
  53 + description += "Start Time: \(dateFormatter.string(from: startTime ?? Date()))\n"
  54 + description += "Location Count: \(locationCount)\n"
  55 +
  56 + if !locations.isEmpty {
  57 + description += "Locations:\n"
  58 + for (index, location) in locations.enumerated() {
  59 + description += " Location \(index + 1):\n"
  60 + description += " Longitude: \(location.longitude)\n"
  61 + description += " Latitude: \(location.latitude)\n"
  62 + }
  63 + }
  64 +
  65 + return description
  66 + }
43 67
44 - init(exerciseType: Int, startTime: Date? = nil, locationCount: Int, locations: [LocationPoint]) { 68 + init(exerciseType: Int,startTimeInterval: TimeInterval, startTime: Date? = nil, locationCount: Int, locations: [LocationPoint]) {
45 self.exerciseType = exerciseType 69 self.exerciseType = exerciseType
  70 + self.startTimeInterval = startTimeInterval
46 self.startTime = startTime 71 self.startTime = startTime
47 self.locationCount = locationCount 72 self.locationCount = locationCount
48 self.locations = locations 73 self.locations = locations
@@ -55,6 +80,7 @@ class NewGpsModel: NSObject { @@ -55,6 +80,7 @@ class NewGpsModel: NSObject {
55 } 80 }
56 gpsModel.exerciseType = Int(data[0]) 81 gpsModel.exerciseType = Int(data[0])
57 let combinedUInt32 = data[1..<5].reduce(0) { ($0 << 8) + UInt32($1) } 82 let combinedUInt32 = data[1..<5].reduce(0) { ($0 << 8) + UInt32($1) }
  83 + gpsModel.startTimeInterval = TimeInterval(combinedUInt32)
58 gpsModel.startTime = Date(timeIntervalSince1970: TimeInterval(combinedUInt32)) 84 gpsModel.startTime = Date(timeIntervalSince1970: TimeInterval(combinedUInt32))
59 gpsModel.locationCount = Int(data[5..<9].reduce(0) { ($0 << 8) + UInt32($1) }) 85 gpsModel.locationCount = Int(data[5..<9].reduce(0) { ($0 << 8) + UInt32($1) })
60 var arr = [LocationPoint]() 86 var arr = [LocationPoint]()
HDFwear/Home/Model/NewSleepModel.swift
@@ -20,12 +20,15 @@ class NewSleepModel: NSObject { @@ -20,12 +20,15 @@ class NewSleepModel: NSObject {
20 20
21 struct SleepFragment { 21 struct SleepFragment {
22 var sleepStatus: NewSleepStatus 22 var sleepStatus: NewSleepStatus
  23 + var startTimeInterval: TimeInterval
23 var startTime: Date? 24 var startTime: Date?
24 var duration: UInt32 25 var duration: UInt32
25 } 26 }
26 27
27 struct NapFragment { 28 struct NapFragment {
  29 + var startTimeInterval: TimeInterval
28 var startTime: Date? 30 var startTime: Date?
  31 + var endTimeInterval: TimeInterval
29 var endTime: Date? 32 var endTime: Date?
30 var duration: UInt32 33 var duration: UInt32
31 } 34 }
@@ -35,6 +38,42 @@ class NewSleepModel: NSObject { @@ -35,6 +38,42 @@ class NewSleepModel: NSObject {
35 var sleepFragments: [SleepFragment] = [] 38 var sleepFragments: [SleepFragment] = []
36 var napFragments: [NapFragment] = [] 39 var napFragments: [NapFragment] = []
37 40
  41 + override var description: String {
  42 + let dateFormatter = DateFormatter()
  43 + dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
  44 + dateFormatter.timeZone = TimeZone.current
  45 +
  46 + var description = "NewSleepModel\n"
  47 + description += "Sleep Type: \(sleepType)\n"
  48 + description += "Sleep Fragment Count: \(sleepFragmentCount)\n"
  49 +
  50 +
  51 + if !sleepFragments.isEmpty {
  52 + description += "Sleep Fragments:\n"
  53 + for (index, fragment) in sleepFragments.enumerated() {
  54 + description += " Fragment \(index + 1):\n"
  55 + description += " Status: \(fragment.sleepStatus)\n"
  56 + description += " Start TimeInterval: \(fragment.startTimeInterval)\n"
  57 + description += " Start Time: \(dateFormatter.string(from: fragment.startTime ?? Date()))\n"
  58 + description += " Duration: \(fragment.duration) seconds\n"
  59 + }
  60 + }
  61 +
  62 + if !napFragments.isEmpty {
  63 + description += "Nap Fragments:\n"
  64 + for (index, fragment) in napFragments.enumerated() {
  65 + description += " Fragment \(index + 1):\n"
  66 + description += " Start TimeInterval: \(fragment.startTimeInterval)\n"
  67 + description += " Start Time: \(dateFormatter.string(from:fragment.startTime ?? Date()))\n"
  68 + description += " End TimeInterval: \(fragment.endTimeInterval)\n"
  69 + description += " End Time: \(dateFormatter.string(from:fragment.endTime ?? Date()))\n"
  70 + description += " Duration: \(fragment.duration) seconds\n"
  71 + }
  72 + }
  73 +
  74 + return description
  75 + }
  76 +
38 init(sleepType: NewSleepType, sleepFragmentCount: Int, sleepFragments: [SleepFragment], napFragments: [NapFragment]) { 77 init(sleepType: NewSleepType, sleepFragmentCount: Int, sleepFragments: [SleepFragment], napFragments: [NapFragment]) {
39 self.sleepType = sleepType 78 self.sleepType = sleepType
40 self.sleepFragmentCount = sleepFragmentCount 79 self.sleepFragmentCount = sleepFragmentCount
@@ -80,7 +119,7 @@ class NewSleepModel: NSObject { @@ -80,7 +119,7 @@ class NewSleepModel: NSObject {
80 let startTime = Date(timeIntervalSince1970: TimeInterval(combinedUInt32)) 119 let startTime = Date(timeIntervalSince1970: TimeInterval(combinedUInt32))
81 let duration = UInt32(data[index + 5..<index + 9].reduce(0) { ($0 << 8) + UInt32($1) }) 120 let duration = UInt32(data[index + 5..<index + 9].reduce(0) { ($0 << 8) + UInt32($1) })
82 121
83 - let fragment = SleepFragment(sleepStatus: sleepStatus, startTime: startTime, duration: duration) 122 + let fragment = SleepFragment(sleepStatus: sleepStatus,startTimeInterval: TimeInterval(combinedUInt32), startTime: startTime, duration: duration)
84 sleepFragments.append(fragment) 123 sleepFragments.append(fragment)
85 } 124 }
86 return sleepFragments 125 return sleepFragments
@@ -97,7 +136,7 @@ class NewSleepModel: NSObject { @@ -97,7 +136,7 @@ class NewSleepModel: NSObject {
97 let endTime = Date(timeIntervalSince1970: TimeInterval(endCombinedUInt32)) 136 let endTime = Date(timeIntervalSince1970: TimeInterval(endCombinedUInt32))
98 let duration = data[index + 8..<index + 12].reduce(0) { ($0 << 8) + UInt32($1) } 137 let duration = data[index + 8..<index + 12].reduce(0) { ($0 << 8) + UInt32($1) }
99 138
100 - let napFragment = NapFragment(startTime: startTime, endTime: endTime, duration: duration) 139 + let napFragment = NapFragment(startTimeInterval: TimeInterval(startCombinedUInt32),startTime: startTime, endTimeInterval: TimeInterval(endCombinedUInt32), endTime: endTime, duration: duration)
101 napFragments.append(napFragment) 140 napFragments.append(napFragment)
102 } 141 }
103 return napFragments 142 return napFragments
HDFwear/Mine/MineViewController.swift
@@ -443,60 +443,66 @@ extension MineViewController: UITableViewDataSource, UITableViewDelegate { @@ -443,60 +443,66 @@ extension MineViewController: UITableViewDataSource, UITableViewDelegate {
443 func fetchDataAlert () { 443 func fetchDataAlert () {
444 let alert = UIAlertController(title: "plz select fetch type", message: nil, preferredStyle: .actionSheet) 444 let alert = UIAlertController(title: "plz select fetch type", message: nil, preferredStyle: .actionSheet)
445 445
446 - let archiveAction9 = UIAlertAction(title: "getSleepHistoryData", style: .default) { action in 446 + let archiveAction9 = UIAlertAction(title: "getSleepHistoryData", style: .default) {[weak self] action in
447 BluetoothManager.shared.getSleepHistoryData(option: .now) { sleepModel, error in 447 BluetoothManager.shared.getSleepHistoryData(option: .now) { sleepModel, error in
448 if error != nil { 448 if error != nil {
449 print("getSleepHistoryData" + (error?.description ?? "")) 449 print("getSleepHistoryData" + (error?.description ?? ""))
450 }else { 450 }else {
  451 + self?.showDetailAlert(msg: sleepModel?.description)
451 print("getSleepHistoryData success") 452 print("getSleepHistoryData success")
452 } 453 }
453 } 454 }
454 } 455 }
455 - let archiveAction10 = UIAlertAction(title: "getBloodOxygenHistoryData", style: .default) { action in 456 + let archiveAction10 = UIAlertAction(title: "getBloodOxygenHistoryData", style: .default) {[weak self] action in
456 BluetoothManager.shared.getBloodOxygenHistoryData() { boArray, error in 457 BluetoothManager.shared.getBloodOxygenHistoryData() { boArray, error in
457 if error != nil { 458 if error != nil {
458 print("getBloodOxygenHistoryData" + (error?.description ?? "")) 459 print("getBloodOxygenHistoryData" + (error?.description ?? ""))
459 }else { 460 }else {
  461 + self?.showDetailAlert(msg: boArray.description)
460 print("getBloodOxygenHistoryData success") 462 print("getBloodOxygenHistoryData success")
461 } 463 }
462 } 464 }
463 } 465 }
464 466
465 - let archiveAction14 = UIAlertAction(title: "getHeartRateHistoryData", style: .default) { action in  
466 - BluetoothManager.shared.getHeartRateHistoryData() { boArray, error in 467 + let archiveAction14 = UIAlertAction(title: "getHeartRateHistoryData", style: .default) {[weak self] action in
  468 + BluetoothManager.shared.getHeartRateHistoryData() { hrArray, error in
467 if error != nil { 469 if error != nil {
468 print("getHeartRateHistoryData" + (error?.description ?? "")) 470 print("getHeartRateHistoryData" + (error?.description ?? ""))
469 }else { 471 }else {
  472 + self?.showDetailAlert(msg: hrArray.description)
470 print("getHeartRateHistoryData success") 473 print("getHeartRateHistoryData success")
471 } 474 }
472 } 475 }
473 } 476 }
474 477
475 - let archiveAction15 = UIAlertAction(title: "getStepHistoryData", style: .default) { action in  
476 - BluetoothManager.shared.getStepHistoryData() { boArray, error in 478 + let archiveAction15 = UIAlertAction(title: "getStepHistoryData", style: .default) {[weak self] action in
  479 + BluetoothManager.shared.getStepHistoryData() { sArray, error in
477 if error != nil { 480 if error != nil {
478 print("getStepHistoryData" + (error?.description ?? "")) 481 print("getStepHistoryData" + (error?.description ?? ""))
479 }else { 482 }else {
  483 + self?.showDetailAlert(msg: sArray.description)
480 print("getStepHistoryData success") 484 print("getStepHistoryData success")
481 } 485 }
482 } 486 }
483 } 487 }
484 488
485 - let archiveAction16 = UIAlertAction(title: "getTrainHistoryData", style: .default) { action in  
486 - BluetoothManager.shared.getTrainHistoryData() { boArray, error in 489 + let archiveAction16 = UIAlertAction(title: "getTrainHistoryData", style: .default) {[weak self] action in
  490 + BluetoothManager.shared.getTrainHistoryData() { tArray, error in
487 if error != nil { 491 if error != nil {
488 print("getTrainHistoryData" + (error?.description ?? "")) 492 print("getTrainHistoryData" + (error?.description ?? ""))
489 }else { 493 }else {
  494 + self?.showDetailAlert(msg: tArray?.description)
490 print("getTrainHistoryData success") 495 print("getTrainHistoryData success")
491 } 496 }
492 } 497 }
493 } 498 }
494 499
495 - let archiveAction17 = UIAlertAction(title: "getPressureHistoryData", style: .default) { action in  
496 - BluetoothManager.shared.getPressureHistoryData() { boArray, error in 500 + let archiveAction17 = UIAlertAction(title: "getPressureHistoryData", style: .default) {[weak self] action in
  501 + BluetoothManager.shared.getPressureHistoryData() { pArray, error in
497 if error != nil { 502 if error != nil {
498 print("getPressureHistoryData" + (error?.description ?? "")) 503 print("getPressureHistoryData" + (error?.description ?? ""))
499 }else { 504 }else {
  505 + self?.showDetailAlert(msg: pArray.description)
500 print("getPressureHistoryData success") 506 print("getPressureHistoryData success")
501 } 507 }
502 } 508 }
@@ -512,11 +518,12 @@ extension MineViewController: UITableViewDataSource, UITableViewDelegate { @@ -512,11 +518,12 @@ extension MineViewController: UITableViewDataSource, UITableViewDelegate {
512 } 518 }
513 } 519 }
514 520
515 - let archiveAction101 = UIAlertAction(title: "newGetGpsData", style: .default) { action in 521 + let archiveAction101 = UIAlertAction(title: "newGetGpsData", style: .default) {[weak self] action in
516 BluetoothManager.shared.newGetGpsData() {gpsModel, error in 522 BluetoothManager.shared.newGetGpsData() {gpsModel, error in
517 if error != nil { 523 if error != nil {
518 print("newGetGpsData" + (error?.description ?? "")) 524 print("newGetGpsData" + (error?.description ?? ""))
519 }else { 525 }else {
  526 + self?.showDetailAlert(msg: gpsModel?.description)
520 print("newGetGpsData success") 527 print("newGetGpsData success")
521 } 528 }
522 } 529 }
@@ -536,4 +543,20 @@ extension MineViewController: UITableViewDataSource, UITableViewDelegate { @@ -536,4 +543,20 @@ extension MineViewController: UITableViewDataSource, UITableViewDelegate {
536 present(alert, animated: true, completion: nil) 543 present(alert, animated: true, completion: nil)
537 } 544 }
538 545
  546 + func showDetailAlert(msg: String? = "") {
  547 + let alert = UIAlertController(title: "info", message: msg, preferredStyle: .alert)
  548 +// let archiveAction = UIAlertAction(title: "newGetGpsData", style: .default) { action in
  549 +// BluetoothManager.shared.newGetGpsData() {gpsModel, error in
  550 +// if error != nil {
  551 +// print("newGetGpsData" + (error?.description ?? ""))
  552 +// }else {
  553 +// print("newGetGpsData success")
  554 +// }
  555 +// }
  556 +// }
  557 +// alert.addAction(archiveAction)
  558 +
  559 + alert.addAction(UIAlertAction(title: "确定", style: .destructive, handler: nil))
  560 + present(alert, animated: true, completion: nil)
  561 + }
539 } 562 }