sport_detail.dart 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. import 'package:sport/bean/rank_game_info.dart';
  2. import 'package:sport/bean/sport_target.dart';
  3. import 'package:sport/services/Converter.dart';
  4. import 'game.dart' as Game;
  5. import 'user.dart';
  6. class SportDetail {
  7. int durationTotalDay;
  8. int durationTarget;
  9. SportTarget target;
  10. NextAchievement nextAchievement;
  11. RecordsTodaySum recordsTodaySum, recordsTodayAvg;
  12. List<RecordsToday> recordsToday;
  13. List<GamesSum> gamesSum;
  14. List<Achievement> achievements;
  15. int step;
  16. int sportTimes;
  17. SportDetail(
  18. {this.durationTotalDay,
  19. this.durationTarget,
  20. this.target,
  21. this.nextAchievement,
  22. this.recordsTodaySum,
  23. this.recordsTodayAvg,
  24. this.recordsToday,
  25. this.gamesSum,
  26. this.achievements});
  27. SportDetail.fromJson(Map<String, dynamic> json) {
  28. durationTotalDay = json['duration_total_day'];
  29. durationTarget = json['duration_target'];
  30. step = json['step'];
  31. sportTimes = json['sport_times'];
  32. target = json['target'] != null ? new SportTarget.fromJson(json['target']) : null;
  33. nextAchievement = json['next_achievement'] != null ? new NextAchievement.fromJson(json['next_achievement']) : null;
  34. recordsTodaySum = json['records_today_sum'] != null ? new RecordsTodaySum.fromJson(json['records_today_sum']) : null;
  35. recordsTodayAvg= json['records_today_avg'] != null ? new RecordsTodaySum.fromJson(json['records_today_avg']) : null;
  36. if (json['records_today'] != null) {
  37. recordsToday = new List<RecordsToday>();
  38. json['records_today'].forEach((v) {
  39. recordsToday.add(new RecordsToday.fromJson(v));
  40. });
  41. }
  42. if (json['games_sum'] != null) {
  43. gamesSum = new List<GamesSum>();
  44. json['games_sum'].forEach((v) {
  45. gamesSum.add(new GamesSum.fromJson(v));
  46. });
  47. }
  48. if (json['achievements'] != null) {
  49. achievements = new List<Achievement>();
  50. json['achievements'].forEach((v) {
  51. achievements.add(new Achievement.fromJson(v));
  52. });
  53. }
  54. }
  55. Map<String, dynamic> toJson() {
  56. final Map<String, dynamic> data = new Map<String, dynamic>();
  57. data['duration_total_day'] = this.durationTotalDay;
  58. data['duration_target'] = this.durationTarget;
  59. data['step'] = this.step;
  60. data['sport_times'] = this.sportTimes;
  61. if (this.target != null) {
  62. data['target'] = this.target.toJson();
  63. }
  64. if (this.nextAchievement != null) {
  65. data['next_achievement'] = this.nextAchievement.toJson();
  66. }
  67. if (this.recordsTodaySum != null) {
  68. data['records_today_sum'] = this.recordsTodaySum.toJson();
  69. }
  70. if (this.recordsToday != null) {
  71. data['records_today'] = this.recordsToday.map((v) => v.toJson()).toList();
  72. }
  73. if (this.gamesSum != null) {
  74. data['games_sum'] = this.gamesSum.map((v) => v.toJson()).toList();
  75. }
  76. if (this.achievements != null) {
  77. data['achievements'] = this.achievements.map((v) => v.toJson()).toList();
  78. }
  79. return data;
  80. }
  81. }
  82. class NextAchievement {
  83. Achievement achievement;
  84. int diff;
  85. NextAchievement({this.achievement, this.diff});
  86. NextAchievement.fromJson(Map<String, dynamic> json) {
  87. achievement = json['achievement'] != null ? new Achievement.fromJson(json['achievement']) : null;
  88. diff = json['condition_count_diff'];
  89. }
  90. Map<String, dynamic> toJson() {
  91. final Map<String, dynamic> data = new Map<String, dynamic>();
  92. if (this.achievement != null) {
  93. data['achievement'] = this.achievement.toJson();
  94. }
  95. data['condition_count_diff'] = this.diff;
  96. return data;
  97. }
  98. }
  99. class RecordsTodaySum {
  100. int id;
  101. int userId;
  102. int duration;
  103. String createdAt;
  104. int consume;
  105. int jumpCount;
  106. int crouchCount;
  107. int screen ;
  108. double score;
  109. int times ;
  110. int stepCount ;
  111. double stepRate;
  112. double stepRateMax;
  113. int durationMinute;
  114. double jumpRate;
  115. double crouchRate;
  116. double scoreMax;
  117. double consumeRate;
  118. int mode;
  119. RecordsTodaySum({this.id, this.userId, this.duration, this.createdAt, this.consume, this.jumpCount, this.crouchCount, this.screen, this.score, this.stepCount, this.times, this.durationMinute});
  120. RecordsTodaySum.fromJson(Map<String, dynamic> json) {
  121. id = json['id'];
  122. userId = json['user_id'];
  123. duration = json['duration'];
  124. createdAt = json['created_at'];
  125. consume = json['consume'];
  126. jumpCount = json['jump_count'];
  127. crouchCount = json['crouch_count'];
  128. screen = json['screen'];
  129. score = Converter.toDouble(json['score']);
  130. times = json['times'];
  131. stepCount = json['step_count'];
  132. stepRate = Converter.toDouble(json['step_rate']);
  133. stepRateMax = Converter.toDouble(json['step_rate_max']);
  134. durationMinute = json['duration_minute'];
  135. jumpRate = Converter.toDouble(json['jump_rate']);
  136. crouchRate = Converter.toDouble(json['crouch_rate']);
  137. scoreMax = Converter.toDouble(json['score_max']);
  138. consumeRate = Converter.toDouble(json['consume_rate']);
  139. mode = json['mode'];
  140. }
  141. Map<String, dynamic> toJson() {
  142. final Map<String, dynamic> data = new Map<String, dynamic>();
  143. data['id'] = this.id;
  144. data['user_id'] = this.userId;
  145. data['duration'] = this.duration;
  146. data['created_at'] = this.createdAt;
  147. data['consume'] = this.consume;
  148. data['jump_count'] = this.jumpCount;
  149. data['crouch_count'] = this.crouchCount;
  150. data['screen'] = this.screen;
  151. return data;
  152. }
  153. String get tag => this.createdAt.split(" ")[0];
  154. }
  155. class RecordsToday {
  156. int id;
  157. int userId;
  158. int duration;
  159. String createdAt;
  160. int month;
  161. int consume;
  162. int gameId;
  163. int jumpCount;
  164. int crouchCount;
  165. double score;
  166. String lastPlayAt;
  167. String name;
  168. String cover;
  169. double todayScoreMax;
  170. int durationTotalMinute;
  171. int userCount;
  172. int times;
  173. int year;
  174. RecordsToday({this.id, this.userId, this.duration, this.createdAt,this.month, this.consume, this.gameId, this.jumpCount, this.crouchCount, this.score, this.name, this.cover, this.userCount});
  175. RecordsToday.fromJson(Map<String, dynamic> json) {
  176. id = json['id'];
  177. userId = json['user_id'];
  178. duration = json['duration'];
  179. createdAt = json['created_at'];
  180. month = json['month'];
  181. consume = json['consume'];
  182. gameId = json['game_id'];
  183. jumpCount = json['jump_count'];
  184. crouchCount = json['crouch_count'];
  185. score = Converter.toDouble(json['score']);
  186. lastPlayAt = json['last_play_at'];
  187. name = json['name'];
  188. cover = json['cover'];
  189. todayScoreMax = Converter.toDouble(json['today_score_max']);
  190. durationTotalMinute = json['duration_minute'];
  191. userCount = json['user_count'];
  192. times = json['times'];
  193. }
  194. Map<String, dynamic> toJson() {
  195. final Map<String, dynamic> data = new Map<String, dynamic>();
  196. data['id'] = this.id;
  197. data['user_id'] = this.userId;
  198. data['duration'] = this.duration;
  199. data['created_at'] = this.createdAt;
  200. data['consume'] = this.consume;
  201. data['game_id'] = this.gameId;
  202. data['jump_count'] = this.jumpCount;
  203. data['crouch_count'] = this.crouchCount;
  204. data['score'] = this.score;
  205. return data;
  206. }
  207. }
  208. class GamesSum {
  209. int id;
  210. int userId;
  211. int gameId;
  212. String lastPlayAt;
  213. int playCount;
  214. int durationTotal;
  215. double scoreTotal;
  216. int consumeTotal;
  217. double scoreMax;
  218. Game.GameInfoData game;
  219. GamesSum(
  220. {this.id, this.userId, this.gameId, this.lastPlayAt, this.playCount, this.durationTotal, this.scoreTotal, this.consumeTotal, this.scoreMax, this.game});
  221. GamesSum.fromJson(Map<String, dynamic> json) {
  222. id = json['id'];
  223. userId = json['user_id'];
  224. gameId = json['game_id'];
  225. lastPlayAt = json['last_play_at'];
  226. playCount = json['times'];
  227. durationTotal = json['duration'];
  228. scoreTotal = Converter.toDouble(json['score']);
  229. consumeTotal = json['consume'];
  230. scoreMax = Converter.toDouble(json['score_max']);
  231. game = json['game'] != null ? new Game.GameInfoData.fromJson(json['game']) : null;
  232. }
  233. Map<String, dynamic> toJson() {
  234. final Map<String, dynamic> data = new Map<String, dynamic>();
  235. data['id'] = this.id;
  236. data['user_id'] = this.userId;
  237. data['game_id'] = this.gameId;
  238. data['last_play_at'] = this.lastPlayAt;
  239. data['times'] = this.playCount;
  240. data['duration'] = this.durationTotal;
  241. data['score_total'] = this.scoreTotal;
  242. data['consume'] = this.consumeTotal;
  243. data['score_max'] = this.scoreMax;
  244. data['game'] = this.game;
  245. return data;
  246. }
  247. }
  248. class SportDetailSimple {
  249. RecordsTodaySum sum, avg;
  250. List<RecordsToday> records;
  251. SportDetailSimple({this.sum, this.records});
  252. SportDetailSimple.fromJson(Map<String, dynamic> json) {
  253. sum = json['sum'] != null ? new RecordsTodaySum.fromJson(json['sum']) : null;
  254. avg = json['avg'] != null ? new RecordsTodaySum.fromJson(json['avg']) : null;
  255. if (json['records'] != null) {
  256. records = new List<RecordsToday>();
  257. json['records'].forEach((v) {
  258. records.add(new RecordsToday.fromJson(v));
  259. });
  260. }
  261. }
  262. }