You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

254 lines
7.9 KiB

//
// DataBaseModel.swift
// Lookfit
//
// Created by lemo. on 2020/6/7.
// Copyright © 2020 Sheldon. All rights reserved.
//
import Foundation
class StepModel: BaseJsonModel {
// mac
var macID: String = ""
/// 2017-01-16
var dataDate: String = ""
///
var stepNumber: Int = 0
/// ()
var stepDistance: Int = 0
/// ()
var stepCalorie: Float = 0
/// ()
var stepDuration: Int = 0
/// step|cal|m|,...
var stepDetails: String = "0|0.0|0.0|0,0|0.0|0.0|1,0|0.0|0.0|2,0|0.0|0.0|3,0|0.0|0.0|4,0|0.0|0.0|5,0|0.0|0.0|6,0|0.0|0.0|7,0|0.0|0.0|8,0|0.0|0.0|9,0|0.0|0.0|10,0|0.0|0.0|11,0|0.0|0.0|12,0|0.0|0.0|13,0|0.0|0.0|14,0|0.0|0.0|15,0|0.0|0.0|16,0|0.0|0.0|17,0|0.0|0.0|18,0|0.0|0.0|19,0|0.0|0.0|20,0|0.0|0.0|21,0|0.0|0.0|22,0|0.0|0.0|23"
}
class SleepModel: BaseJsonModel {
// mac
var macID: String = ""
/// (2018-06-20)
var dataDate: String = ""
///
var deepSleepDuration: Int = 0
///
var lightSleepDuration: Int = 0
///
var awakeDuration: Int = 0
///
var totalSleepDuration: Int = 0
/// (2020-04-16 21:04)
var fallingSleepTimes: String = ""
///
var awakeTimes: String = ""
///
var awakeNumber: Int = 0
/// (|||,..) 0: 1 2
var sleepDetails: String = ""
func getToatlSleepTimeStr() -> String {
return "\(totalSleepDuration / 60)h \(totalSleepDuration % 60)m"
}
}
class HeartRateModel: BaseJsonModel {
// mac
var macID: String = ""
/// (2018-06-20)
var dataDate: String = ""
///
var heartMax: Int = 0
///
var heartMin: Int = 0
///
var heartAvg: Int = 0
/// |,...
var heartDetails: String = ""
}
class TemperatureModel: BaseJsonModel {
// mac
var macID: String = ""
/// (2018-06-20)
var dataDate: String = ""
///
var temperatureMax: Double = 0
///
var temperatureMin: Double = 0
///
var temperatureAvg: Double = 0
/// |,...
var temperatureDetails: String = ""
}
class BloodPressureModel: BaseJsonModel {
// mac
var macID: String = ""
/// (2018-06-20)
var dataDate: String = ""
///
var sbpMax: Int = 0
///
var sbpMin: Int = 0
///
var sbpAvg: Int = 0
///
var dbpMax: Int = 0
///
var dbpMin: Int = 0
///
var dbpAvg: Int = 0
/// ||,...
var details: String = ""
}
class BloodOxygenModel: BaseJsonModel {
// mac
var macID: String = ""
/// (2018-06-20)
var dataDate: String = ""
///
var bloodOxygenMax: Int = 0
///
var bloodOxygenMin: Int = 0
///
var bloodOxygenAvg: Int = 0
/// |,...
var details: String = ""
}
class SportModel: BaseJsonModel {
/// mac
var macID: String = ""
/// (2017-12-17 10:20:20)
var dataDate: String = ""
///
var verison: Int = 0
/// 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21.22.
var sportType: Int = 0
/// ()
var duration: Int = 0
/// ()
var distance: Int = 0
///
var calorie: Float = 0
/// (使)
var stepNumber: Int = 0
///
var heartMax: Int = 0
///
var heartAvg: Int = 0
///
var heartMin: Int = 0
/// ()
var stepFrequencyMax: Int = 0
/// (SWOLF)
var stepFrequencyAvg: Int = 0
/// (姿)
var stepFrequencyMin: Int = 0
/// (s)
var paceMax: Int = 0
/// (s)
var paceAvg: Int = 0
/// (s)
var paceMin: Int = 0
///
var startAltitude: Int = 0
///
var endAltitude: Int = 0
/// GPS
var gpsCount: Int = 0
///
var kmCount: Int = 0
///
var stepCount: Int = 0
///
var heartCount: Int = 0
///
var trainDetailCount: Int = 0
/// GPS
var gpsTimestamp: Int = 0
/// GPS(|||,...)
var gpsDeatail: String = ""
/// (|||,...)
var kmDetail: String = ""
///
var stepTimestamp: Int = 0
/// (||m,...)
var stepDetail: String = ""
/// HRS
var hrsTimestamp: Int = 0
/// HRS((5S)|0)
var hrsDetail: String = ""
/// (|||||)
var swimmingDetail: String = ""
// MARK:-
/// (/)
var stepFrequency: Int {
if stepNumber <= 0 {
return 0
}
let temp = Float(stepNumber) / (Float(duration) / 60.0)
return lroundf(temp + 0.5)
}
/// ()
var stride: Int {
if stepNumber <= 0 {
return 0
}
return (distance * 100) / stepNumber
}
}
// MARK:-
extension SportModel {
/// hh:mm:ss
var durationStr: String {
return String(format:"%02d:%02d:%02d",duration / 3600, duration % 3600 / 60, duration % 60)
}
///
var getSportType: SportType {
return SportType(rawValue: sportType) ?? .walkTraining
}
/// 20185
func getSportYearMonth() -> String {
let date = DateClass.getTimeStrToDate(formatStr: "yyyy-MM-dd HH:mm:ss", timeStr: dataDate)
let nowYear = Date().year()
let year = MultiLanguageKey.year.localized
let month = MultiLanguageKey.month.localized
if date.year() == nowYear {
return DateClass.timestampToStr(Int(date.timeIntervalSince1970), formatStr: "MM") + month
}
return DateClass.timestampToStr(Int(date.timeIntervalSince1970), formatStr: "yyyy") + year + DateClass.timestampToStr(Int(date.timeIntervalSince1970), formatStr: "MM") + month
}
//
var avgPaceStr: String {
let metric = UserDefaultsManager.getUserInfo()?.metricUnit ?? 0
let realDistance = metric == 0 ? Double(distance) * 0.001 : Double(distance) * 0.001 * 0.62137
let pace = (Double(duration) / 60.0) / realDistance
return String(format: "%.1f", pace)
}
//
var avgSpeedStr: String {
let metric = UserDefaultsManager.getUserInfo()?.metricUnit ?? 0
let realDistance = metric == 0 ? Double(distance) * 0.001 : Double(distance) * 0.001 * 0.62137
let speed = realDistance / (Double(duration) / 3600.0)
return String(format: "%.1f", speed)
}
//
var timestamp: Int {
return DateClass.timeStrToTimestamp(dataDate, formatStr: "yyyy-MM-dd HH:mm:ss")
}
}