health_models.dart
20.1 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
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
import '../enums/app_enums.dart';
int? _parseInt(dynamic value) {
if (value == null) return null;
if (value is int) return value;
if (value is double) return value.toInt();
if (value is String) {
return int.tryParse(value);
}
return null;
}
double? _parseDouble(dynamic value) {
if (value == null) return null;
if (value is num) return value.toDouble();
if (value is String) {
if (value == 'NaN') return double.nan;
if (value == 'Infinity') return double.infinity;
if (value == '-Infinity') return double.negativeInfinity;
return double.tryParse(value);
}
return null;
}
class TodayStatusData {
const TodayStatusData({
this.recentData,
this.hrvDataList,
this.heartRateDataList,
this.spo2DataList,
this.sleepDuration,
});
final TodayStatusRecentData? recentData;
final List<TodayHrvData>? hrvDataList;
final List<TodayHeartRateData>? heartRateDataList;
final List<TodaySpo2Data>? spo2DataList;
final int? sleepDuration;
factory TodayStatusData.fromJson(Map<String, dynamic> json) {
return TodayStatusData(
recentData: json['recent_data'] == null
? null
: TodayStatusRecentData.fromJson(
json['recent_data'] as Map<String, dynamic>),
hrvDataList: (json['hrv_data_list'] as List<dynamic>?)
?.map((e) => TodayHrvData.fromJson(e as Map<String, dynamic>))
.toList(),
heartRateDataList: (json['heart_rate_data_list'] as List<dynamic>?)
?.map((e) => TodayHeartRateData.fromJson(e as Map<String, dynamic>))
.toList(),
spo2DataList: (json['oxygen_saturation_data_list'] as List<dynamic>?)
?.map((e) => TodaySpo2Data.fromJson(e as Map<String, dynamic>))
.toList(),
sleepDuration: _parseInt(json['sleep_duration']),
);
}
Map<String, dynamic> toJson() {
final val = <String, dynamic>{};
if (recentData != null) val['recent_data'] = recentData!.toJson();
if (hrvDataList != null) {
val['hrv_data_list'] = hrvDataList!.map((e) => e.toJson()).toList();
}
if (heartRateDataList != null) {
val['heart_rate_data_list'] =
heartRateDataList!.map((e) => e.toJson()).toList();
}
if (spo2DataList != null) {
val['oxygen_saturation_data_list'] =
spo2DataList!.map((e) => e.toJson()).toList();
}
if (sleepDuration != null) val['sleep_duration'] = sleepDuration;
return val;
}
}
class TodayStatusRecentData {
const TodayStatusRecentData({
this.heartRate,
this.spo2,
this.move,
this.exercise,
this.stand,
this.steps,
});
final int? heartRate;
final double? spo2;
final int? move;
final int? exercise;
final int? stand;
final int? steps;
factory TodayStatusRecentData.fromJson(Map<String, dynamic> json) {
return TodayStatusRecentData(
heartRate: _parseInt(json['heart_rate']),
spo2: _parseDouble(json['oxygen_saturation']),
move: _parseInt(json['move']),
exercise: _parseInt(json['exercise']),
stand: _parseInt(json['stand']),
steps: _parseInt(json['steps']),
);
}
Map<String, dynamic> toJson() {
final val = <String, dynamic>{};
if (heartRate != null) val['heart_rate'] = heartRate;
if (spo2 != null) val['oxygen_saturation'] = spo2;
if (move != null) val['move'] = move;
if (exercise != null) val['exercise'] = exercise;
if (stand != null) val['stand'] = stand;
if (steps != null) val['steps'] = steps;
return val;
}
}
class TodayHrvData {
const TodayHrvData({this.time, this.value, this.hrvBaseline});
final int? time;
final double? value;
final double? hrvBaseline;
HrvStatus? get hrvStatus {
final actualHrv = value;
if (actualHrv == null) return null;
final baseline = hrvBaseline ?? 0;
if (baseline > 0) {
if (actualHrv >= 1.2 * baseline) return HrvStatus.energetic;
if (actualHrv <= 0.8 * baseline) return HrvStatus.overload;
return HrvStatus.normal;
}
if (actualHrv >= 128) return HrvStatus.energetic;
if (actualHrv <= 30) return HrvStatus.overload;
return HrvStatus.normal;
}
factory TodayHrvData.fromJson(Map<String, dynamic> json) {
return TodayHrvData(
time: _parseInt(json['time']),
value: _parseDouble(json['value']),
hrvBaseline: _parseDouble(json['hrv_baseline']),
);
}
Map<String, dynamic> toJson() {
final val = <String, dynamic>{};
if (time != null) val['time'] = time;
if (value != null) val['value'] = value;
if (hrvBaseline != null) val['hrv_baseline'] = hrvBaseline;
return val;
}
}
class TodayHeartRateData {
const TodayHeartRateData({this.index, this.minimum, this.maximum});
final int? index;
final int? minimum;
final int? maximum;
factory TodayHeartRateData.fromJson(Map<String, dynamic> json) {
return TodayHeartRateData(
index: _parseInt(json['bi_hour_index']),
minimum: _parseInt(json['minimum']),
maximum: _parseInt(json['maximum']),
);
}
Map<String, dynamic> toJson() {
final val = <String, dynamic>{};
if (index != null) val['bi_hour_index'] = index;
if (minimum != null) val['minimum'] = minimum;
if (maximum != null) val['maximum'] = maximum;
return val;
}
}
class TodaySpo2Data {
const TodaySpo2Data({this.index, this.average});
final int? index;
final double? average;
factory TodaySpo2Data.fromJson(Map<String, dynamic> json) {
return TodaySpo2Data(
index: _parseInt(json['bi_hour_index']),
average: _parseDouble(json['average']),
);
}
Map<String, dynamic> toJson() {
final val = <String, dynamic>{};
if (index != null) val['bi_hour_index'] = index;
if (average != null) val['average'] = average;
return val;
}
}
class PkCurrentMonthData {
const PkCurrentMonthData({
this.userWinAmount,
this.partnerWinAmount,
this.todayRecord,
this.monthRecordList,
});
final int? userWinAmount;
final int? partnerWinAmount;
final PkRecord? todayRecord;
final List<PkRecord>? monthRecordList;
factory PkCurrentMonthData.fromJson(Map<String, dynamic> json) {
return PkCurrentMonthData(
userWinAmount: _parseInt(json['user_win']),
partnerWinAmount: _parseInt(json['pair_user_win']),
todayRecord: json['data_today'] == null
? null
: PkRecord.fromJson(json['data_today'] as Map<String, dynamic>),
monthRecordList: (json['month_data_list'] as List<dynamic>?)
?.map((e) => PkRecord.fromJson(e as Map<String, dynamic>))
.toList(),
);
}
Map<String, dynamic> toJson() {
final val = <String, dynamic>{};
if (userWinAmount != null) val['user_win'] = userWinAmount;
if (partnerWinAmount != null) val['pair_user_win'] = partnerWinAmount;
if (todayRecord != null) val['data_today'] = todayRecord!.toJson();
if (monthRecordList != null) {
val['month_data_list'] = monthRecordList!.map((e) => e.toJson()).toList();
}
return val;
}
}
class PkRecord {
const PkRecord({
this.date,
this.userScore,
this.userMove,
this.userStand,
this.userSteps,
this.partnerScore,
this.partnerMove,
this.partnerStand,
this.partnerSteps,
});
final int? date;
final int? userScore;
final int? userMove;
final int? userStand;
final int? userSteps;
final int? partnerScore;
final int? partnerMove;
final int? partnerStand;
final int? partnerSteps;
factory PkRecord.fromJson(Map<String, dynamic> json) {
return PkRecord(
date: _parseInt(json['date']),
userScore: _parseInt(json['user_score']),
userMove: _parseInt(json['user_move']),
userStand: _parseInt(json['user_stand']),
userSteps: _parseInt(json['user_steps']),
partnerScore: _parseInt(json['pair_user_score']),
partnerMove: _parseInt(json['pair_user_move']),
partnerStand: _parseInt(json['pair_user_stand']),
partnerSteps: _parseInt(json['pair_user_steps']),
);
}
Map<String, dynamic> toJson() {
final val = <String, dynamic>{};
if (date != null) val['date'] = date;
if (userScore != null) val['user_score'] = userScore;
if (userMove != null) val['user_move'] = userMove;
if (userStand != null) val['user_stand'] = userStand;
if (userSteps != null) val['user_steps'] = userSteps;
if (partnerScore != null) val['pair_user_score'] = partnerScore;
if (partnerMove != null) val['pair_user_move'] = partnerMove;
if (partnerStand != null) val['pair_user_stand'] = partnerStand;
if (partnerSteps != null) val['pair_user_steps'] = partnerSteps;
return val;
}
}
class SleepStatisticsData {
const SleepStatisticsData({
this.avgSleepDuration,
this.awakePercentage,
this.corePercentage,
this.deepPercentage,
this.remPercentage,
this.sleepTrendList,
this.asleepTimeDistributionList,
});
final int? avgSleepDuration;
final double? awakePercentage;
final double? corePercentage;
final double? deepPercentage;
final double? remPercentage;
final List<SleepTrend>? sleepTrendList;
final List<AsleepTimeDistribution>? asleepTimeDistributionList;
factory SleepStatisticsData.fromJson(Map<String, dynamic> json) {
return SleepStatisticsData(
avgSleepDuration: _parseInt(json['avg_sleep_duration']),
awakePercentage: _parseDouble(json['awake_percentage']),
corePercentage: _parseDouble(json['core_percentage']),
deepPercentage: _parseDouble(json['deep_percentage']),
remPercentage: _parseDouble(json['rem_percentage']),
sleepTrendList: (json['sleep_trend_list'] as List<dynamic>?)
?.map((e) => SleepTrend.fromJson(e as Map<String, dynamic>))
.toList(),
asleepTimeDistributionList: (json['asleep_time_trend_list'] as List<dynamic>?)
?.map((e) => AsleepTimeDistribution.fromJson(e as Map<String, dynamic>))
.toList(),
);
}
Map<String, dynamic> toJson() {
final val = <String, dynamic>{};
if (avgSleepDuration != null) val['avg_sleep_duration'] = avgSleepDuration;
if (awakePercentage != null) val['awake_percentage'] = awakePercentage;
if (corePercentage != null) val['core_percentage'] = corePercentage;
if (deepPercentage != null) val['deep_percentage'] = deepPercentage;
if (remPercentage != null) val['rem_percentage'] = remPercentage;
if (sleepTrendList != null) {
val['sleep_trend_list'] = sleepTrendList!.map((e) => e.toJson()).toList();
}
if (asleepTimeDistributionList != null) {
val['asleep_time_trend_list'] =
asleepTimeDistributionList!.map((e) => e.toJson()).toList();
}
return val;
}
}
class SleepTrend {
const SleepTrend({this.timeKey, this.average});
final int? timeKey;
final int? average;
factory SleepTrend.fromJson(Map<String, dynamic> json) {
return SleepTrend(
timeKey: _parseInt(json['time_key']),
average: _parseInt(json['average']),
);
}
Map<String, dynamic> toJson() {
final val = <String, dynamic>{};
if (timeKey != null) val['time_key'] = timeKey;
if (average != null) val['average'] = average;
return val;
}
}
class AsleepTimeDistribution {
const AsleepTimeDistribution({this.timeKey, this.average});
final int? timeKey;
final String? average;
factory AsleepTimeDistribution.fromJson(Map<String, dynamic> json) {
return AsleepTimeDistribution(
timeKey: _parseInt(json['time_key']),
average: json['average'] as String?,
);
}
Map<String, dynamic> toJson() {
final val = <String, dynamic>{};
if (timeKey != null) val['time_key'] = timeKey;
if (average != null) val['average'] = average;
return val;
}
}
class ActivityBurnStatisticsData {
const ActivityBurnStatisticsData({
this.totalCaloriesBurned,
this.avgCaloriesBurned,
this.maxCaloriesBurned,
this.minCaloriesBurned,
this.totalSteps,
this.totalStand,
this.caloriesBurnedTrendList,
this.exerciseTimeTrendList,
this.activityTargetInfo,
});
final int? totalCaloriesBurned;
final double? avgCaloriesBurned;
final CaloriesBurnedValue? maxCaloriesBurned;
final CaloriesBurnedValue? minCaloriesBurned;
final int? totalSteps;
final int? totalStand;
final List<CaloriesBurnedTrend>? caloriesBurnedTrendList;
final List<ExerciseTimeTrend>? exerciseTimeTrendList;
final ActivityTargetInfo? activityTargetInfo;
factory ActivityBurnStatisticsData.fromJson(Map<String, dynamic> json) {
return ActivityBurnStatisticsData(
totalCaloriesBurned: _parseInt(json['total_move']),
avgCaloriesBurned: _parseDouble(json['avg_move']),
maxCaloriesBurned: json['max_move'] == null
? null
: CaloriesBurnedValue.fromJson(json['max_move'] as Map<String, dynamic>),
minCaloriesBurned: json['min_move'] == null
? null
: CaloriesBurnedValue.fromJson(json['min_move'] as Map<String, dynamic>),
totalSteps: _parseInt(json['total_steps']),
totalStand: _parseInt(json['total_stand']),
caloriesBurnedTrendList: (json['move_trend_list'] as List<dynamic>?)
?.map((e) => CaloriesBurnedTrend.fromJson(e as Map<String, dynamic>))
.toList(),
exerciseTimeTrendList: (json['excercise_trend_list'] as List<dynamic>?)
?.map((e) => ExerciseTimeTrend.fromJson(e as Map<String, dynamic>))
.toList(),
activityTargetInfo: json['activity_target_info'] == null
? null
: ActivityTargetInfo.fromJson(
json['activity_target_info'] as Map<String, dynamic>),
);
}
Map<String, dynamic> toJson() {
final val = <String, dynamic>{};
if (totalCaloriesBurned != null) val['total_move'] = totalCaloriesBurned;
if (avgCaloriesBurned != null) val['avg_move'] = avgCaloriesBurned;
if (maxCaloriesBurned != null) val['max_move'] = maxCaloriesBurned!.toJson();
if (minCaloriesBurned != null) val['min_move'] = minCaloriesBurned!.toJson();
if (totalSteps != null) val['total_steps'] = totalSteps;
if (totalStand != null) val['total_stand'] = totalStand;
if (caloriesBurnedTrendList != null) {
val['move_trend_list'] =
caloriesBurnedTrendList!.map((e) => e.toJson()).toList();
}
if (exerciseTimeTrendList != null) {
val['excercise_trend_list'] =
exerciseTimeTrendList!.map((e) => e.toJson()).toList();
}
if (activityTargetInfo != null) {
val['activity_target_info'] = activityTargetInfo!.toJson();
}
return val;
}
}
class CaloriesBurnedValue {
const CaloriesBurnedValue({this.date, this.value});
final int? date;
final int? value;
factory CaloriesBurnedValue.fromJson(Map<String, dynamic> json) {
return CaloriesBurnedValue(
date: _parseInt(json['date']),
value: _parseInt(json['value']),
);
}
Map<String, dynamic> toJson() {
final val = <String, dynamic>{};
if (date != null) val['date'] = date;
if (value != null) val['value'] = value;
return val;
}
}
class CaloriesBurnedTrend {
const CaloriesBurnedTrend({this.timeKey, this.value});
final int? timeKey;
final int? value;
factory CaloriesBurnedTrend.fromJson(Map<String, dynamic> json) {
return CaloriesBurnedTrend(
timeKey: _parseInt(json['time_key']),
value: _parseInt(json['value']),
);
}
Map<String, dynamic> toJson() {
final val = <String, dynamic>{};
if (timeKey != null) val['time_key'] = timeKey;
if (value != null) val['value'] = value;
return val;
}
}
class ExerciseTimeTrend {
const ExerciseTimeTrend({this.timeKey, this.value});
final int? timeKey;
final int? value;
factory ExerciseTimeTrend.fromJson(Map<String, dynamic> json) {
return ExerciseTimeTrend(
timeKey: _parseInt(json['time_key']),
value: _parseInt(json['value']),
);
}
Map<String, dynamic> toJson() {
final val = <String, dynamic>{};
if (timeKey != null) val['time_key'] = timeKey;
if (value != null) val['value'] = value;
return val;
}
}
class ActivityTargetInfo {
const ActivityTargetInfo({this.move, this.step, this.stand});
final int? move;
final int? step;
final int? stand;
factory ActivityTargetInfo.fromJson(Map<String, dynamic> json) {
return ActivityTargetInfo(
move: _parseInt(json['move']),
step: _parseInt(json['step']),
stand: _parseInt(json['stand']),
);
}
Map<String, dynamic> toJson() {
final val = <String, dynamic>{};
if (move != null) val['move'] = move;
if (step != null) val['step'] = step;
if (stand != null) val['stand'] = stand;
return val;
}
}
class HrvStatisticsData {
const HrvStatisticsData({
this.avgHrv,
this.avgHrvBaseline,
this.avgWalkingHeartRate,
this.avgRestingHeartRate,
this.avgSleepingHeartRate,
this.hrvTrendList,
this.hrvDistributionList,
});
final double? avgHrv;
final double? avgHrvBaseline;
final double? avgWalkingHeartRate;
final double? avgRestingHeartRate;
final double? avgSleepingHeartRate;
final List<HrvTrend>? hrvTrendList;
final List<HrvDistribution>? hrvDistributionList;
factory HrvStatisticsData.fromJson(Map<String, dynamic> json) {
return HrvStatisticsData(
avgHrv: _parseDouble(json['avg_hrv']),
avgHrvBaseline: _parseDouble(json['avg_hrv_baseline']),
avgWalkingHeartRate: _parseDouble(json['avg_walking_heart_rate']),
avgRestingHeartRate: _parseDouble(json['avg_resting_heart_rate']),
avgSleepingHeartRate: _parseDouble(json['avg_sleeping_heart_rate']),
hrvTrendList: (json['hrv_trend_list'] as List<dynamic>?)
?.map((e) => HrvTrend.fromJson(e as Map<String, dynamic>))
.toList(),
hrvDistributionList: (json['hrv_distribution_list'] as List<dynamic>?)
?.map((e) => HrvDistribution.fromJson(e as Map<String, dynamic>))
.toList(),
);
}
Map<String, dynamic> toJson() {
final val = <String, dynamic>{};
if (avgHrv != null) val['avg_hrv'] = avgHrv;
if (avgHrvBaseline != null) val['avg_hrv_baseline'] = avgHrvBaseline;
if (avgWalkingHeartRate != null) {
val['avg_walking_heart_rate'] = avgWalkingHeartRate;
}
if (avgRestingHeartRate != null) {
val['avg_resting_heart_rate'] = avgRestingHeartRate;
}
if (avgSleepingHeartRate != null) {
val['avg_sleeping_heart_rate'] = avgSleepingHeartRate;
}
if (hrvTrendList != null) {
val['hrv_trend_list'] = hrvTrendList!.map((e) => e.toJson()).toList();
}
if (hrvDistributionList != null) {
val['hrv_distribution_list'] =
hrvDistributionList!.map((e) => e.toJson()).toList();
}
return val;
}
}
class HrvTrend {
const HrvTrend({this.timeKey, this.average});
final int? timeKey;
final double? average;
factory HrvTrend.fromJson(Map<String, dynamic> json) {
return HrvTrend(
timeKey: _parseInt(json['time_key']),
average: _parseDouble(json['average']),
);
}
Map<String, dynamic> toJson() {
final val = <String, dynamic>{};
if (timeKey != null) val['time_key'] = timeKey;
if (average != null) val['average'] = average;
return val;
}
}
class HrvDistribution {
const HrvDistribution({this.timeKey, this.dayCounts});
final int? timeKey;
final HrvDistributionDayCount? dayCounts;
factory HrvDistribution.fromJson(Map<String, dynamic> json) {
return HrvDistribution(
timeKey: _parseInt(json['time_key']),
dayCounts: json['day_counts'] == null
? null
: HrvDistributionDayCount.fromJson(
json['day_counts'] as Map<String, dynamic>),
);
}
Map<String, dynamic> toJson() {
final val = <String, dynamic>{};
if (timeKey != null) val['time_key'] = timeKey;
if (dayCounts != null) val['day_counts'] = dayCounts!.toJson();
return val;
}
}
class HrvDistributionDayCount {
const HrvDistributionDayCount({
this.stressful,
this.normal,
this.energetic,
});
final int? stressful;
final int? normal;
final int? energetic;
factory HrvDistributionDayCount.fromJson(Map<String, dynamic> json) {
return HrvDistributionDayCount(
stressful: _parseInt(json['stressful']),
normal: _parseInt(json['normal']),
energetic: _parseInt(json['energetic']),
);
}
Map<String, dynamic> toJson() {
final val = <String, dynamic>{};
if (stressful != null) val['stressful'] = stressful;
if (normal != null) val['normal'] = normal;
if (energetic != null) val['energetic'] = energetic;
return val;
}
}