health_v2_models.dart
6.32 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
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;
}
/// v2/lastest_hrv/ response
class V2LatestHrvData {
const V2LatestHrvData(
{this.latestHrv, this.latestDataTime, this.state, this.tip});
final double? latestHrv;
final int? latestDataTime;
final int? state;
final String? tip;
factory V2LatestHrvData.fromJson(Map<String, dynamic> json) {
return V2LatestHrvData(
latestHrv: _parseDouble(json['latest_hrv']),
latestDataTime: _parseInt(json['latest_data_time']),
state: _parseInt(json['state']),
tip: json['tip_text'],
);
}
}
/// v2/health_data/ response
class V2HealthData {
const V2HealthData({
this.hrvAvg,
this.lastRestingHrValue,
this.hrAvg,
this.move,
this.exercise,
this.stand,
this.steps,
this.sleepDuration,
this.sleepScore,
this.sleepState,
});
final int? hrvAvg;
final int? lastRestingHrValue;
final int? hrAvg;
final int? move;
final int? exercise;
final int? stand;
final int? steps;
final int? sleepDuration;
final double? sleepScore;
final int? sleepState;
factory V2HealthData.fromJson(Map<String, dynamic> json) {
return V2HealthData(
hrvAvg: _parseInt(json['hrv_avg']),
lastRestingHrValue: _parseInt(json['last_resting_hr_value']),
hrAvg: _parseInt(json['hr_avg']),
move: _parseInt(json['move']),
exercise: _parseInt(json['exercise']),
stand: _parseInt(json['stand']),
steps: _parseInt(json['steps']),
sleepDuration: _parseInt(json['sleep_duration']),
sleepScore: _parseDouble(json['sleep_score']),
sleepState: _parseInt(json['sleep_state']),
);
}
Map<String, dynamic> toJson() {
final val = <String, dynamic>{};
if (hrvAvg != null) val['hrv_avg'] = hrvAvg;
if (lastRestingHrValue != null) {
val['last_resting_hr_value'] = lastRestingHrValue;
}
if (hrAvg != null) val['hr_avg'] = hrAvg;
if (move != null) val['move'] = move;
if (exercise != null) val['exercise'] = exercise;
if (stand != null) val['stand'] = stand;
if (steps != null) val['steps'] = steps;
if (sleepDuration != null) val['sleep_duration'] = sleepDuration;
if (sleepScore != null) val['sleep_score'] = sleepScore;
if (sleepState != null) val['sleep_state'] = sleepState;
return val;
}
}
/// v2/stress_score/ response
class V2StressScore {
const V2StressScore({
this.state,
this.hrvScore,
this.hrScore,
this.latestHr,
this.comprehensiveScore,
});
final int? state;
final int? hrvScore;
final int? hrScore;
final int? latestHr;
final int? comprehensiveScore;
factory V2StressScore.fromJson(Map<String, dynamic> json) {
return V2StressScore(
state: _parseInt(json['state']),
hrvScore: _parseInt(json['hrv_score']),
hrScore: _parseInt(json['hr_score']),
latestHr: _parseInt(json['latest_hr']),
comprehensiveScore: _parseInt(json['comprehensive_score']),
);
}
Map<String, dynamic> toJson() {
final val = <String, dynamic>{};
if (state != null) val['state'] = state;
if (hrvScore != null) val['hrv_score'] = hrvScore;
if (hrScore != null) val['hr_score'] = hrScore;
if (latestHr != null) val['latest_hr'] = latestHr;
if (comprehensiveScore != null) {
val['comprehensive_score'] = comprehensiveScore;
}
return val;
}
}
/// Single item in v2/hrv_trend/ list
class V2HrvTrendItem {
const V2HrvTrendItem({this.time, this.rawHrv, this.trendHrv, this.state});
final int? time;
final double? rawHrv;
final int? trendHrv;
final int? state;
factory V2HrvTrendItem.fromJson(Map<String, dynamic> json) {
return V2HrvTrendItem(
time: _parseInt(json['time']),
rawHrv: _parseDouble(json['raw_hrv']),
trendHrv: _parseInt(json['trend_hrv']),
state: _parseInt(json['state']),
);
}
Map<String, dynamic> toJson() {
final val = <String, dynamic>{};
if (time != null) val['time'] = time;
if (rawHrv != null) val['raw_hrv'] = rawHrv;
if (trendHrv != null) val['trend_hrv'] = trendHrv;
if (state != null) val['state'] = state;
return val;
}
}
/// v2/hrv_trend/ response
class V2HrvTrendData {
const V2HrvTrendData({this.list});
final List<V2HrvTrendItem>? list;
factory V2HrvTrendData.fromJson(Map<String, dynamic> json) {
return V2HrvTrendData(
list: (json['list'] as List<dynamic>?)
?.map((e) => V2HrvTrendItem.fromJson(e as Map<String, dynamic>))
.toList(),
);
}
Map<String, dynamic> toJson() {
final val = <String, dynamic>{};
if (list != null) {
val['list'] = list!.map((e) => e.toJson()).toList();
}
return val;
}
}
/// Single item in v2/realtime_stress/ list
class V2RealtimeStressItem {
const V2RealtimeStressItem({this.time, this.value, this.state});
final int? time;
final int? value;
final int? state;
factory V2RealtimeStressItem.fromJson(Map<String, dynamic> json) {
return V2RealtimeStressItem(
time: _parseInt(json['time']),
value: _parseInt(json['value']),
state: _parseInt(json['state']),
);
}
Map<String, dynamic> toJson() {
final val = <String, dynamic>{};
if (time != null) val['time'] = time;
if (value != null) val['value'] = value;
if (state != null) val['state'] = state;
return val;
}
}
/// v2/realtime_stress/ response
class V2RealtimeStressData {
const V2RealtimeStressData({this.list});
final List<V2RealtimeStressItem>? list;
factory V2RealtimeStressData.fromJson(Map<String, dynamic> json) {
return V2RealtimeStressData(
list: (json['list'] as List<dynamic>?)
?.map((e) => V2RealtimeStressItem.fromJson(e as Map<String, dynamic>))
.toList(),
);
}
Map<String, dynamic> toJson() {
final val = <String, dynamic>{};
if (list != null) {
val['list'] = list!.map((e) => e.toJson()).toList();
}
return val;
}
}