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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> {
|
||||
|
||||
CustomerTrainingPlan? _myPlan;
|
||||
CustomerTrainingPlanDetails? _myDetail;
|
||||
CustomerTrainingPlanDetails? _backupDetail;
|
||||
|
||||
TrainingPlan? _myTrainingPlan;
|
||||
final List<String> trainingPlanDayNames = [];
|
||||
@@ -75,6 +76,7 @@ class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> {
|
||||
yield TrainingPlanFinished();
|
||||
} else if (event is TrainingPlanWeightChange) {
|
||||
yield TrainingPlanExerciseLoading();
|
||||
print("New weight: ${event.weight}");
|
||||
event.detail.weight = event.weight;
|
||||
|
||||
yield TrainingPlanExerciseReady();
|
||||
@@ -108,10 +110,19 @@ class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> {
|
||||
} else if (event is TrainingPlanWeightChangeRecalculate) {
|
||||
yield TrainingPlanExerciseLoading();
|
||||
|
||||
print("Base1RM ${event.detail.base1RM}");
|
||||
if (event.detail.base1RM > 0) {
|
||||
if (event.detail.baseOneRepMax > 0) {
|
||||
if (_myTrainingPlan == null) {
|
||||
setTrainingPlanFromCache();
|
||||
}
|
||||
final int originalRepeats = trainingPlanRepository.getOriginalRepeats(_myTrainingPlan!.trainingPlanId, event.detail);
|
||||
event.detail.repeats =
|
||||
Common.calculateQuantityByChangedWeight(event.detail.base1RM, event.weight, event.detail.repeats!.toDouble());
|
||||
Common.calculateQuantityByChangedWeight(event.detail.baseOneRepMax, event.weight, originalRepeats.toDouble());
|
||||
|
||||
print("Base1RM ${event.detail.baseOneRepMax} repeats: ${event.detail.repeats}");
|
||||
if (event.detail.repeats! < 1) {
|
||||
event.detail.repeats = 1;
|
||||
event.detail.weight = trainingPlanRepository.getOriginalWeight(_myTrainingPlan!.trainingPlanId, event.detail);
|
||||
}
|
||||
ExerciseSaveStream().repeats = event.detail.repeats!;
|
||||
ExerciseSaveStream().getStreamController().add(true);
|
||||
}
|
||||
@@ -136,7 +147,7 @@ class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> {
|
||||
yield TrainingPlanReady();
|
||||
throw Exception("Please type your repeats!");
|
||||
}
|
||||
print("ExerciseTypeUID: ${event.detail.exerciseTypeId}");
|
||||
print("SAVE for ExerciseTypeID: ${event.detail.exerciseTypeId} weight: ${event.detail.weight}");
|
||||
if (event.detail.weight == -3) {
|
||||
print("DropSet");
|
||||
event.detail.state = ExercisePlanDetailState.finished;
|
||||
@@ -152,8 +163,6 @@ class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> {
|
||||
event.detail.exercises.add(exercise);
|
||||
if (this.isAllDetailsSameExerciseFinished(event.detail)) {
|
||||
event.detail.state = ExercisePlanDetailState.finished;
|
||||
} else if (event.detail.exercises.length >= 0) {
|
||||
event.detail.state = ExercisePlanDetailState.inProgress;
|
||||
}
|
||||
// recalculate the weight to the original planned repeats for the next details
|
||||
if (exercise.unitQuantity != null && exercise.unitQuantity! > 0) {
|
||||
@@ -165,23 +174,23 @@ class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> {
|
||||
nextDetail.customerTrainingPlanDetailsId != event.detail.customerTrainingPlanDetailsId) {
|
||||
print("recalculating -2 ${event.detail.customerTrainingPlanDetailsId}");
|
||||
trainingPlanRepository.recalculateDetail(_myPlan!.trainingPlanId!, event.detail, nextDetail);
|
||||
nextDetail.base1RM = Common.calculate1RM(nextDetail.weight!, nextDetail.repeats!.toDouble());
|
||||
nextDetail.baseOneRepMax = Common.calculate1RM(nextDetail.weight!, nextDetail.repeats!.toDouble());
|
||||
} else if (nextDetail.exerciseTypeId == event.detail.exerciseTypeId && weightFromPlan == -1 && nextDetail.set! > 1) {
|
||||
print("recalculating -1 ${event.detail.customerTrainingPlanDetailsId}");
|
||||
nextDetail = trainingPlanRepository.recalculateDetailFixRepeats(_myPlan!.trainingPlanId!, nextDetail);
|
||||
nextDetail.base1RM = Common.calculate1RM(nextDetail.weight!, nextDetail.repeats!.toDouble());
|
||||
nextDetail.baseOneRepMax = Common.calculate1RM(nextDetail.weight!, nextDetail.repeats!.toDouble());
|
||||
} else if (nextDetail.exerciseTypeId == event.detail.exerciseTypeId && nextDetail.weight == -1 && nextDetail.set! == 1) {
|
||||
print("recalculating -1, set 1 ${event.detail.customerTrainingPlanDetailsId}");
|
||||
nextDetail = trainingPlanRepository.recalculateDetailFixRepeatsSet1(_myPlan!.trainingPlanId!, nextDetail, event.detail);
|
||||
nextDetail.base1RM = Common.calculate1RM(nextDetail.weight!, nextDetail.repeats!.toDouble());
|
||||
} else if (nextDetail.exerciseTypeId == event.detail.exerciseTypeId &&
|
||||
nextDetail.baseOneRepMax = Common.calculate1RM(nextDetail.weight!, nextDetail.repeats!.toDouble());
|
||||
} /* else if (nextDetail.exerciseTypeId == event.detail.exerciseTypeId &&
|
||||
weightFromPlan == -2 &&
|
||||
nextDetail.set! == 1 &&
|
||||
nextDetail.exercises.length == 0) {
|
||||
print("recalculating -1/ no exercise, set 1 ${event.detail.customerTrainingPlanDetailsId}");
|
||||
nextDetail = trainingPlanRepository.recalculateDetailFixRepeatsSet1(_myPlan!.trainingPlanId!, nextDetail, event.detail);
|
||||
nextDetail.base1RM = Common.calculate1RM(nextDetail.weight!, nextDetail.repeats!.toDouble());
|
||||
}
|
||||
nextDetail.baseOneRepMax = Common.calculate1RM(nextDetail.weight!, nextDetail.repeats!.toDouble());
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -288,12 +297,42 @@ class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> {
|
||||
}
|
||||
Track().track(TrackingEvent.training_plan_custom, eventValue: event.exerciseType.name);
|
||||
yield TrainingPlanReady();
|
||||
} else if (event is TrainingPlanChangeCancel) {
|
||||
yield TrainingPlanLoading();
|
||||
print("Backup $_backupDetail");
|
||||
if (_backupDetail != null) {
|
||||
event.detail.repeats = _backupDetail!.repeats;
|
||||
event.detail.weight = _backupDetail!.weight;
|
||||
}
|
||||
yield TrainingPlanReady();
|
||||
} else if (event is TrainingPlanFinishDropset) {
|
||||
yield TrainingPlanLoading();
|
||||
event.detail.state = ExercisePlanDetailState.finished;
|
||||
yield TrainingPlanReady();
|
||||
}
|
||||
} on Exception catch (e) {
|
||||
yield TrainingPlanError(message: e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
void backupDetail(CustomerTrainingPlanDetails detail) {
|
||||
if (_backupDetail == null) {
|
||||
_backupDetail = CustomerTrainingPlanDetails();
|
||||
}
|
||||
_backupDetail!.copy(detail);
|
||||
}
|
||||
|
||||
void setTrainingPlanFromCache() {
|
||||
if (_myPlan == null) {
|
||||
setMyPlan(Cache().myTrainingPlan);
|
||||
}
|
||||
Cache().getTrainingPlans()!.forEach((element) {
|
||||
if (_myPlan!.trainingPlanId == element.trainingPlanId) {
|
||||
_myTrainingPlan = element;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void addNewPlan() {
|
||||
if (Cache().userLoggedIn == null) {
|
||||
throw Exception("Please log in");
|
||||
@@ -603,7 +642,7 @@ class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> {
|
||||
final String day = dayNames[this.activeDayIndex];
|
||||
CustomerTrainingPlanDetails? prev;
|
||||
for (var detail in _myPlan!.days[day]!) {
|
||||
//print("Offset detail $detail");
|
||||
print("Offset detail $detail");
|
||||
if (detail.state == ExercisePlanDetailState.inProgress || detail.state == ExercisePlanDetailState.start) {
|
||||
prev = detail;
|
||||
break;
|
||||
@@ -618,7 +657,7 @@ class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> {
|
||||
}
|
||||
int index = indexInStart > indexInProgress ? indexInStart : indexInProgress;
|
||||
offset = (index) * 300;
|
||||
//print("Offset: $offset day: $day ($indexInStart, $indexInProgress)");
|
||||
print("Offset: $offset day: $day ($indexInStart, $indexInProgress)");
|
||||
return offset;
|
||||
}
|
||||
|
||||
@@ -770,10 +809,16 @@ class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> {
|
||||
bool isAllDetailsSameExerciseFinished(CustomerTrainingPlanDetails detail) {
|
||||
bool allFinished = true;
|
||||
List<CustomerTrainingPlanDetails> list = getAllDetailsSameExercise(detail);
|
||||
//print("SAME count: ${list.length}");
|
||||
for (var listDetail in list) {
|
||||
//print("SAME $listDetail");
|
||||
if (listDetail.exercises.length >= listDetail.set!) {
|
||||
listDetail.state = ExercisePlanDetailState.finished;
|
||||
}
|
||||
allFinished =
|
||||
allFinished && (listDetail.exercises.length >= listDetail.set! || listDetail.state.equalsTo(ExercisePlanDetailState.skipped));
|
||||
}
|
||||
print("All finished: $allFinished for ${detail.exerciseTypeId}");
|
||||
return allFinished;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,6 +111,14 @@ class TrainingPlanAddExerciseType extends TrainingPlanEvent {
|
||||
const TrainingPlanAddExerciseType();
|
||||
}
|
||||
|
||||
class TrainingPlanChangeCancel extends TrainingPlanEvent {
|
||||
final CustomerTrainingPlanDetails detail;
|
||||
const TrainingPlanChangeCancel({required this.detail});
|
||||
|
||||
@override
|
||||
List<Object> get props => [detail];
|
||||
}
|
||||
|
||||
class TrainingPlanDeleteExerciseType extends TrainingPlanEvent {
|
||||
final ExerciseType exerciseType;
|
||||
const TrainingPlanDeleteExerciseType({required this.exerciseType});
|
||||
@@ -126,3 +134,11 @@ class TrainingPlanCustomAddLoad extends TrainingPlanEvent {
|
||||
@override
|
||||
List<Object> get props => [exerciseType];
|
||||
}
|
||||
|
||||
class TrainingPlanFinishDropset extends TrainingPlanEvent {
|
||||
final CustomerTrainingPlanDetails detail;
|
||||
const TrainingPlanFinishDropset({required this.detail});
|
||||
|
||||
@override
|
||||
List<Object> get props => [detail];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user