record.dart 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. import 'package:sport/provider/lib/view_state_model.dart';
  2. import 'package:sport/services/Converter.dart';
  3. class JogRecord {
  4. List<Records>? records;
  5. Sum? sum, avg;
  6. Best? best;
  7. int? activeDay;
  8. JogRecord({this.records, this.sum, this.best, this.activeDay = 0});
  9. JogRecord.fromJson(Map<String, dynamic> json) {
  10. try {
  11. if (json['records'] != null) {
  12. records = [];
  13. json['records'].forEach((v) {
  14. records!.add(new Records.fromJson(v));
  15. });
  16. }
  17. sum = json['sum'] != null ? new Sum.fromJson(json['sum']) : null;
  18. avg = json['avg'] != null ? new Sum.fromJson(json['avg']) : null;
  19. best = json['best'] != null ? new Best.fromJson(json['best']) : null;
  20. activeDay = json['active_day'] ?? 0;
  21. } catch (e, stack) {
  22. print(e);
  23. printErrorStack(e, stack);
  24. }
  25. }
  26. Map<String, dynamic> toJson() {
  27. final Map<String, dynamic> data = new Map<String, dynamic>();
  28. if (this.records != null) {
  29. data['records'] = this.records!.map((v) => v.toJson()).toList();
  30. }
  31. if (this.sum != null) {
  32. data['sum'] = this.sum!.toJson();
  33. }
  34. if (this.best != null) {
  35. data['best'] = this.best!.toJson();
  36. }
  37. return data;
  38. }
  39. }
  40. class Records {
  41. int? distance;
  42. int? month;
  43. int? year;
  44. String? createdAt;
  45. Records({this.distance, this.month});
  46. Records.fromJson(Map<String, dynamic> json) {
  47. distance = json['distance'];
  48. month = json['month'];
  49. year = json['year'];
  50. createdAt = json['created_at'];
  51. }
  52. Map<String, dynamic> toJson() {
  53. final Map<String, dynamic> data = new Map<String, dynamic>();
  54. data['distance'] = this.distance;
  55. data['month'] = this.month;
  56. data['year'] = this.year;
  57. return data;
  58. }
  59. }
  60. class Sum {
  61. int? distance;
  62. int? duration;
  63. int durationMin = 0;
  64. int? times;
  65. int? consume;
  66. double? consumeAvg;
  67. int? kmDurationAvg;
  68. int? stepRateAvg;
  69. double? stepDistanceAvg;
  70. double met = 0.0;
  71. Sum(
  72. {this.distance,
  73. this.duration,
  74. this.times,
  75. this.consume,
  76. this.consumeAvg,
  77. this.kmDurationAvg,
  78. this.stepRateAvg,
  79. this.stepDistanceAvg});
  80. Sum.fromJson(Map<String, dynamic> json) {
  81. distance = Converter.toInt(json['distance']);
  82. duration = Converter.toInt(json['duration']);
  83. durationMin = Converter.toInt(json['duration_min']);
  84. times = Converter.toInt(json['times']);
  85. consume = Converter.toInt(json['consume']);
  86. consumeAvg = Converter.toDouble(json['consume_avg']);
  87. kmDurationAvg = Converter.toInt(json['km_duration_avg']);
  88. stepRateAvg = Converter.toInt(json['step_rate_avg']);
  89. stepDistanceAvg = Converter.toDouble(json['step_distance_avg']);
  90. met = Converter.toDouble(json['met']);
  91. }
  92. Map<String, dynamic> toJson() {
  93. final Map<String, dynamic> data = new Map<String, dynamic>();
  94. data['distance'] = this.distance;
  95. data['duration'] = this.duration;
  96. data['times'] = this.times;
  97. data['consume'] = this.consume;
  98. data['consume_avg'] = this.consumeAvg;
  99. data['km_duration_avg'] = this.kmDurationAvg;
  100. data['step_rate_avg'] = this.stepRateAvg;
  101. data['step_distance_avg'] = this.stepDistanceAvg;
  102. return data;
  103. }
  104. double get speed{
  105. if((this.duration ?? 0) > 0){
  106. return (this.distance ?? 0) * 3.6 / this.duration!;
  107. }
  108. return 0;
  109. }
  110. int durationWeek(int day){
  111. if((this.duration ?? 0) > 0){
  112. return Converter.toInt((this.duration ?? 0) / 60 / (day / 7));
  113. }
  114. return 0;
  115. }
  116. int consumeWeek(int day){
  117. if((this.consume ?? 0) > 0){
  118. return Converter.toInt((this.consume ?? 0) / (day / 7));
  119. }
  120. return 0;
  121. }
  122. }
  123. class Best {
  124. Distance? distance;
  125. Distance? duration;
  126. Distance? kmDuration;
  127. List<KmDurationList>? kmDurationList;
  128. Best({this.distance, this.duration, this.kmDuration, this.kmDurationList});
  129. Best.fromJson(Map<String, dynamic> json) {
  130. distance = json['distance'] != null
  131. ? new Distance.fromJson(json['distance'])
  132. : null;
  133. duration = json['duration'] != null
  134. ? new Distance.fromJson(json['duration'])
  135. : null;
  136. kmDuration = json['km_duration'] != null
  137. ? new Distance.fromJson(json['km_duration'])
  138. : null;
  139. if (json['km_duration_list'] != null) {
  140. kmDurationList = [];
  141. json['km_duration_list'].forEach((v) {
  142. kmDurationList!.add(new KmDurationList.fromJson(v));
  143. });
  144. }
  145. }
  146. Map<String, dynamic> toJson() {
  147. final Map<String, dynamic> data = new Map<String, dynamic>();
  148. if (this.distance != null) {
  149. data['distance'] = this.distance!.toJson();
  150. }
  151. if (this.duration != null) {
  152. data['duration'] = this.duration!.toJson();
  153. }
  154. if (this.kmDuration != null) {
  155. data['km_duration'] = this.kmDuration!.toJson();
  156. }
  157. if (this.kmDurationList != null) {
  158. data['km_duration_list'] =
  159. this.kmDurationList!.map((v) => v.toJson()).toList();
  160. }
  161. return data;
  162. }
  163. }
  164. class Distance {
  165. int? id;
  166. int? value;
  167. String? createdAt;
  168. Distance({this.id, this.value, this.createdAt});
  169. Distance.fromJson(Map<String, dynamic> json) {
  170. id = json['id'];
  171. value = json['value'];
  172. createdAt = json['created_at'];
  173. }
  174. Map<String, dynamic> toJson() {
  175. final Map<String, dynamic> data = new Map<String, dynamic>();
  176. data['id'] = this.id;
  177. data['value'] = this.value;
  178. data['created_at'] = this.createdAt;
  179. return data;
  180. }
  181. }
  182. class KmDurationList {
  183. int? id;
  184. String? createdAt;
  185. int? distance;
  186. int? duration;
  187. KmDurationList({this.id, this.createdAt, this.distance, this.duration});
  188. KmDurationList.fromJson(Map<String, dynamic> json) {
  189. id = json['id'];
  190. createdAt = json['created_at'];
  191. distance = json['distance'];
  192. duration = json['duration'];
  193. }
  194. Map<String, dynamic> toJson() {
  195. final Map<String, dynamic> data = new Map<String, dynamic>();
  196. data['id'] = this.id;
  197. data['created_at'] = this.createdAt;
  198. data['distance'] = this.distance;
  199. data['duration'] = this.duration;
  200. return data;
  201. }
  202. }