// // 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 } /// 获取运动所在的年月 2018年5月 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") } }