import 'package:sport/provider/lib/view_state_model.dart'; import 'package:sport/services/Converter.dart'; class JogRecord { List? records; Sum? sum, avg; Best? best; int? activeDay; JogRecord({this.records, this.sum, this.best, this.activeDay = 0}); JogRecord.fromJson(Map json) { try { if (json['records'] != null) { records = []; json['records'].forEach((v) { records!.add(new Records.fromJson(v)); }); } sum = json['sum'] != null ? new Sum.fromJson(json['sum']) : null; avg = json['avg'] != null ? new Sum.fromJson(json['avg']) : null; best = json['best'] != null ? new Best.fromJson(json['best']) : null; activeDay = json['active_day'] ?? 0; } catch (e, stack) { print(e); printErrorStack(e, stack); } } Map toJson() { final Map data = new Map(); if (this.records != null) { data['records'] = this.records!.map((v) => v.toJson()).toList(); } if (this.sum != null) { data['sum'] = this.sum!.toJson(); } if (this.best != null) { data['best'] = this.best!.toJson(); } return data; } } class Records { int? distance; int? month; int? year; String? createdAt; Records({this.distance, this.month}); Records.fromJson(Map json) { distance = json['distance']; month = json['month']; year = json['year']; createdAt = json['created_at']; } Map toJson() { final Map data = new Map(); data['distance'] = this.distance; data['month'] = this.month; data['year'] = this.year; return data; } } class Sum { int? distance; int? duration; int durationMin = 0; int? times; int? consume; double? consumeAvg; int? kmDurationAvg; int? stepRateAvg; double? stepDistanceAvg; double met = 0.0; Sum( {this.distance, this.duration, this.times, this.consume, this.consumeAvg, this.kmDurationAvg, this.stepRateAvg, this.stepDistanceAvg}); Sum.fromJson(Map json) { distance = Converter.toInt(json['distance']); duration = Converter.toInt(json['duration']); durationMin = Converter.toInt(json['duration_min']); times = Converter.toInt(json['times']); consume = Converter.toInt(json['consume']); consumeAvg = Converter.toDouble(json['consume_avg']); kmDurationAvg = Converter.toInt(json['km_duration_avg']); stepRateAvg = Converter.toInt(json['step_rate_avg']); stepDistanceAvg = Converter.toDouble(json['step_distance_avg']); met = Converter.toDouble(json['met']); } Map toJson() { final Map data = new Map(); data['distance'] = this.distance; data['duration'] = this.duration; data['times'] = this.times; data['consume'] = this.consume; data['consume_avg'] = this.consumeAvg; data['km_duration_avg'] = this.kmDurationAvg; data['step_rate_avg'] = this.stepRateAvg; data['step_distance_avg'] = this.stepDistanceAvg; return data; } double get speed{ if((this.duration ?? 0) > 0){ return (this.distance ?? 0) * 3.6 / this.duration!; } return 0; } int durationWeek(int day){ if((this.duration ?? 0) > 0){ return Converter.toInt((this.duration ?? 0) / 60 / (day / 7)); } return 0; } int consumeWeek(int day){ if((this.consume ?? 0) > 0){ return Converter.toInt((this.consume ?? 0) / (day / 7)); } return 0; } } class Best { Distance? distance; Distance? duration; Distance? kmDuration; List? kmDurationList; Best({this.distance, this.duration, this.kmDuration, this.kmDurationList}); Best.fromJson(Map json) { distance = json['distance'] != null ? new Distance.fromJson(json['distance']) : null; duration = json['duration'] != null ? new Distance.fromJson(json['duration']) : null; kmDuration = json['km_duration'] != null ? new Distance.fromJson(json['km_duration']) : null; if (json['km_duration_list'] != null) { kmDurationList = []; json['km_duration_list'].forEach((v) { kmDurationList!.add(new KmDurationList.fromJson(v)); }); } } Map toJson() { final Map data = new Map(); if (this.distance != null) { data['distance'] = this.distance!.toJson(); } if (this.duration != null) { data['duration'] = this.duration!.toJson(); } if (this.kmDuration != null) { data['km_duration'] = this.kmDuration!.toJson(); } if (this.kmDurationList != null) { data['km_duration_list'] = this.kmDurationList!.map((v) => v.toJson()).toList(); } return data; } } class Distance { int? id; int? value; String? createdAt; Distance({this.id, this.value, this.createdAt}); Distance.fromJson(Map json) { id = json['id']; value = json['value']; createdAt = json['created_at']; } Map toJson() { final Map data = new Map(); data['id'] = this.id; data['value'] = this.value; data['created_at'] = this.createdAt; return data; } } class KmDurationList { int? id; String? createdAt; int? distance; int? duration; KmDurationList({this.id, this.createdAt, this.distance, this.duration}); KmDurationList.fromJson(Map json) { id = json['id']; createdAt = json['created_at']; distance = json['distance']; duration = json['duration']; } Map toJson() { final Map data = new Map(); data['id'] = this.id; data['created_at'] = this.createdAt; data['distance'] = this.distance; data['duration'] = this.duration; return data; } }