NativeHealthDataUploader.swift
22.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
import Foundation
enum NativeHealthUploadConfiguration {
/// Process-lifetime throttle. Each health data type can start at most one
/// upload request during this interval.
static let minimumTriggerInterval: TimeInterval = 60
}
struct NativeHealthUploadSummary {
let commonUploadSuccess: Bool
let sleepUploadSuccess: Bool
let errorMessage: String?
let commonCount: Int
let sleepCount: Int
}
enum NativeHealthUploadError: LocalizedError {
case invalidServerURL
case missingAccessToken
case invalidResponse
case requestFailed(path: String, statusCode: Int, body: String?)
var errorDescription: String? {
switch self {
case .invalidServerURL:
return "健康数据上传地址无效"
case .missingAccessToken:
return "缺少登录态,无法上传健康数据"
case .invalidResponse:
return "健康数据上传接口响应无效"
case .requestFailed(let path, let statusCode, let body):
return "健康数据接口请求失败:\(path), HTTP \(statusCode)\(body.map { ", \($0)" } ?? "")"
}
}
}
/// Uploads Apple Health data to DoubleFeel.
///
/// Data reading stays in `HealthDataReader` / `HealthKitService`; this type only
/// owns upload requests. Upload boundaries always come from the server's
/// `/data_upload/common/` response.
actor NativeHealthDataUploader {
static let shared = NativeHealthDataUploader()
private let session: URLSession
private let defaultUploadTimeWeek = 1
private let firstUploadYear = 2
private let uploadBatchSize = 500
private var lastUploadTriggerDates: [NativeHealthDataType: Date] = [:]
init(session: URLSession = .shared) {
self.session = session
}
func uploadAll(service: HealthKitService = .shared) async -> NativeHealthUploadSummary {
guard AppShared.shared.token?.isEmpty == false else {
let message = NativeHealthUploadError.missingAccessToken.localizedDescription
DebugLogger.debugLog("uploadAll skipped, user is not logged in")
return NativeHealthUploadSummary(
commonUploadSuccess: false,
sleepUploadSuccess: false,
errorMessage: message,
commonCount: 0,
sleepCount: 0
)
}
var commonCount = 0
var sleepCount = 0
var commonUploadSuccess = true
var sleepUploadSuccess = true
var errorMessages: [String] = []
DebugLogger.debugLog("uploadAll started ")
do {
let uploadTimeList = try await processLastUploadTime()
for type in Self.commonUploadTypes {
let result = await upload(
type: type,
uploadTimeList: uploadTimeList,
trigger: .full,
service: service
)
commonCount += result.uploadedCount
if !result.success {
commonUploadSuccess = false
if let errorMessage = result.errorMessage {
errorMessages.append(errorMessage)
}
}
}
let sleepResult = await upload(
type: .sleep,
uploadTimeList: uploadTimeList,
trigger: .full,
service: service
)
sleepCount = sleepResult.uploadedCount
sleepUploadSuccess = sleepResult.success
if let errorMessage = sleepResult.errorMessage {
errorMessages.append(errorMessage)
}
let activityTargetUploaded = await uploadActivityTargetIfNeeded(
uploadTimeList: uploadTimeList,
service: service
)
if !activityTargetUploaded.success {
commonUploadSuccess = false
if let errorMessage = activityTargetUploaded.errorMessage {
errorMessages.append(errorMessage)
}
}
} catch {
commonUploadSuccess = false
sleepUploadSuccess = false
errorMessages.append(error.localizedDescription)
DebugLogger.debugLog("uploadAll failed before per-type upload, error=\(error.localizedDescription)")
}
DebugLogger.debugLog("uploadAll finished, commonSuccess=\(commonUploadSuccess), sleepSuccess=\(sleepUploadSuccess), commonCount=\(commonCount), sleepCount=\(sleepCount), error=\(errorMessages.isEmpty ? "<nil>" : errorMessages.joined(separator: " | "))")
return NativeHealthUploadSummary(
commonUploadSuccess: commonUploadSuccess,
sleepUploadSuccess: sleepUploadSuccess,
errorMessage: errorMessages.isEmpty ? nil : errorMessages.joined(separator: "\n"),
commonCount: commonCount,
sleepCount: sleepCount
)
}
func upload(type: NativeHealthDataType, service: HealthKitService = .shared) async -> Bool {
guard AppShared.shared.token?.isEmpty == false else {
DebugLogger.debugLog("upload(\(type.debugName)) skipped, user is not logged in")
return false
}
do {
let uploadTimeList = try await processLastUploadTime()
return await upload(
type: type,
uploadTimeList: uploadTimeList,
trigger: .manual,
service: service
).success
} catch {
DebugLogger.debugLog("upload(\(type.debugName)) failed to process last upload time, error=\(error.localizedDescription)")
DebugLogger.debugLog("Health upload failed to process last upload time: \(error.localizedDescription)")
return false
}
}
func uploadObservedChange(
types: [NativeHealthDataType],
includeActivityTarget: Bool,
service: HealthKitService = .shared
) async -> Bool {
guard AppShared.shared.token?.isEmpty == false else {
DebugLogger.debugLog("observed change skipped, user is not logged in")
return false
}
do {
let uploadTimeList = try await processLastUploadTime()
var success = true
var uploadedNewData = false
for type in types {
let result = await upload(
type: type,
uploadTimeList: uploadTimeList,
trigger: .observer,
service: service
)
success = success && result.success
uploadedNewData = uploadedNewData || result.uploadedCount > 0
}
if includeActivityTarget && uploadedNewData {
let result = await uploadActivityTargetIfNeeded(
uploadTimeList: uploadTimeList,
service: service
)
success = success && result.success
}
return success
} catch {
DebugLogger.debugLog("observed change upload failed, error=\(error.localizedDescription)")
return false
}
}
}
private extension NativeHealthDataUploader {
struct UploadTaskResult {
let success: Bool
let uploadedCount: Int
let errorMessage: String?
}
enum UploadTrigger: String {
case full
case observer
case manual
}
static let commonUploadTypes: [NativeHealthDataType] = [
.hrv,
.heartRate,
.walkingHeartRate,
.restingHeartRate,
.sleepingHeartRate,
.oxygenSaturation,
.activeEnergy,
.exercise,
.stand,
.steps,
.sleepingWristTemperature,
.respiratoryRate,
.irregularHeartRhythm,
]
func upload(
type: NativeHealthDataType,
uploadTimeList: NativeHealthUploadTimeList,
trigger: UploadTrigger,
service: HealthKitService
) async -> UploadTaskResult {
guard type != .unknown,
let startUploadDate = uploadTimeList.latestDataTime(for: type) else {
DebugLogger.debugLog("[\(type.debugName)] skipped, no upload start date")
return UploadTaskResult(success: true, uploadedCount: 0, errorMessage: nil)
}
let endUploadDate = Date()
DebugLogger.debugLog(
"[\(type.debugName)] upload started, trigger=\(trigger.rawValue), range=\(Self.debugDateFormatter.string(from: startUploadDate)) -> \(Self.debugDateFormatter.string(from: endUploadDate))"
)
guard endUploadDate >= startUploadDate else {
DebugLogger.debugLog("[\(type.debugName)] upload failed, start date is later than end date")
return UploadTaskResult(
success: false,
uploadedCount: 0,
errorMessage: "健康数据上传开始时间晚于结束时间:\(type)"
)
}
do {
switch type {
case .sleep:
DebugLogger.debugLog("[\(type.debugName)] reading sleep data")
let data = try await service.fetchSleepData(startDate: startUploadDate, endDate: endUploadDate)
.filter { $0.toTime > startUploadDate.timeIntervalSince1970 }
.sorted { $0.toTime < $1.toTime }
debugLogTimeComparison(
type: type,
serverTime: startUploadDate.timeIntervalSince1970,
newestTime: data.map(\.toTime).max()
)
DebugLogger.debugLog("[\(type.debugName)] read finished, count=\(data.count)")
guard !data.isEmpty else {
DebugLogger.debugLog("[\(type.debugName)] no data; server upload time remains unchanged")
return UploadTaskResult(success: true, uploadedCount: 0, errorMessage: nil)
}
guard allowUploadTrigger(for: type) else {
return UploadTaskResult(success: true, uploadedCount: 0, errorMessage: nil)
}
DebugLogger.debugLog("[\(type.debugName)] uploading, count=\(data.count)")
try await uploadSleep(data)
notifyFlutterUpload(
type: type,
timestamp: data.map(\.toTime).max() ?? endUploadDate.timeIntervalSince1970
)
DebugLogger.debugLog("[\(type.debugName)] upload success, count=\(data.count); next boundary will come from server")
return UploadTaskResult(success: true, uploadedCount: data.count, errorMessage: nil)
default:
DebugLogger.debugLog("[\(type.debugName)] reading common data")
let data = try await fetchCommonData(
type: type,
startDate: startUploadDate,
endDate: endUploadDate,
service: service
)
.filter { $0.time > startUploadDate.timeIntervalSince1970 }
.sorted { $0.time < $1.time }
debugLogTimeComparison(
type: type,
serverTime: startUploadDate.timeIntervalSince1970,
newestTime: data.map(\.time).max()
)
DebugLogger.debugLog("[\(type.debugName)] read finished, count=\(data.count)")
guard !data.isEmpty else {
DebugLogger.debugLog("[\(type.debugName)] no data; server upload time remains unchanged")
return UploadTaskResult(success: true, uploadedCount: 0, errorMessage: nil)
}
guard allowUploadTrigger(for: type) else {
return UploadTaskResult(success: true, uploadedCount: 0, errorMessage: nil)
}
DebugLogger.debugLog("[\(type.debugName)] uploading, count=\(data.count)")
try await uploadCommon(data)
notifyFlutterUpload(
type: type,
timestamp: data.map(\.time).max() ?? endUploadDate.timeIntervalSince1970
)
DebugLogger.debugLog("[\(type.debugName)] upload success, count=\(data.count); next boundary will come from server")
return UploadTaskResult(success: true, uploadedCount: data.count, errorMessage: nil)
}
} catch {
DebugLogger.debugLog("[\(type.debugName)] upload failed, error=\(error.localizedDescription)")
return UploadTaskResult(
success: false,
uploadedCount: 0,
errorMessage: "健康数据上传失败:\(type), \(error.localizedDescription)"
)
}
}
func fetchCommonData(
type: NativeHealthDataType,
startDate: Date,
endDate: Date,
service: HealthKitService
) async throws -> [NativeHealthDataPoint] {
switch type {
case .hrv:
return try await service.fetchHrvData(startDate: startDate, endDate: endDate)
case .heartRate:
return try await service.fetchHeartRateData(startDate: startDate, endDate: endDate)
case .walkingHeartRate:
return try await service.fetchWalkingHeartRateData(startDate: startDate, endDate: endDate)
case .restingHeartRate:
return try await service.fetchRestingHeartRateData(startDate: startDate, endDate: endDate)
case .sleepingHeartRate:
return try await service.fetchSleepingHeartRateData(startDate: startDate, endDate: endDate)
case .oxygenSaturation:
return try await service.fetchOxygenSaturationData(startDate: startDate, endDate: endDate)
case .activeEnergy:
return try await service.fetchActiveEnergyData(startDate: startDate, endDate: endDate)
case .exercise:
return try await service.fetchExerciseData(startDate: startDate, endDate: endDate)
case .stand:
return try await service.fetchStandData(startDate: startDate, endDate: endDate)
case .steps:
return try await service.fetchStepCountData(startDate: startDate, endDate: endDate)
case .sleepingWristTemperature:
return try await service.fetchSleepingWristTemperatureData(startDate: startDate, endDate: endDate)
case .respiratoryRate:
return try await service.fetchRespiratoryRateData(startDate: startDate, endDate: endDate)
case .irregularHeartRhythm:
return try await service.fetchIrregularHeartRhythmData(startDate: startDate, endDate: endDate)
case .unknown, .sleep:
return []
}
}
func uploadActivityTargetIfNeeded(
uploadTimeList: NativeHealthUploadTimeList,
service: HealthKitService
) async -> UploadTaskResult {
let startDate = uploadTimeList.latestDataTime(for: .activeEnergy)
?? Calendar.current.date(byAdding: .weekOfYear, value: -defaultUploadTimeWeek, to: Date())
?? Date(timeIntervalSinceNow: -7 * 24 * 60 * 60)
let endDate = Date()
DebugLogger.debugLog(
"[activityTarget] upload started, range=\(Self.debugDateFormatter.string(from: startDate)) -> \(Self.debugDateFormatter.string(from: endDate))"
)
do {
guard let target = try await service.fetchActivityTargetData(startDate: startDate, endDate: endDate),
target.move != nil || target.stand != nil else {
DebugLogger.debugLog("[activityTarget] no target data")
return UploadTaskResult(success: true, uploadedCount: 0, errorMessage: nil)
}
DebugLogger.debugLog("[activityTarget] uploading, body=\(target.uploadBodyForDebug)")
try await uploadActivityTarget(target)
DebugLogger.debugLog("[activityTarget] upload success")
return UploadTaskResult(success: true, uploadedCount: 1, errorMessage: nil)
} catch {
DebugLogger.debugLog("[activityTarget] upload failed, error=\(error.localizedDescription)")
return UploadTaskResult(
success: false,
uploadedCount: 0,
errorMessage: "活动目标上传失败:\(error.localizedDescription)"
)
}
}
func processLastUploadTime() async throws -> NativeHealthUploadTimeList {
let serverTimeList = try await fetchLastUploadTime()
var resultTimeList: [NativeHealthUploadTimeList.HealthUploadTime] = []
DebugLogger.debugLog("processLastUploadTime started, source=server")
let twoYearsAgo = Calendar.current.date(byAdding: .year, value: -firstUploadYear, to: Date())
?? Date(timeIntervalSinceNow: -TimeInterval(firstUploadYear * 365 * 24 * 60 * 60))
let twoYearsAgoMidnight = Calendar.current.startOfDay(for: twoYearsAgo).timeIntervalSince1970
for type in NativeHealthDataType.allCases where type != .unknown {
let serverTime = serverTimeList.latestTimeInterval(for: type)
let finalTime = serverTime ?? twoYearsAgoMidnight
DebugLogger.debugLog(
"[\(type.debugName)] server start time=\(serverTime.map { Self.debugDateFormatter.string(from: Date(timeIntervalSince1970: $0)) } ?? "<missing; first upload uses two years>"), resolved=\(Self.debugDateFormatter.string(from: Date(timeIntervalSince1970: finalTime)))"
)
resultTimeList.append(
NativeHealthUploadTimeList.HealthUploadTime(
dataType: type,
latestDataTime: finalTime
)
)
}
return NativeHealthUploadTimeList(latestDataTimeList: resultTimeList)
}
func uploadCommon(_ data: [NativeHealthDataPoint]) async throws {
for batch in data.chunked(into: uploadBatchSize) {
batch.forEach { point in
DebugLogger.debugLog(
"[iOS][upload] dataType=\(point.dataType.rawValue)(\(point.dataType.debugName)), time=\(debugTimestamp(point.time)), unix=\(Int64(point.time)), value=\(point.value)"
)
}
let list = batch.map {
[
"data_type": $0.dataType.rawValue,
"time": $0.time,
"value": $0.value,
] as [String: Any]
}
try await request(path: "/client/doublefeel/health/v2/data_upload/common/", method: "POST", body: ["data_list": list])
}
}
func allowUploadTrigger(for type: NativeHealthDataType, now: Date = Date()) -> Bool {
if let lastDate = lastUploadTriggerDates[type],
now.timeIntervalSince(lastDate) < NativeHealthUploadConfiguration.minimumTriggerInterval {
DebugLogger.debugLog(
"[\(type.debugName)] skipped by \(Int(NativeHealthUploadConfiguration.minimumTriggerInterval))s process throttle"
)
return false
}
lastUploadTriggerDates[type] = now
return true
}
func notifyFlutterUpload(type: NativeHealthDataType, timestamp: TimeInterval) {
let seconds = Int64(timestamp)
DebugLogger.debugLog("[\(type.debugName)] notifying Flutter, dataType=\(type.rawValue), timestamp=\(seconds)")
NotificationCenter.default.post(
name: .nativeHealthDataDidUpload,
object: nil,
userInfo: [
"dataType": type.rawValue,
"timestamp": seconds,
]
)
}
func uploadSleep(_ data: [NativeSleepInterval]) async throws {
for batch in data.chunked(into: uploadBatchSize) {
batch.forEach { interval in
DebugLogger.debugLog(
"[iOS][upload][sleep] dataType=\(interval.dataType), from=\(debugTimestamp(interval.fromTime)), fromUnix=\(Int64(interval.fromTime)), to=\(debugTimestamp(interval.toTime)), toUnix=\(Int64(interval.toTime))"
)
}
let list = batch.map {
[
"data_type": $0.dataType,
"from_time": $0.fromTime,
"to_time": $0.toTime,
] as [String: Any]
}
try await request(path: "/client/doublefeel/health/v2/data_upload/sleep/", method: "POST", body: ["data_list": list])
}
}
func uploadActivityTarget(_ target: NativeActivityTarget) async throws {
try await request(path: "/client/doublefeel/health/v2/activity_target/", method: "POST", body: target.uploadBody)
}
func fetchLastUploadTime() async throws -> NativeHealthUploadTimeList {
let data = try await request(path: "/client/doublefeel/health/v2/data_upload/common/", method: "GET")
return try NativeHealthUploadTimeList.decode(from: data)
}
@discardableResult
func request(path: String, method: String, body: [String: Any]? = nil) async throws -> Data {
guard let baseURL = URL(string: AppShared.shared.baseUrl),
let url = URL(string: path, relativeTo: baseURL)?.absoluteURL else {
throw NativeHealthUploadError.invalidServerURL
}
guard let accessToken = AppShared.shared.token, !accessToken.isEmpty else {
throw NativeHealthUploadError.missingAccessToken
}
var request = URLRequest(url: url)
request.httpMethod = method
request.timeoutInterval = 60
request.setValue("application/json", forHTTPHeaderField: "Accept")
request.setValue(accessToken, forHTTPHeaderField: "access_token")
request.setValue(AppShared.shared.agent.finalUA, forHTTPHeaderField: "User-Agent")
if let body {
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpBody = try JSONSerialization.data(withJSONObject: body)
}
let (data, response) = try await session.data(for: request)
guard let httpResponse = response as? HTTPURLResponse else {
throw NativeHealthUploadError.invalidResponse
}
guard (200..<300).contains(httpResponse.statusCode) else {
throw NativeHealthUploadError.requestFailed(
path: path,
statusCode: httpResponse.statusCode,
body: String(data: data, encoding: .utf8)
)
}
return data
}
static let debugDateFormatter: DateFormatter = {
let formatter = DateFormatter()
formatter.locale = Locale(identifier: "en_US_POSIX")
formatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
return formatter
}()
func debugTimestamp(_ timeInterval: TimeInterval) -> String {
Self.debugDateFormatter.string(from: Date(timeIntervalSince1970: timeInterval))
}
func debugLogTimeComparison(
type: NativeHealthDataType,
serverTime: TimeInterval,
newestTime: TimeInterval?
) {
let newestDescription = newestTime.map {
"\(debugTimestamp($0)) (unix=\(Int64($0)))"
} ?? "<none>"
DebugLogger.debugLog(
"[iOS][time-check] dataType=\(type.rawValue)(\(type.debugName)), server=\(debugTimestamp(serverTime)) (unix=\(Int64(serverTime))), newest=\(newestDescription), shouldUpload=\(newestTime.map { $0 > serverTime } ?? false)"
)
}
}
struct NativeHealthUploadTimeList: Codable {
struct HealthUploadTime: Codable {
let dataType: NativeHealthDataType?
let latestDataTime: TimeInterval?
enum CodingKeys: String, CodingKey {
case dataType = "data_type"
case latestDataTime = "latest_data_time"
}
}
var latestDataTimeList: [HealthUploadTime]
enum CodingKeys: String, CodingKey {
case latestDataTimeList = "latest_data_time_list"
}
func latestDataTime(for type: NativeHealthDataType) -> Date? {
latestTimeInterval(for: type).map(Date.init(timeIntervalSince1970:))
}
func latestTimeInterval(for type: NativeHealthDataType) -> TimeInterval? {
latestDataTimeList.first { $0.dataType == type }?.latestDataTime
}
static func decode(from data: Data) throws -> NativeHealthUploadTimeList {
let decoder = JSONDecoder()
if let direct = try? decoder.decode(NativeHealthUploadTimeList.self, from: data) {
return direct
}
let wrapped = try decoder.decode(HealthUploadTimeListResponse.self, from: data)
if let data = wrapped.data {
return data
}
throw NativeHealthUploadError.invalidResponse
}
}
private extension Array {
func chunked(into size: Int) -> [[Element]] {
guard size > 0 else { return [self] }
return stride(from: 0, to: count, by: size).map {
Array(self[$0..<Swift.min($0 + size, count)])
}
}
}
private struct HealthUploadTimeListResponse: Decodable {
let data: NativeHealthUploadTimeList?
}
private extension NativeHealthDataType {
var debugName: String {
switch self {
case .unknown:
return "unknown"
case .hrv:
return "hrv"
case .heartRate:
return "heartRate"
case .oxygenSaturation:
return "oxygenSaturation"
case .activeEnergy:
return "activeEnergy"
case .exercise:
return "exercise"
case .stand:
return "stand"
case .steps:
return "steps"
case .walkingHeartRate:
return "walkingHeartRate"
case .restingHeartRate:
return "restingHeartRate"
case .sleepingHeartRate:
return "sleepingHeartRate"
case .sleepingWristTemperature:
return "sleepingWristTemperature"
case .respiratoryRate:
return "respiratoryRate"
case .irregularHeartRhythm:
return "irregularHeartRhythm"
case .sleep:
return "sleep"
}
}
}