123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- import 'package:sport/provider/lib/view_state_model.dart';
- import 'package:sport/services/Converter.dart';
- class JogRecord {
- List<Records>? records;
- Sum? sum, avg;
- Best? best;
- int? activeDay;
- JogRecord({this.records, this.sum, this.best, this.activeDay = 0});
- JogRecord.fromJson(Map<String, dynamic> 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<String, dynamic> toJson() {
- final Map<String, dynamic> data = new Map<String, dynamic>();
- 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<String, dynamic> json) {
- distance = json['distance'];
- month = json['month'];
- year = json['year'];
- createdAt = json['created_at'];
- }
- Map<String, dynamic> toJson() {
- final Map<String, dynamic> data = new Map<String, dynamic>();
- 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<String, dynamic> 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<String, dynamic> toJson() {
- final Map<String, dynamic> data = new Map<String, dynamic>();
- 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>? kmDurationList;
- Best({this.distance, this.duration, this.kmDuration, this.kmDurationList});
- Best.fromJson(Map<String, dynamic> 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<String, dynamic> toJson() {
- final Map<String, dynamic> data = new Map<String, dynamic>();
- 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<String, dynamic> json) {
- id = json['id'];
- value = json['value'];
- createdAt = json['created_at'];
- }
- Map<String, dynamic> toJson() {
- final Map<String, dynamic> data = new Map<String, dynamic>();
- 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<String, dynamic> json) {
- id = json['id'];
- createdAt = json['created_at'];
- distance = json['distance'];
- duration = json['duration'];
- }
- Map<String, dynamic> toJson() {
- final Map<String, dynamic> data = new Map<String, dynamic>();
- data['id'] = this.id;
- data['created_at'] = this.createdAt;
- data['distance'] = this.distance;
- data['duration'] = this.duration;
- return data;
- }
- }
|