WT 1.1.24+5 training plan fixes
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:aitrainer_app/bloc/training_plan/training_plan_bloc.dart';
|
||||
import 'package:aitrainer_app/model/cache.dart';
|
||||
import 'package:aitrainer_app/model/customer_training_plan_details.dart';
|
||||
@@ -22,6 +22,7 @@ class TrainingEvaluationBloc extends Bloc<TrainingEvaluationEvent, TrainingEvalu
|
||||
String totalLift = "0";
|
||||
String maxTotalLift = "0";
|
||||
String maxRepeats = "0";
|
||||
String totalRepeats = "0";
|
||||
DateTime? end;
|
||||
|
||||
List<TrainingEvaluationExercise> evaluationList = [];
|
||||
@@ -32,13 +33,14 @@ class TrainingEvaluationBloc extends Bloc<TrainingEvaluationEvent, TrainingEvalu
|
||||
) async* {
|
||||
try {
|
||||
if (event is TrainingEvaluationLoad) {
|
||||
yield TrainingEvaluationLoading();
|
||||
//yield TrainingEvaluationLoading();
|
||||
await saveResult();
|
||||
getDuration();
|
||||
getTotalLift();
|
||||
getMaxRepeats();
|
||||
getTotalRepeats();
|
||||
createEvaluationData();
|
||||
//getMaxTotalLift();
|
||||
getMaxLift();
|
||||
if (end == null || DateTime.now().difference(end!).inMinutes > 5) {
|
||||
yield TrainingEvaluationReady();
|
||||
} else {
|
||||
@@ -58,15 +60,11 @@ class TrainingEvaluationBloc extends Bloc<TrainingEvaluationEvent, TrainingEvalu
|
||||
}
|
||||
|
||||
trainingPlanBloc.getMyPlan()!.days[day]!.forEach((element) {
|
||||
//if (!element.state.equalsTo(ExercisePlanDetailState.extra)) {
|
||||
if (element.exerciseTypeId != null) {
|
||||
if (!findExerciseInEvaluationList(element.exerciseTypeId!)) {
|
||||
addEvaluationExercise(element);
|
||||
} else {
|
||||
//editEvaluationExercise(element);
|
||||
}
|
||||
}
|
||||
//}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -104,8 +102,8 @@ class TrainingEvaluationBloc extends Bloc<TrainingEvaluationEvent, TrainingEvalu
|
||||
exercise.type = TrainingEvaluationExerciseType.weightBased;
|
||||
exercise.oneRepMax = Common.calculate1RM(detail.weight!, detail.repeats!.toDouble());
|
||||
exercise.max1RM = getMax1RMByExerciseType(detail.exerciseTypeId!);
|
||||
exercise.totalLift = (detail.weight! * detail.repeats!).round();
|
||||
exercise.maxTotalLift = getMaxTotalLiftByExerciseType(detail.exerciseTypeId!).round();
|
||||
exercise.totalLift = getTotalLiftBySameExercise(detail.exerciseTypeId!);
|
||||
exercise.maxTotalLift = getMaxTotalLiftByExerciseType(detail.exerciseTypeId!);
|
||||
exercise.trend = this.getTrendWeight(exercise.oneRepMax!, exercise.max1RM, exercise.totalLift, exercise.maxTotalLift);
|
||||
}
|
||||
exercise.trendText = getTrendText(exercise.trend!);
|
||||
@@ -189,6 +187,36 @@ class TrainingEvaluationBloc extends Bloc<TrainingEvaluationEvent, TrainingEvalu
|
||||
totalLift = total.toStringAsFixed(0);
|
||||
}
|
||||
|
||||
double getTotalLiftBySameExercise(int exerciseTypeId) {
|
||||
if (trainingPlanBloc.getMyPlan() == null || trainingPlanBloc.getMyPlan()!.days[day] == null) {
|
||||
return 0;
|
||||
}
|
||||
double total = 0;
|
||||
trainingPlanBloc.getMyPlan()!.days[day]!.forEach((element) {
|
||||
if (element.exerciseTypeId == exerciseTypeId) {
|
||||
if (element.state.equalsTo(ExercisePlanDetailState.finished) && element.exerciseType!.unitQuantityUnit != null) {
|
||||
total += element.weight! * element.repeats!;
|
||||
}
|
||||
}
|
||||
});
|
||||
return total;
|
||||
}
|
||||
|
||||
void getMaxLift() {
|
||||
if (trainingPlanBloc.getMyPlan() == null || trainingPlanBloc.getMyPlan()!.days[day] == null) {
|
||||
return;
|
||||
}
|
||||
double max = 0;
|
||||
trainingPlanBloc.getMyPlan()!.days[day]!.forEach((element) {
|
||||
if (element.state.equalsTo(ExercisePlanDetailState.finished) && element.exerciseType!.unitQuantityUnit != null) {
|
||||
if (max < element.weight!) {
|
||||
max = element.weight!;
|
||||
}
|
||||
}
|
||||
});
|
||||
maxTotalLift = max.toStringAsFixed(0);
|
||||
}
|
||||
|
||||
void getMaxRepeats() {
|
||||
if (trainingPlanBloc.getMyPlan() == null || trainingPlanBloc.getMyPlan()!.days[day] == null) {
|
||||
return;
|
||||
@@ -205,16 +233,39 @@ class TrainingEvaluationBloc extends Bloc<TrainingEvaluationEvent, TrainingEvalu
|
||||
maxRepeats = max.toStringAsFixed(0);
|
||||
}
|
||||
|
||||
void getTotalRepeats() {
|
||||
if (trainingPlanBloc.getMyPlan() == null || trainingPlanBloc.getMyPlan()!.days[day] == null) {
|
||||
return;
|
||||
}
|
||||
int total = 0;
|
||||
trainingPlanBloc.getMyPlan()!.days[day]!.forEach((element) {
|
||||
if (element.state.equalsTo(ExercisePlanDetailState.finished) && element.exerciseType!.unit != "second") {
|
||||
print("Repeats ${element.repeats}");
|
||||
|
||||
total += element.repeats!;
|
||||
}
|
||||
});
|
||||
totalRepeats = total.toStringAsFixed(0);
|
||||
}
|
||||
|
||||
double getMaxTotalLiftByExerciseType(int exerciseTypeId) {
|
||||
if (Cache().getExercises() == null || Cache().getExercises()!.length == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
var now = new DateTime.now();
|
||||
var formatter = new DateFormat('yyyy-MM-dd');
|
||||
final String formattedToday = formatter.format(now);
|
||||
|
||||
double maxTotal = 0;
|
||||
Cache().getExercises()!.forEach((element) {
|
||||
if (element.exerciseTypeId == exerciseTypeId) {
|
||||
final double total = element.quantity! * element.unitQuantity!;
|
||||
if (maxTotal < total) {
|
||||
maxTotal = total;
|
||||
if (element.dateAdd != null) {
|
||||
final String formattedExerciseDate = formatter.format(element.dateAdd!);
|
||||
if (element.exerciseTypeId == exerciseTypeId && formattedToday != formattedExerciseDate) {
|
||||
final double total = element.quantity! * element.unitQuantity!;
|
||||
if (maxTotal < total) {
|
||||
maxTotal = total;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -226,12 +277,19 @@ class TrainingEvaluationBloc extends Bloc<TrainingEvaluationEvent, TrainingEvalu
|
||||
if (Cache().getExercises() == null || Cache().getExercises()!.length == 0) {
|
||||
return 0;
|
||||
}
|
||||
var now = new DateTime.now();
|
||||
var formatter = new DateFormat('yyyy-MM-dd');
|
||||
final String formattedToday = formatter.format(now);
|
||||
|
||||
double max1RM = 0;
|
||||
Cache().getExercises()!.forEach((element) {
|
||||
if (element.exerciseTypeId == exerciseTypeId) {
|
||||
final double oneRepMax = Common.calculate1RM(element.unitQuantity!, element.quantity!);
|
||||
if (max1RM < oneRepMax) {
|
||||
max1RM = oneRepMax;
|
||||
if (element.dateAdd != null) {
|
||||
final String formattedExerciseDate = formatter.format(element.dateAdd!);
|
||||
if (element.exerciseTypeId == exerciseTypeId && formattedToday != formattedExerciseDate) {
|
||||
final double oneRepMax = Common.calculate1RM(element.unitQuantity!, element.quantity!);
|
||||
if (max1RM < oneRepMax) {
|
||||
max1RM = oneRepMax;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -269,8 +327,8 @@ class TrainingEvaluationBloc extends Bloc<TrainingEvaluationEvent, TrainingEvalu
|
||||
}
|
||||
|
||||
double getTrendWeight(double oneRepMax, max1RM, totalLift, maxTotalLift) {
|
||||
double oneRepMaxRate = oneRepMax / max1RM;
|
||||
double totalLiftRate = totalLift / maxTotalLift;
|
||||
return (oneRepMaxRate + totalLiftRate) / 2;
|
||||
final double oneRepMaxRate = oneRepMax / max1RM;
|
||||
//double totalLiftRate = totalLift / maxTotalLift;
|
||||
return oneRepMaxRate;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user