WT 1.1.25+5 weight calculation fixes in the training
This commit is contained in:
parent
05cace39bf
commit
f1f20d12f2
@ -388,7 +388,7 @@
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
|
||||
CURRENT_PROJECT_VERSION = 4;
|
||||
CURRENT_PROJECT_VERSION = 5;
|
||||
DEVELOPMENT_TEAM = SFJJBDCU6Z;
|
||||
ENABLE_BITCODE = NO;
|
||||
FRAMEWORK_SEARCH_PATHS = (
|
||||
@ -531,7 +531,7 @@
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
|
||||
CURRENT_PROJECT_VERSION = 4;
|
||||
CURRENT_PROJECT_VERSION = 5;
|
||||
DEVELOPMENT_TEAM = SFJJBDCU6Z;
|
||||
ENABLE_BITCODE = NO;
|
||||
FRAMEWORK_SEARCH_PATHS = (
|
||||
@ -566,7 +566,7 @@
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
|
||||
CURRENT_PROJECT_VERSION = 4;
|
||||
CURRENT_PROJECT_VERSION = 5;
|
||||
DEVELOPMENT_TEAM = SFJJBDCU6Z;
|
||||
ENABLE_BITCODE = NO;
|
||||
FRAMEWORK_SEARCH_PATHS = (
|
||||
|
@ -163,45 +163,7 @@ class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> {
|
||||
}
|
||||
|
||||
// recalculate the weight to the original planned repeats for the next details
|
||||
int id = 0;
|
||||
if (exercise.unitQuantity != null && exercise.unitQuantity! > 0) {
|
||||
double calculatedWeight = 0;
|
||||
for (var nextDetail in _myPlan!.details) {
|
||||
if (nextDetail.exerciseTypeId == event.detail.exerciseTypeId) {
|
||||
if (id == 0 && nextDetail.customerTrainingPlanDetailsId == event.detail.customerTrainingPlanDetailsId) {
|
||||
id = nextDetail.customerTrainingPlanDetailsId!;
|
||||
}
|
||||
double weightFromPlan = trainingPlanRepository.getOriginalWeight(this.getMyPlan()!.trainingPlanId!, nextDetail);
|
||||
print("NextDetail detail: $nextDetail *** PlanWeight: $weightFromPlan");
|
||||
if (nextDetail.weight == -2 && nextDetail.customerTrainingPlanDetailsId != event.detail.customerTrainingPlanDetailsId) {
|
||||
print("Nr 1. - recalculating -2 ${event.detail.customerTrainingPlanDetailsId}");
|
||||
trainingPlanRepository.recalculateDetail(_myPlan!.trainingPlanId!, event.detail, nextDetail);
|
||||
nextDetail.baseOneRepMax = Common.calculate1RM(nextDetail.weight!, nextDetail.repeats!.toDouble());
|
||||
} else if (weightFromPlan == -1 && nextDetail.set! > 1 && nextDetail.exercises.length == 1) {
|
||||
print("Nr 2. recalculating -1 ${event.detail.customerTrainingPlanDetailsId}");
|
||||
nextDetail = trainingPlanRepository.recalculateDetailFixRepeats(_myPlan!.trainingPlanId!, nextDetail);
|
||||
nextDetail.baseOneRepMax = Common.calculate1RM(nextDetail.weight!, nextDetail.repeats!.toDouble());
|
||||
} else if (nextDetail.weight == -1 && nextDetail.set! == 1) {
|
||||
print("Nr 3. recalculating -1, set 1 ${event.detail.customerTrainingPlanDetailsId}");
|
||||
nextDetail = trainingPlanRepository.recalculateDetailFixRepeatsSet1(_myPlan!.trainingPlanId!, nextDetail, event.detail);
|
||||
nextDetail.baseOneRepMax = Common.calculate1RM(nextDetail.weight!, nextDetail.repeats!.toDouble());
|
||||
} else if (event.detail.set! == 1 &&
|
||||
(weightFromPlan == -2 || weightFromPlan == -1) &&
|
||||
nextDetail.customerTrainingPlanDetailsId! == id + 1) {
|
||||
print("Nr 4. recalculating after the first exercise ${event.detail.customerTrainingPlanDetailsId}");
|
||||
nextDetail = trainingPlanRepository.recalculateDetailFixRepeatsSet1(_myPlan!.trainingPlanId!, nextDetail, event.detail);
|
||||
nextDetail.baseOneRepMax = Common.calculate1RM(nextDetail.weight!, nextDetail.repeats!.toDouble());
|
||||
calculatedWeight = nextDetail.weight!;
|
||||
} else if (event.detail.set! == 1 &&
|
||||
(weightFromPlan == -2 || weightFromPlan == -1) &&
|
||||
nextDetail.customerTrainingPlanDetailsId! > id + 1) {
|
||||
print("Nr 5. recalculating after the second exercise ${event.detail.customerTrainingPlanDetailsId}");
|
||||
nextDetail.weight = calculatedWeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.recalculateNextDetails(event.detail);
|
||||
exercise.trainingPlanDetailsId = _myPlan!.trainingPlanId;
|
||||
|
||||
// save Exercise
|
||||
@ -230,6 +192,68 @@ class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> {
|
||||
}
|
||||
}
|
||||
|
||||
void recalculateNextDetails(CustomerTrainingPlanDetails eventDetail) {
|
||||
int id = 0;
|
||||
bool recalculate = false;
|
||||
|
||||
int baseCustomerTrainingPlanDetailsId = 0;
|
||||
if (eventDetail.exerciseType!.unitQuantity != null && eventDetail.weight! > 0) {
|
||||
double calculatedWeight = 0;
|
||||
for (var nextDetail in _myPlan!.details) {
|
||||
if (nextDetail.exerciseTypeId == eventDetail.exerciseTypeId) {
|
||||
if (id == 0 && nextDetail.customerTrainingPlanDetailsId == eventDetail.customerTrainingPlanDetailsId) {
|
||||
id = nextDetail.customerTrainingPlanDetailsId!;
|
||||
recalculate = true;
|
||||
}
|
||||
if (id == 0) {
|
||||
// we are after the first exercise
|
||||
baseCustomerTrainingPlanDetailsId = nextDetail.customerTrainingPlanDetailsId!;
|
||||
}
|
||||
double weightFromPlan = trainingPlanRepository.getOriginalWeight(this.getMyPlan()!.trainingPlanId!, nextDetail);
|
||||
print("NextDetail detail: $nextDetail *** PlanWeight: $weightFromPlan");
|
||||
if (nextDetail.weight == -2 && nextDetail.customerTrainingPlanDetailsId != eventDetail.customerTrainingPlanDetailsId) {
|
||||
print("Nr 1. - recalculating -2 ${eventDetail.customerTrainingPlanDetailsId}");
|
||||
trainingPlanRepository.recalculateDetail(_myPlan!.trainingPlanId!, eventDetail, nextDetail);
|
||||
nextDetail.baseOneRepMax = Common.calculate1RM(nextDetail.weight!, nextDetail.repeats!.toDouble());
|
||||
} /* else if (weightFromPlan == -1 && nextDetail.set! > 1 && nextDetail.exercises.length == 1) {
|
||||
print("Nr 2. recalculating -1 ${event.detail.customerTrainingPlanDetailsId}");
|
||||
nextDetail = trainingPlanRepository.recalculateDetailFixRepeats(_myPlan!.trainingPlanId!, nextDetail);
|
||||
nextDetail.baseOneRepMax = Common.calculate1RM(nextDetail.weight!, nextDetail.repeats!.toDouble());
|
||||
} */
|
||||
else if (nextDetail.weight == -1 && nextDetail.set! == 1) {
|
||||
print("Nr 3. recalculating -1, set 1 ${eventDetail.customerTrainingPlanDetailsId}");
|
||||
nextDetail = trainingPlanRepository.recalculateDetailFixRepeatsSet1(_myPlan!.trainingPlanId!, nextDetail, eventDetail);
|
||||
nextDetail.baseOneRepMax = Common.calculate1RM(nextDetail.weight!, nextDetail.repeats!.toDouble());
|
||||
} else if (eventDetail.set! == 1 &&
|
||||
(weightFromPlan == -2 || weightFromPlan == -1) &&
|
||||
nextDetail.customerTrainingPlanDetailsId! == id + 1 &&
|
||||
recalculate) {
|
||||
print("Nr 4. recalculating after the first exercise ${eventDetail.customerTrainingPlanDetailsId}");
|
||||
nextDetail = trainingPlanRepository.recalculateDetailFixRepeatsSet1(_myPlan!.trainingPlanId!, nextDetail, eventDetail);
|
||||
nextDetail.baseOneRepMax = Common.calculate1RM(nextDetail.weight!, nextDetail.repeats!.toDouble());
|
||||
calculatedWeight = nextDetail.weight!;
|
||||
} else if (eventDetail.set! == 1 &&
|
||||
(weightFromPlan == -2 || weightFromPlan == -1) &&
|
||||
nextDetail.customerTrainingPlanDetailsId! > id + 1 &&
|
||||
recalculate) {
|
||||
print("Nr 5. recalculating after the second exercise ${eventDetail.customerTrainingPlanDetailsId}");
|
||||
nextDetail = trainingPlanRepository.recalculateDetailFixRepeatsSet1(_myPlan!.trainingPlanId!, nextDetail, eventDetail);
|
||||
nextDetail.baseOneRepMax = Common.calculate1RM(nextDetail.weight!, nextDetail.repeats!.toDouble());
|
||||
} else if (id != 0) {
|
||||
// calculate weight and repeat based on the first baseOneRepMax
|
||||
if (baseCustomerTrainingPlanDetailsId != 0) {
|
||||
CustomerTrainingPlanDetails? firstDetail = trainingPlanRepository.getDetailById(_myPlan, baseCustomerTrainingPlanDetailsId);
|
||||
if (firstDetail != null) {
|
||||
print("Nr 6. recalculating based on the first exercise $nextDetail");
|
||||
nextDetail = trainingPlanRepository.recalculateDetailFixRepeatsSet1(_myPlan!.trainingPlanId!, nextDetail, firstDetail);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _onChangeAlternate(TrainingPlanAlternateChange event, Emitter<TrainingPlanState> emit) {
|
||||
emit(TrainingPlanLoading());
|
||||
if (_myPlan == null || _myPlan!.details.length == 0) {
|
||||
@ -268,6 +292,8 @@ class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> {
|
||||
void _onSkipExercise(TrainingPlanSkipExercise event, Emitter<TrainingPlanState> emit) async {
|
||||
emit(TrainingPlanLoading());
|
||||
event.detail.state = ExercisePlanDetailState.skipped;
|
||||
this.recalculateNextDetails(event.detail);
|
||||
print(" * Skipping ${event.detail.exerciseTypeId}");
|
||||
Cache().myTrainingPlan = _myPlan;
|
||||
await Cache().saveMyTrainingPlan();
|
||||
if (isDayDone()) {
|
||||
@ -450,8 +476,8 @@ class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> {
|
||||
}
|
||||
_alternatives[detail.customerTrainingPlanDetailsId!]!.add(detail);
|
||||
}
|
||||
print(
|
||||
"Created alternaties for ${detail.exerciseTypeId} and repeat ${detail.repeats} -- ${_alternatives[detail.customerTrainingPlanDetailsId!]}");
|
||||
//print(
|
||||
// "Created alternaties for ${detail.exerciseTypeId} and repeat ${detail.repeats} -- ${_alternatives[detail.customerTrainingPlanDetailsId!]}");
|
||||
});
|
||||
}
|
||||
|
||||
@ -764,7 +790,9 @@ class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> {
|
||||
}
|
||||
}
|
||||
//print("Next detail $next");
|
||||
|
||||
if (next != null) {
|
||||
//this.recalculateNextDetails(next);
|
||||
}
|
||||
return next;
|
||||
}
|
||||
|
||||
|
@ -84,6 +84,23 @@ class TrainingPlanRepository {
|
||||
return plan;
|
||||
}
|
||||
|
||||
CustomerTrainingPlanDetails? getDetailById(CustomerTrainingPlan? plan, int customerTrainingPlanDetailsId) {
|
||||
CustomerTrainingPlanDetails? foundDetail;
|
||||
|
||||
if (plan == null || plan.details.length == 0 || customerTrainingPlanDetailsId == 0) {
|
||||
return foundDetail;
|
||||
}
|
||||
|
||||
for (var detail in plan.details) {
|
||||
if (detail.customerTrainingPlanDetailsId == customerTrainingPlanDetailsId) {
|
||||
foundDetail = detail;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return foundDetail;
|
||||
}
|
||||
|
||||
CustomerTrainingPlanDetails createAlternativeDetail(
|
||||
CustomerTrainingPlan plan, CustomerTrainingPlanDetails detail, TrainingPlanDetail elem, int exerciseTypeId) {
|
||||
CustomerTrainingPlanDetails alternativeDetail = CustomerTrainingPlanDetails();
|
||||
@ -256,7 +273,7 @@ class TrainingPlanRepository {
|
||||
//detail.weight = Common.calculateWeigthByChangedQuantity(detail.weight!, detail.repeats!.toDouble(), lastExercise1RM!.quantity!);
|
||||
//weight = lastExercise1RM!.unitQuantity! * detail.repeats! / lastExercise1RM!.quantity!;
|
||||
weight = Common.roundWeight(weight);
|
||||
print("Recaluclated weight ${detail.weight} - repeat: ${detail.repeats}");
|
||||
//print("Recaluclated weight ${detail.weight} - repeat: ${detail.repeats}");
|
||||
|
||||
//detail.repeats = Common.calculateQuantityByChangedWeight(oneRepMax, weight, detail.repeats!.toDouble());
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user