123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- import 'dart:math';
- import 'dart:ui';
- import 'package:sport/application.dart';
- import 'package:sport/bean/sport_detail.dart';
- import 'package:sport/bean/sport_target.dart';
- import 'package:sport/bean/user.dart';
- //import 'package:sport/bean/user.dart';
- import 'game.dart' as game;
- class SportIndex {
- int? duration;
- int? durationTarget;
- int? consume;
- int? beyond;
- String? inspire;
- game.GameInfoData? lastGame;
- List<game.GameInfoData>? games;
- RankInfo? rank;
- List<Achievement>? achievement;
- Today? today;
- SportTarget? target;
- List<RecordsToday>? records;
- SportIndex({this.duration, this.durationTarget, this.consume, this.beyond, this.inspire, this.lastGame, this.achievement});
- SportIndex.fromJson(Map<String, dynamic> json) {
- duration = json['duration'];
- durationTarget = json['duration_target'];
- consume = json['consume'];
- beyond = json['beyond'];
- inspire = json['inspire'];
- lastGame = json['last_game'] != null ? new game.GameInfoData.fromJson(json['last_game']) : null;
- rank = json['rank'] != null ? new RankInfo.fromJson(json['rank']) : null;
- if (json['games'] != null) {
- games = [];
- json['games'].forEach((v) {
- games!.add(new game.GameInfoData.fromJson(v));
- });
- }
- if (json['new_achievements'] != null) {
- achievement = [];
- json['new_achievements'].forEach((v) {
- achievement!.add(new Achievement.fromJson(v));
- });
- }
- today = json['today'] != null ? new Today.fromJson(json['today']) : null;
- target = json['target'] != null ? new SportTarget.fromJson(json['target']) : null;
- if (json['records'] != null) {
- records = [];
- json['records'].forEach((v) {
- records!.add(new RecordsToday.fromJson(v));
- });
- }
- }
- Map<String, dynamic> toJson() {
- final Map<String, dynamic> data = new Map<String, dynamic>();
- data['duration'] = this.duration;
- data['duration_target'] = this.durationTarget;
- data['consume'] = this.consume;
- data['beyond'] = this.beyond;
- data['inspire'] = this.inspire;
- if (this.lastGame != null) {
- data['last_game'] = this.lastGame!.toJson();
- }
- data["new_achievements"] = this.achievement;
- return data;
- }
- }
- class RankInfo {
- Rank? rank;
- User? user;
- List<User>? records;
- RankInfo({this.rank, this.user, this.records});
- RankInfo.fromJson(Map<String, dynamic> json) {
- rank = json['rank'] != null
- ? json['rank'] is bool
- ? null
- : new Rank.fromJson(json['rank'])
- : null;
- user = json['user'] != null ? new User.fromJson(json['user']) : null;
- if (json['records'] != null) {
- records = [];
- json['records'].forEach((v) {
- records!.add(new User.fromJson(v));
- });
- }
- }
- Map<String, dynamic> toJson() {
- final Map<String, dynamic> data = new Map<String, dynamic>();
- if (this.rank != null) {
- data['rank'] = this.rank!.toJson();
- }
- if (this.user != null) {
- data['user'] = this.user!.toJson();
- }
- if (this.records != null) {
- data['records'] = this.records!.map((v) => v.toJson()).toList();
- }
- return data;
- }
- }
- class Rank {
- int? id;
- String? name;
- int? isGame;
- int? isSport;
- int? gameId;
- String? introduce;
- int? userCountMax;
- String? rateBegin;
- String? rateEnd;
- Rank({this.id, this.name, this.isGame, this.isSport, this.gameId, this.introduce, this.userCountMax, this.rateBegin, this.rateEnd});
- Rank.fromJson(Map<String, dynamic> json) {
- id = json['id'];
- name = json['name'];
- isGame = json['is_game'];
- isSport = json['is_sport'];
- gameId = json['game_id'];
- introduce = json['introduce'];
- userCountMax = json['user_count_max'];
- rateBegin = json['rate_begin'];
- rateEnd = json['rate_end'];
- }
- Map<String, dynamic> toJson() {
- final Map<String, dynamic> data = new Map<String, dynamic>();
- data['id'] = this.id;
- data['name'] = this.name;
- data['is_game'] = this.isGame;
- data['is_sport'] = this.isSport;
- data['game_id'] = this.gameId;
- data['introduce'] = this.introduce;
- data['user_count_max'] = this.userCountMax;
- data['rate_begin'] = this.rateBegin;
- data['rate_end'] = this.rateEnd;
- return data;
- }
- }
- class Today {
- int? step, consume, duration;
- Today({this.step, this.consume, this.duration});
- Today.fromJson(Map<String, dynamic> json) {
- step = json['step'];
- consume = json['consume'];
- duration = json['duration_minute'];
- }
- double get strength => strengthToValue(consume, duration);
- String strengthLabel() {
- return strengthToLabel(consume, duration);
- }
- int? value(String? type) => type == "consume" ? consume : duration;
- }
- const strengthArr = ["低强度", "中等", "高强度", "剧烈", "高负荷"];
- const strengthDetails = ["该级别适用于恢复和基础心血功能训练,可以提高心脏的泵血能力和肌肉使用氧气的能力", "可以适当增强心肺功能,获得更强耐力", "可以增强力量和肌肉耐力,提高厌氧能力和乳酸阈值", "有利于增强机体内肌肉的含量,加快代谢,使肌肉骨骼更加强壮", "可以增加个人机体的极限,对人体素质有很大提高;此时强度过大,心肺对全身的肌肉、细胞供氧不足,可能会出现无力、虚脱等症状"];
- const strengthColors = [const Color(0xffFFBFA8), const Color(0xffFF9D77), const Color(0xffFF5B1D), const Color(0xffD93D01), const Color(0xff9C2B00)];
- double strengthToValue(int? consume, int? duration) {
- if (duration == null || consume == null) return 0.0;
- if (duration == 0 || consume == 0) return 0.0;
- double result = consume / duration * 60.0;
- return result;
- }
- String strengthToLabel(int? consume, int? duration) {
- double v = metNum(consume, (duration ?? 0) ~/ 60);
- return strengthMetToLabel(v);
- }
- String metToLabel(double met) {
- return strengthMetToLabel(met);
- }
- String metToDetail(double met) {
- var label = metToLabel(met);
- return strengthDetails[strengthArr.indexOf(label)];
- }
- Color metToColor(double met) {
- var label = metToLabel(met);
- return strengthColors[strengthArr.indexOf(label)];
- }
- String strengthMetToLabel(double met) {
- double v = met;
- if (v == 0) return strengthArr[0];
- if (gender == 1) {
- if (v < 4.0) {
- return strengthArr[0];
- } else if (v < 6.0) {
- return strengthArr[1];
- } else if (v < 8.0) {
- return strengthArr[2];
- } else if (v < 10.0) {
- return strengthArr[3];
- } else {
- return strengthArr[4];
- }
- } else {
- if (v < 2.8) {
- return strengthArr[0];
- } else if (v < 4.4) {
- return strengthArr[1];
- } else if (v < 6.0) {
- return strengthArr[2];
- } else if (v < 7.6) {
- return strengthArr[3];
- } else {
- return strengthArr[4];
- }
- }
- }
- String met(int? consume, int? duration) {
- return metNum(consume, duration).toStringAsFixed(1);
- }
- double metNum(int? consume, int? duration) {
- // print("met $consume $duration");
- if (duration == null || consume == null) return 0;
- if (duration == 0 || consume == 0) return 0;
- // 卡路里消耗(大卡)=MET值× 0.0167 ×时间h(min)×体重(kg)
- return min(30.0, (consume / (0.0167 * duration * weight)));
- }
|