import 'package:sport/bean/rank_game_info.dart'; import 'package:sport/bean/sport_index.dart'; import 'package:sport/bean/sport_target.dart'; import 'package:sport/services/Converter.dart'; import 'package:sport/utils/DateFormat.dart'; import 'game.dart' as Game; import 'user.dart'; class SportDetail { int durationTotalDay = 0; int durationTarget = 0; SportTarget? target; NextAchievement? nextAchievement; RecordsTodaySum? recordsTodaySum, recordsTodayAvg; List? recordsToday; List? gamesSum; List? achievements; int step = 0; int sportTimes = 0; List targetFinish = []; List exerDay = []; int exerDayTotal = 0; 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}); SportDetail.fromJson(Map json) { durationTotalDay = json['duration_total_day']; durationTarget = json['duration_target']; step = json['step']; sportTimes = json['sport_times']; target = json['target'] != null ? new SportTarget.fromJson(json['target']) : null; nextAchievement = json['next_achievement'] != null ? new NextAchievement.fromJson(json['next_achievement']) : null; recordsTodaySum = json['records_today_sum'] != null ? new RecordsTodaySum.fromJson(json['records_today_sum']) : null; recordsTodayAvg = json['records_today_avg'] != null ? new RecordsTodaySum.fromJson(json['records_today_avg']) : null; if (json['records_today'] != null) { recordsToday = []; json['records_today'].forEach((v) { recordsToday!.add(new RecordsTodaySum.fromJson(v)); }); } if (json['games_sum'] != null) { gamesSum = []; json['games_sum'].forEach((v) { gamesSum!.add(new GamesSum.fromJson(v)); }); } if (json['achievements'] != null) { achievements = []; json['achievements'].forEach((v) { achievements!.add(new Achievement.fromJson(v)); }); } if (json['target_finish'] != null) { targetFinish = json['target_finish']; } if (json['exer_day'] != null) { exerDay = json['exer_day']; } } Map toJson() { final Map data = new Map(); data['duration_total_day'] = this.durationTotalDay; data['duration_target'] = this.durationTarget; data['step'] = this.step; data['sport_times'] = this.sportTimes; if (this.target != null) { data['target'] = this.target!.toJson(); } if (this.nextAchievement != null) { data['next_achievement'] = this.nextAchievement!.toJson(); } if (this.recordsTodaySum != null) { data['records_today_sum'] = this.recordsTodaySum!.toJson(); } if (this.recordsToday != null) { data['records_today'] = this.recordsToday!.map((v) => v.toJson()).toList(); } if (this.gamesSum != null) { data['games_sum'] = this.gamesSum!.map((v) => v.toJson()).toList(); } if (this.achievements != null) { data['achievements'] = this.achievements!.map((v) => v.toJson()).toList(); } return data; } } class NextAchievement { Achievement? achievement; int? diff; NextAchievement({this.achievement, this.diff}); NextAchievement.fromJson(Map json) { achievement = json['achievement'] != null ? new Achievement.fromJson(json['achievement']) : null; diff = json['condition_count_diff']; } Map toJson() { final Map data = new Map(); if (this.achievement != null) { data['achievement'] = this.achievement!.toJson(); } data['condition_count_diff'] = this.diff; return data; } } class RecordsTodaySum { int id = 0; int? userId; int consume = 0; int consume_game = 0; int consume_jog = 0; int consume_daily = 0; int duration = 0; int duration_game = 0; int duration_jog = 0; double durationMin = 0; double durationMinGame = 0; double durationMinJog = 0; int step = 0; int step_game = 0; int step_jog = 0; int step_daily = 0; int distance = 0; int distance_game = 0; int distance_jog = 0; int distance_daily = 0; int times = 0; int times_game = 0; int times_jog = 0; String? createdAt; int crouch = 0; double crouchRate = 0; int jump = 0; double jumpRate = 0; int? screen; double stepRate = 0.0; double stepRateGame = 0.0; double stepRateJog = 0.0; double score = 0; double scoreMax = 0; double consumeRate = 0; int year = 0; int month = 0; double met = 0.0; int? mode; String? group; RecordsTodaySum({ this.id = 0, this.userId, this.duration = 0, this.createdAt, this.consume = 0, this.jump = 0, this.crouch = 0, this.screen, this.score = 0, this.step = 0, this.times = 0, this.year = 0, this.month = 0, }); RecordsTodaySum.fromJson(Map json) { id = json['id'] ?? 0; userId = json['user_id']; consume = json['consume'] ?? 0; consume_game = json['consume_game'] ?? 0; consume_jog = json['consume_jog'] ?? 0; consume_daily = json['consume_daily'] ?? 0; duration = json['duration'] ?? json['duration_minute'] ?? 0; duration_game = json['duration_game'] ?? 0; duration_jog = json['duration_jog'] ?? 0; durationMin = json['duration'] != null ? (Converter.toDouble(json['duration']) / 60).round().toDouble() : Converter.toDouble(json['duration_min'] ?? json['duration_minute']); durationMinGame = json['duration_game'] != null ?(Converter.toDouble(json['duration_game']) / 60).round().toDouble() : Converter.toDouble(json['duration_game_min']); durationMinJog = json['duration_jog'] != null ?(Converter.toDouble(json['duration_jog']) / 60).round().toDouble() : Converter.toDouble(json['duration_jog_min']); step = json['step'] ?? 0; step_game = json['step_game'] ?? 0; step_jog = json['step_jog'] ?? 0; step_daily = json['step_daily'] ?? 0; stepRate = Converter.toDouble(json['step_rate']); times = json['times'] ?? 0; times_game = json['times_game'] ?? 0; times_jog = json['times_jog'] ?? 0; distance = json['distance'] ?? 0; distance_game = json['distance_game'] ?? 0; distance_jog = json['distance_jog'] ?? 0; distance_daily = json['distance_daily'] ?? 0; createdAt = json['created_at']; jump = json['jump'] ?? 0; jumpRate = Converter.toDouble(json['jump_rate']); crouch = json['crouch'] ?? 0; crouchRate = Converter.toDouble(json['crouch_rate']); screen = json['screen']; score = Converter.toDouble(json['score']); times = json['times'] ?? 0; step = json['step'] ?? 0; scoreMax = Converter.toDouble(json['score_max']); consumeRate = Converter.toDouble(json['consume_rate']); month = Converter.toInt(json['month']); year = Converter.toInt(json['year']); met = Converter.toDouble(json['met']); mode = json['mode']; group = json['play_group']; } Map toJson() { final Map data = new Map(); data['id'] = this.id; data['user_id'] = this.userId; data['duration'] = this.duration; data['duration_min'] = this.durationMin; data['created_at'] = this.createdAt; data['consume'] = this.consume; data['consume_daily'] = this.consume_daily; data['consume_game'] = this.consume_game; data['consume_jog'] = this.consume_jog; data['jump'] = this.jump; data['crouch'] = this.crouch; data['screen'] = this.screen; data['times'] = this.times; return data; } String get tag => this.createdAt?.split(" ")[0] ?? ""; String get title { if (this.createdAt?.isNotEmpty == true) { return DateFormat.formatCreateAtYYYYMMDDHHmm(this.createdAt!); } return ""; } RecordsTodaySum operator +(RecordsTodaySum other) { this.times++; this.duration += other.duration; this.durationMin += other.durationMin; this.distance_daily += other.distance_daily; this.distance_game += other.distance_game; this.distance_jog += other.distance_jog; this.consume += other.consume; this.consume_daily += other.consume_daily; this.consume_game += other.consume_game; this.consume_jog += other.consume_jog; this.step += other.step; this.step_daily += other.step_daily; this.step_game += other.step_game; this.step_jog += other.step_jog; this.crouch += other.crouch; this.jump += this.jump; this.createdAt = other.createdAt; return this; } bool isSameDay(int day) { if (createdAt == null) return false; DateTime date = DateTime.parse(createdAt!); // print("11111111111111111111 $date ${date.day} == $day"); return date.day == day; } bool isSameHour(int hour) { if (createdAt == null) return false; DateTime date = DateTime.parse(createdAt!); return date.hour == hour; } String getDate(int type) { if (type == 3) { return "$year年${'$month'.padLeft(2, '0')}月"; } if (createdAt == null) return ""; DateTime date = DateTime.parse(createdAt!); switch (type) { case 0: return "${'${date.month}'.padLeft(2, '0')}月${'${date.day}'.padLeft(2, '0')}日"; case 1: return "${'${date.month}'.padLeft(2, '0')}月${'${date.day}'.padLeft(2, '0')}日"; case 2: return "${'${date.month}'.padLeft(2, '0')}月${'${date.day}'.padLeft(2, '0')}日"; case 3: return "${date.year}年${'${date.month}'.padLeft(2, '0')}月"; } return ""; } double getValue(int type) { switch (type) { case 0: return consume.toDouble(); case 1: return step.toDouble(); case 2: return durationMin.toDouble(); case 3: return met; } return 0; } } class RecordsToday { int? id; int? userId; int? duration; String? createdAt; int? month; int? consume; int? gameId; int? jumpCount; int? crouchCount; double? score; String? lastPlayAt; String? name; String? cover; double? todayScoreMax; int? durationTotalMinute; int? userCount; int? times; int? year; double? met; 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}); RecordsToday.fromJson(Map json) { id = json['id']; userId = json['user_id']; duration = json['duration']; createdAt = json['created_at']; month = json['month']; consume = json['consume']; gameId = json['game_id']; jumpCount = json['jump']; crouchCount = json['crouch']; score = Converter.toDouble(json['score']); lastPlayAt = json['last_play_at']; name = json['name']; cover = json['cover']; todayScoreMax = Converter.toDouble(json['today_score_max']); durationTotalMinute = json['duration_minute']; userCount = json['user_count']; times = json['times']; met = Converter.toDouble(json['met']); } Map toJson() { final Map data = new Map(); data['id'] = this.id; data['user_id'] = this.userId; data['duration'] = this.duration; data['created_at'] = this.createdAt; data['consume'] = this.consume; data['game_id'] = this.gameId; data['jump_count'] = this.jumpCount; data['crouch_count'] = this.crouchCount; data['score'] = this.score; return data; } } class GamesSum { int? id; int? userId; int? gameId; String? lastPlayAt; int? playCount; int durationTotal = 0; double scoreTotal = 0; int consumeTotal = 0; double? scoreMax; Game.GameInfoData? game; GamesSum.fromJson(Map json) { id = json['id']; userId = json['user_id']; gameId = json['game_id']; lastPlayAt = json['last_play_at']; playCount = json['times']; durationTotal = json['duration']; scoreTotal = Converter.toDouble(json['score']); consumeTotal = json['consume']; scoreMax = Converter.toDouble(json['score_max']); game = json['game'] != null ? new Game.GameInfoData.fromJson(json['game']) : null; } Map toJson() { final Map data = new Map(); data['id'] = this.id; data['user_id'] = this.userId; data['game_id'] = this.gameId; data['last_play_at'] = this.lastPlayAt; data['times'] = this.playCount; data['duration'] = this.durationTotal; data['score_total'] = this.scoreTotal; data['consume'] = this.consumeTotal; data['score_max'] = this.scoreMax; data['game'] = this.game; return data; } } class SportDetailSimple { RecordsTodaySum? sum, avg; List? records; List targetFinish = []; List exerDay = []; int exerDayTotal = 0; SportTarget? target; SportDetailSimple({this.sum, this.records}); SportDetailSimple.fromJson(Map json) { sum = json['sum'] != null ? new RecordsTodaySum.fromJson(json['sum']) : null; avg = json['avg'] != null ? new RecordsTodaySum.fromJson(json['avg']) : null; if (json['records'] != null) { records = []; json['records'].forEach((v) { records!.add(new RecordsTodaySum.fromJson(v)); }); } if (json['target_finish'] != null) { targetFinish = []; json['target_finish'].forEach((v) { targetFinish.add(v as int); }); } if (json['exer_day'] != null) { exerDay = []; json['target_finish'].forEach((v) { exerDay.add(v as int); }); } exerDayTotal = Converter.toInt(json['exer_day_total']); target = json['target'] != null ? new SportTarget.fromJson(json['target']) : null; } } class SportHistory { int year = 0; List> data = []; SportHistory.fromJson(Map json) { year = Converter.toInt(json['year']); if (json['data'] != null) { data = []; json['data'].forEach((v) { List day = []; v.forEach((v) { day.add(Converter.toInt(v)); }); data.add(day); }); } } }