sport_index.dart 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. import 'dart:math';
  2. import 'package:sport/bean/sport_detail.dart';
  3. import 'package:sport/bean/sport_target.dart';
  4. import 'package:sport/bean/user.dart';
  5. //import 'package:sport/bean/user.dart';
  6. import 'game.dart' as game;
  7. class SportIndex {
  8. int duration;
  9. int durationTarget;
  10. int consume;
  11. int beyond;
  12. String inspire;
  13. game.GameInfoData lastGame;
  14. List<game.GameInfoData> games;
  15. RankInfo rank;
  16. List<Achievement> achievement;
  17. Today today;
  18. SportTarget target;
  19. List<RecordsToday> records;
  20. SportIndex({this.duration, this.durationTarget, this.consume, this.beyond, this.inspire, this.lastGame, this.achievement});
  21. SportIndex.fromJson(Map<String, dynamic> json) {
  22. duration = json['duration'];
  23. durationTarget = json['duration_target'];
  24. consume = json['consume'];
  25. beyond = json['beyond'];
  26. inspire = json['inspire'];
  27. lastGame = json['last_game'] != null ? new game.GameInfoData.fromJson(json['last_game']) : null;
  28. rank = json['rank'] != null ? new RankInfo.fromJson(json['rank']) : null;
  29. if (json['games'] != null) {
  30. games = new List<game.GameInfoData>();
  31. json['games'].forEach((v) {
  32. games.add(new game.GameInfoData.fromJson(v));
  33. });
  34. }
  35. if (json['new_achievements'] != null) {
  36. achievement = new List<Achievement>();
  37. json['new_achievements'].forEach((v) {
  38. achievement.add(new Achievement.fromJson(v));
  39. });
  40. }
  41. today = json['today'] != null ? new Today.fromJson(json['today']) : null;
  42. target = json['target'] != null ? new SportTarget.fromJson(json['target']) : null;
  43. if (json['records'] != null) {
  44. records = new List<RecordsToday>();
  45. json['records'].forEach((v) {
  46. records.add(new RecordsToday.fromJson(v));
  47. });
  48. }
  49. }
  50. Map<String, dynamic> toJson() {
  51. final Map<String, dynamic> data = new Map<String, dynamic>();
  52. data['duration'] = this.duration;
  53. data['duration_target'] = this.durationTarget;
  54. data['consume'] = this.consume;
  55. data['beyond'] = this.beyond;
  56. data['inspire'] = this.inspire;
  57. if (this.lastGame != null) {
  58. data['last_game'] = this.lastGame.toJson();
  59. }
  60. data["new_achievements"] = this.achievement;
  61. return data;
  62. }
  63. }
  64. class RankInfo {
  65. Rank rank;
  66. User user;
  67. List<User> records;
  68. RankInfo({this.rank, this.user, this.records});
  69. RankInfo.fromJson(Map<String, dynamic> json) {
  70. rank = json['rank'] != null ? new Rank.fromJson(json['rank']) : null;
  71. user = json['user'] != null ? new User.fromJson(json['user']) : null;
  72. if (json['records'] != null) {
  73. records = new List<User>();
  74. json['records'].forEach((v) {
  75. records.add(new User.fromJson(v));
  76. });
  77. }
  78. }
  79. Map<String, dynamic> toJson() {
  80. final Map<String, dynamic> data = new Map<String, dynamic>();
  81. if (this.rank != null) {
  82. data['rank'] = this.rank.toJson();
  83. }
  84. if (this.user != null) {
  85. data['user'] = this.user.toJson();
  86. }
  87. if (this.records != null) {
  88. data['records'] = this.records.map((v) => v.toJson()).toList();
  89. }
  90. return data;
  91. }
  92. }
  93. class Rank {
  94. int id;
  95. String name;
  96. int isGame;
  97. int isSport;
  98. int gameId;
  99. String introduce;
  100. int userCountMax;
  101. String rateBegin;
  102. String rateEnd;
  103. Rank({this.id, this.name, this.isGame, this.isSport, this.gameId, this.introduce, this.userCountMax, this.rateBegin, this.rateEnd});
  104. Rank.fromJson(Map<String, dynamic> json) {
  105. id = json['id'];
  106. name = json['name'];
  107. isGame = json['is_game'];
  108. isSport = json['is_sport'];
  109. gameId = json['game_id'];
  110. introduce = json['introduce'];
  111. userCountMax = json['user_count_max'];
  112. rateBegin = json['rate_begin'];
  113. rateEnd = json['rate_end'];
  114. }
  115. Map<String, dynamic> toJson() {
  116. final Map<String, dynamic> data = new Map<String, dynamic>();
  117. data['id'] = this.id;
  118. data['name'] = this.name;
  119. data['is_game'] = this.isGame;
  120. data['is_sport'] = this.isSport;
  121. data['game_id'] = this.gameId;
  122. data['introduce'] = this.introduce;
  123. data['user_count_max'] = this.userCountMax;
  124. data['rate_begin'] = this.rateBegin;
  125. data['rate_end'] = this.rateEnd;
  126. return data;
  127. }
  128. }
  129. class Today {
  130. int step, consume, duration;
  131. Today({this.step, this.consume, this.duration});
  132. Today.fromJson(Map<String, dynamic> json) {
  133. step = json['step'];
  134. consume = json['consume'];
  135. duration = json['duration_minute'];
  136. }
  137. double get strength => strengthToValue(consume);
  138. String strengthLabel() {
  139. return strengthToLabel(consume);
  140. }
  141. int value(String type) => type == "consume" ? consume : duration;
  142. }
  143. const strengthArr = ["低强度" , "强度适中" ,"高强度"];
  144. double strengthToValue(int consume) => (consume ?? 0) / 60.0;
  145. String strengthToLabel(int consume) {
  146. if(consume == 0)
  147. return "无";
  148. double v = (consume ?? 0) / 60.0;
  149. if (v < 5.0) {
  150. return strengthArr[0];
  151. } else if (v < 7.5) {
  152. return strengthArr[1];
  153. } else {
  154. return strengthArr[2];
  155. }
  156. }