sport_detail.dart 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. import 'package:sport/bean/rank_game_info.dart';
  2. import 'package:sport/bean/sport_index.dart';
  3. import 'package:sport/bean/sport_target.dart';
  4. import 'package:sport/services/Converter.dart';
  5. import 'package:sport/utils/DateFormat.dart';
  6. import 'game.dart' as Game;
  7. import 'user.dart';
  8. class SportDetail {
  9. int durationTotalDay = 0;
  10. int durationTarget = 0;
  11. SportTarget? target;
  12. NextAchievement? nextAchievement;
  13. RecordsTodaySum? recordsTodaySum, recordsTodayAvg;
  14. List<RecordsTodaySum>? recordsToday;
  15. List<GamesSum>? gamesSum;
  16. List<Achievement>? achievements;
  17. int step = 0;
  18. int sportTimes = 0;
  19. List<int> targetFinish = [];
  20. List<int> exerDay = [];
  21. int exerDayTotal = 0;
  22. SportDetail({this.durationTotalDay = 0, this.durationTarget = 0, this.target, this.nextAchievement, this.recordsTodaySum, this.recordsTodayAvg, this.recordsToday, this.gamesSum, this.achievements, this.targetFinish = const [], this.exerDay = const [], this.exerDayTotal = 0});
  23. SportDetail.fromJson(Map<String, dynamic> json) {
  24. durationTotalDay = json['duration_total_day'];
  25. durationTarget = json['duration_target'];
  26. step = json['step'];
  27. sportTimes = json['sport_times'];
  28. target = json['target'] != null ? new SportTarget.fromJson(json['target']) : null;
  29. nextAchievement = json['next_achievement'] != null ? new NextAchievement.fromJson(json['next_achievement']) : null;
  30. recordsTodaySum = json['records_today_sum'] != null ? new RecordsTodaySum.fromJson(json['records_today_sum']) : null;
  31. recordsTodayAvg = json['records_today_avg'] != null ? new RecordsTodaySum.fromJson(json['records_today_avg']) : null;
  32. if (json['records_today'] != null) {
  33. recordsToday = [];
  34. json['records_today'].forEach((v) {
  35. recordsToday!.add(new RecordsTodaySum.fromJson(v));
  36. });
  37. }
  38. if (json['games_sum'] != null) {
  39. gamesSum = [];
  40. json['games_sum'].forEach((v) {
  41. gamesSum!.add(new GamesSum.fromJson(v));
  42. });
  43. }
  44. if (json['achievements'] != null) {
  45. achievements = [];
  46. json['achievements'].forEach((v) {
  47. achievements!.add(new Achievement.fromJson(v));
  48. });
  49. }
  50. if (json['target_finish'] != null) {
  51. targetFinish = json['target_finish'];
  52. }
  53. if (json['exer_day'] != null) {
  54. exerDay = json['exer_day'];
  55. }
  56. }
  57. Map<String, dynamic> toJson() {
  58. final Map<String, dynamic> data = new Map<String, dynamic>();
  59. data['duration_total_day'] = this.durationTotalDay;
  60. data['duration_target'] = this.durationTarget;
  61. data['step'] = this.step;
  62. data['sport_times'] = this.sportTimes;
  63. if (this.target != null) {
  64. data['target'] = this.target!.toJson();
  65. }
  66. if (this.nextAchievement != null) {
  67. data['next_achievement'] = this.nextAchievement!.toJson();
  68. }
  69. if (this.recordsTodaySum != null) {
  70. data['records_today_sum'] = this.recordsTodaySum!.toJson();
  71. }
  72. if (this.recordsToday != null) {
  73. data['records_today'] = this.recordsToday!.map((v) => v.toJson()).toList();
  74. }
  75. if (this.gamesSum != null) {
  76. data['games_sum'] = this.gamesSum!.map((v) => v.toJson()).toList();
  77. }
  78. if (this.achievements != null) {
  79. data['achievements'] = this.achievements!.map((v) => v.toJson()).toList();
  80. }
  81. return data;
  82. }
  83. }
  84. class NextAchievement {
  85. Achievement? achievement;
  86. int? diff;
  87. NextAchievement({this.achievement, this.diff});
  88. NextAchievement.fromJson(Map<String, dynamic> json) {
  89. achievement = json['achievement'] != null ? new Achievement.fromJson(json['achievement']) : null;
  90. diff = json['condition_count_diff'];
  91. }
  92. Map<String, dynamic> toJson() {
  93. final Map<String, dynamic> data = new Map<String, dynamic>();
  94. if (this.achievement != null) {
  95. data['achievement'] = this.achievement!.toJson();
  96. }
  97. data['condition_count_diff'] = this.diff;
  98. return data;
  99. }
  100. }
  101. class RecordsTodaySum {
  102. int id = 0;
  103. int? userId;
  104. int consume = 0;
  105. int consume_game = 0;
  106. int consume_jog = 0;
  107. int consume_daily = 0;
  108. int duration = 0;
  109. int duration_game = 0;
  110. int duration_jog = 0;
  111. double durationMin = 0;
  112. double durationMinGame = 0;
  113. double durationMinJog = 0;
  114. int step = 0;
  115. int step_game = 0;
  116. int step_jog = 0;
  117. int step_daily = 0;
  118. int distance = 0;
  119. int distance_game = 0;
  120. int distance_jog = 0;
  121. int distance_daily = 0;
  122. int times = 0;
  123. int times_game = 0;
  124. int times_jog = 0;
  125. String? createdAt;
  126. int crouch = 0;
  127. double crouchRate = 0;
  128. int jump = 0;
  129. double jumpRate = 0;
  130. int? screen;
  131. double stepRate = 0.0;
  132. double stepRateGame = 0.0;
  133. double stepRateJog = 0.0;
  134. double score = 0;
  135. double scoreMax = 0;
  136. double consumeRate = 0;
  137. int year = 0;
  138. int month = 0;
  139. double met = 0.0;
  140. int? mode;
  141. String? group;
  142. RecordsTodaySum({
  143. this.id = 0,
  144. this.userId,
  145. this.duration = 0,
  146. this.createdAt,
  147. this.consume = 0,
  148. this.jump = 0,
  149. this.crouch = 0,
  150. this.screen,
  151. this.score = 0,
  152. this.step = 0,
  153. this.times = 0,
  154. this.year = 0,
  155. this.month = 0,
  156. });
  157. RecordsTodaySum.fromJson(Map<String, dynamic> json) {
  158. id = json['id'] ?? 0;
  159. userId = json['user_id'];
  160. consume = json['consume'] ?? 0;
  161. consume_game = json['consume_game'] ?? 0;
  162. consume_jog = json['consume_jog'] ?? 0;
  163. consume_daily = json['consume_daily'] ?? 0;
  164. duration = json['duration'] ?? json['duration_minute'] ?? 0;
  165. duration_game = json['duration_game'] ?? 0;
  166. duration_jog = json['duration_jog'] ?? 0;
  167. durationMin = json['duration'] != null ? (Converter.toDouble(json['duration']) / 60).round().toDouble() : Converter.toDouble(json['duration_min'] ?? json['duration_minute']);
  168. durationMinGame = json['duration_game'] != null ?(Converter.toDouble(json['duration_game']) / 60).round().toDouble() : Converter.toDouble(json['duration_game_min']);
  169. durationMinJog = json['duration_jog'] != null ?(Converter.toDouble(json['duration_jog']) / 60).round().toDouble() : Converter.toDouble(json['duration_jog_min']);
  170. step = json['step'] ?? 0;
  171. step_game = json['step_game'] ?? 0;
  172. step_jog = json['step_jog'] ?? 0;
  173. step_daily = json['step_daily'] ?? 0;
  174. stepRate = Converter.toDouble(json['step_rate']);
  175. times = json['times'] ?? 0;
  176. times_game = json['times_game'] ?? 0;
  177. times_jog = json['times_jog'] ?? 0;
  178. distance = json['distance'] ?? 0;
  179. distance_game = json['distance_game'] ?? 0;
  180. distance_jog = json['distance_jog'] ?? 0;
  181. distance_daily = json['distance_daily'] ?? 0;
  182. createdAt = json['created_at'];
  183. jump = json['jump'] ?? 0;
  184. jumpRate = Converter.toDouble(json['jump_rate']);
  185. crouch = json['crouch'] ?? 0;
  186. crouchRate = Converter.toDouble(json['crouch_rate']);
  187. screen = json['screen'];
  188. score = Converter.toDouble(json['score']);
  189. times = json['times'] ?? 0;
  190. step = json['step'] ?? 0;
  191. scoreMax = Converter.toDouble(json['score_max']);
  192. consumeRate = Converter.toDouble(json['consume_rate']);
  193. month = Converter.toInt(json['month']);
  194. year = Converter.toInt(json['year']);
  195. met = Converter.toDouble(json['met']);
  196. mode = json['mode'];
  197. group = json['play_group'];
  198. }
  199. Map<String, dynamic> toJson() {
  200. final Map<String, dynamic> data = new Map<String, dynamic>();
  201. data['id'] = this.id;
  202. data['user_id'] = this.userId;
  203. data['duration'] = this.duration;
  204. data['duration_min'] = this.durationMin;
  205. data['created_at'] = this.createdAt;
  206. data['consume'] = this.consume;
  207. data['consume_daily'] = this.consume_daily;
  208. data['consume_game'] = this.consume_game;
  209. data['consume_jog'] = this.consume_jog;
  210. data['jump'] = this.jump;
  211. data['crouch'] = this.crouch;
  212. data['screen'] = this.screen;
  213. data['times'] = this.times;
  214. return data;
  215. }
  216. String get tag => this.createdAt?.split(" ")[0] ?? "";
  217. String get title {
  218. if (this.createdAt?.isNotEmpty == true) {
  219. return DateFormat.formatCreateAtYYYYMMDDHHmm(this.createdAt!);
  220. }
  221. return "";
  222. }
  223. RecordsTodaySum operator +(RecordsTodaySum other) {
  224. this.times++;
  225. this.duration += other.duration;
  226. this.durationMin += other.durationMin;
  227. this.distance_daily += other.distance_daily;
  228. this.distance_game += other.distance_game;
  229. this.distance_jog += other.distance_jog;
  230. this.consume += other.consume;
  231. this.consume_daily += other.consume_daily;
  232. this.consume_game += other.consume_game;
  233. this.consume_jog += other.consume_jog;
  234. this.step += other.step;
  235. this.step_daily += other.step_daily;
  236. this.step_game += other.step_game;
  237. this.step_jog += other.step_jog;
  238. this.crouch += other.crouch;
  239. this.jump += this.jump;
  240. this.createdAt = other.createdAt;
  241. return this;
  242. }
  243. bool isSameDay(int day) {
  244. if (createdAt == null) return false;
  245. DateTime date = DateTime.parse(createdAt!);
  246. // print("11111111111111111111 $date ${date.day} == $day");
  247. return date.day == day;
  248. }
  249. bool isSameHour(int hour) {
  250. if (createdAt == null) return false;
  251. DateTime date = DateTime.parse(createdAt!);
  252. return date.hour == hour;
  253. }
  254. String getDate(int type) {
  255. if (type == 3) {
  256. return "$year年${'$month'.padLeft(2, '0')}月";
  257. }
  258. if (createdAt == null) return "";
  259. DateTime date = DateTime.parse(createdAt!);
  260. switch (type) {
  261. case 0:
  262. return "${'${date.month}'.padLeft(2, '0')}月${'${date.day}'.padLeft(2, '0')}日";
  263. case 1:
  264. return "${'${date.month}'.padLeft(2, '0')}月${'${date.day}'.padLeft(2, '0')}日";
  265. case 2:
  266. return "${'${date.month}'.padLeft(2, '0')}月${'${date.day}'.padLeft(2, '0')}日";
  267. case 3:
  268. return "${date.year}年${'${date.month}'.padLeft(2, '0')}月";
  269. }
  270. return "";
  271. }
  272. double getValue(int type) {
  273. switch (type) {
  274. case 0:
  275. return consume.toDouble();
  276. case 1:
  277. return step.toDouble();
  278. case 2:
  279. return durationMin.toDouble();
  280. case 3:
  281. return met;
  282. }
  283. return 0;
  284. }
  285. }
  286. class RecordsToday {
  287. int? id;
  288. int? userId;
  289. int? duration;
  290. String? createdAt;
  291. int? month;
  292. int? consume;
  293. int? gameId;
  294. int? jumpCount;
  295. int? crouchCount;
  296. double? score;
  297. String? lastPlayAt;
  298. String? name;
  299. String? cover;
  300. double? todayScoreMax;
  301. int? durationTotalMinute;
  302. int? userCount;
  303. int? times;
  304. int? year;
  305. double? met;
  306. 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});
  307. RecordsToday.fromJson(Map<String, dynamic> json) {
  308. id = json['id'];
  309. userId = json['user_id'];
  310. duration = json['duration'];
  311. createdAt = json['created_at'];
  312. month = json['month'];
  313. consume = json['consume'];
  314. gameId = json['game_id'];
  315. jumpCount = json['jump'];
  316. crouchCount = json['crouch'];
  317. score = Converter.toDouble(json['score']);
  318. lastPlayAt = json['last_play_at'];
  319. name = json['name'];
  320. cover = json['cover'];
  321. todayScoreMax = Converter.toDouble(json['today_score_max']);
  322. durationTotalMinute = json['duration_minute'];
  323. userCount = json['user_count'];
  324. times = json['times'];
  325. met = Converter.toDouble(json['met']);
  326. }
  327. Map<String, dynamic> toJson() {
  328. final Map<String, dynamic> data = new Map<String, dynamic>();
  329. data['id'] = this.id;
  330. data['user_id'] = this.userId;
  331. data['duration'] = this.duration;
  332. data['created_at'] = this.createdAt;
  333. data['consume'] = this.consume;
  334. data['game_id'] = this.gameId;
  335. data['jump_count'] = this.jumpCount;
  336. data['crouch_count'] = this.crouchCount;
  337. data['score'] = this.score;
  338. return data;
  339. }
  340. }
  341. class GamesSum {
  342. int? id;
  343. int? userId;
  344. int? gameId;
  345. String? lastPlayAt;
  346. int? playCount;
  347. int durationTotal = 0;
  348. double scoreTotal = 0;
  349. int consumeTotal = 0;
  350. double? scoreMax;
  351. Game.GameInfoData? game;
  352. GamesSum.fromJson(Map<String, dynamic> json) {
  353. id = json['id'];
  354. userId = json['user_id'];
  355. gameId = json['game_id'];
  356. lastPlayAt = json['last_play_at'];
  357. playCount = json['times'];
  358. durationTotal = json['duration'];
  359. scoreTotal = Converter.toDouble(json['score']);
  360. consumeTotal = json['consume'];
  361. scoreMax = Converter.toDouble(json['score_max']);
  362. game = json['game'] != null ? new Game.GameInfoData.fromJson(json['game']) : null;
  363. }
  364. Map<String, dynamic> toJson() {
  365. final Map<String, dynamic> data = new Map<String, dynamic>();
  366. data['id'] = this.id;
  367. data['user_id'] = this.userId;
  368. data['game_id'] = this.gameId;
  369. data['last_play_at'] = this.lastPlayAt;
  370. data['times'] = this.playCount;
  371. data['duration'] = this.durationTotal;
  372. data['score_total'] = this.scoreTotal;
  373. data['consume'] = this.consumeTotal;
  374. data['score_max'] = this.scoreMax;
  375. data['game'] = this.game;
  376. return data;
  377. }
  378. }
  379. class SportDetailSimple {
  380. RecordsTodaySum? sum, avg;
  381. List<RecordsTodaySum>? records;
  382. List<int> targetFinish = [];
  383. List<int> exerDay = [];
  384. int exerDayTotal = 0;
  385. SportTarget? target;
  386. SportDetailSimple({this.sum, this.records});
  387. SportDetailSimple.fromJson(Map<String, dynamic> json) {
  388. sum = json['sum'] != null ? new RecordsTodaySum.fromJson(json['sum']) : null;
  389. avg = json['avg'] != null ? new RecordsTodaySum.fromJson(json['avg']) : null;
  390. if (json['records'] != null) {
  391. records = [];
  392. json['records'].forEach((v) {
  393. records!.add(new RecordsTodaySum.fromJson(v));
  394. });
  395. }
  396. if (json['target_finish'] != null) {
  397. targetFinish = [];
  398. json['target_finish'].forEach((v) {
  399. targetFinish.add(v as int);
  400. });
  401. }
  402. if (json['exer_day'] != null) {
  403. exerDay = [];
  404. json['target_finish'].forEach((v) {
  405. exerDay.add(v as int);
  406. });
  407. }
  408. exerDayTotal = Converter.toInt(json['exer_day_total']);
  409. target = json['target'] != null ? new SportTarget.fromJson(json['target']) : null;
  410. }
  411. }
  412. class SportHistory {
  413. int year = 0;
  414. List<List<int>> data = [];
  415. SportHistory.fromJson(Map<String, dynamic> json) {
  416. year = Converter.toInt(json['year']);
  417. if (json['data'] != null) {
  418. data = [];
  419. json['data'].forEach((v) {
  420. List<int> day = [];
  421. v.forEach((v) {
  422. day.add(Converter.toInt(v));
  423. });
  424. data.add(day);
  425. });
  426. }
  427. }
  428. }