WT 1.1.24+2 Weight calculation
This commit is contained in:
@@ -4,6 +4,7 @@ import 'package:aitrainer_app/model/cache.dart';
|
||||
import 'package:aitrainer_app/model/sport.dart';
|
||||
import 'package:aitrainer_app/repository/customer_repository.dart';
|
||||
import 'package:aitrainer_app/repository/mautic_repository.dart';
|
||||
import 'package:aitrainer_app/util/app_language.dart';
|
||||
import 'package:aitrainer_app/util/common.dart';
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
@@ -138,6 +139,10 @@ class CustomerChangeBloc extends Bloc<CustomerChangeEvent, CustomerChangeState>
|
||||
customerRepository.customer!.sportId = selectedSport!.sportId;
|
||||
}
|
||||
|
||||
if (customerRepository.customer!.lang == null) {
|
||||
customerRepository.customer!.lang = AppLanguage().appLocal.languageCode;
|
||||
}
|
||||
|
||||
await customerRepository.saveCustomer();
|
||||
MauticRepository mauticRepository = MauticRepository(customerRepository: customerRepository);
|
||||
await mauticRepository.sendMauticDataChange();
|
||||
|
||||
@@ -8,6 +8,7 @@ import 'package:aitrainer_app/repository/mautic_repository.dart';
|
||||
import 'package:aitrainer_app/repository/split_test_respository.dart';
|
||||
import 'package:aitrainer_app/repository/training_plan_repository.dart';
|
||||
import 'package:aitrainer_app/repository/user_repository.dart';
|
||||
import 'package:aitrainer_app/util/app_language.dart';
|
||||
import 'package:aitrainer_app/util/common.dart';
|
||||
import 'package:aitrainer_app/util/enums.dart';
|
||||
import 'package:aitrainer_app/util/track.dart';
|
||||
@@ -170,6 +171,7 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> with Trans {
|
||||
customerRepository!.customer!.dataPolicyAllowed = 1;
|
||||
customerRepository!.customer!.emailSubscription = 1;
|
||||
customerRepository!.customer!.syncedDate = DateTime.now();
|
||||
customerRepository!.customer!.lang = AppLanguage().appLocal.languageCode;
|
||||
customerRepository!.setCustomerProperty("Weight", tempCustomer.getProperty("Weight"));
|
||||
customerRepository!.setCustomerProperty("Height", tempCustomer.getProperty("Height"));
|
||||
await customerRepository!.saveCustomer();
|
||||
|
||||
@@ -43,6 +43,8 @@ class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> {
|
||||
bool celebrating = false;
|
||||
int activeDayIndex = 0;
|
||||
|
||||
double base1RM = 0;
|
||||
|
||||
CustomerTrainingPlan? getMyPlan() => this._myPlan;
|
||||
setMyPlan(CustomerTrainingPlan? myPlan) => this._myPlan = myPlan;
|
||||
|
||||
@@ -106,21 +108,13 @@ class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> {
|
||||
} else if (event is TrainingPlanWeightChangeRecalculate) {
|
||||
yield TrainingPlanExerciseLoading();
|
||||
|
||||
/* double weightFromPlan = trainingPlanRepository.getOriginalWeight(this.getMyPlan()!.trainingPlanId!, event.detail);
|
||||
print("Plan Wieght: $weightFromPlan");
|
||||
if (weightFromPlan != -1 || (weightFromPlan == -1 && event.detail.set! > 1)) {
|
||||
bool isTest = weightFromPlan != -1 || weightFromPlan != -2;
|
||||
if (!isTest || (isTest && event.detail.set! > 1)) {
|
||||
//&& event.detail.exercises.length > 0
|
||||
print("Base1RM ${event.detail.base1RM}");
|
||||
if (event.detail.base1RM > 0) {
|
||||
event.detail.repeats =
|
||||
Common.reCalculateRepeatsByChangedWeight(event.detail.weight!, event.detail.repeats!.toDouble(), event.weight);
|
||||
|
||||
if (event.detail.repeats! < 3) {
|
||||
event.detail.repeats = 4;
|
||||
}
|
||||
Common.calculateQuantityByChangedWeight(event.detail.base1RM, event.weight, event.detail.repeats!.toDouble());
|
||||
ExerciseSaveStream().repeats = event.detail.repeats!;
|
||||
ExerciseSaveStream().getStreamController().add(true);
|
||||
} */
|
||||
}
|
||||
event.detail.weight = event.weight;
|
||||
yield TrainingPlanExerciseReady();
|
||||
yield TrainingPlanReady();
|
||||
@@ -171,18 +165,22 @@ 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());
|
||||
} 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());
|
||||
} 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 &&
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -427,9 +425,7 @@ class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> {
|
||||
|
||||
String getSummary(TrainingPlanDetail detail) {
|
||||
String summary = "";
|
||||
String set = "1";
|
||||
|
||||
set = detail.set.toString() + "/ ";
|
||||
List<TrainingPlanDetail> details = getAllTrainingPlanDetailsSameExercise(detail);
|
||||
int index = 0;
|
||||
|
||||
@@ -622,7 +618,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;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ class Customer {
|
||||
DateTime? syncedDate;
|
||||
DateTime? trialDate;
|
||||
String? firebaseRegToken;
|
||||
String? lang;
|
||||
|
||||
LinkedHashMap<String, CustomerProperty> properties = LinkedHashMap();
|
||||
|
||||
@@ -70,6 +71,7 @@ class Customer {
|
||||
this.trainer = json['trainer'];
|
||||
this.firebaseUid = json['firebaseUid'];
|
||||
this.firebaseRegToken = json['firebaseRegToken'];
|
||||
this.lang = json['lang'];
|
||||
|
||||
this.dataPolicyAllowed = json['dataPolicyAllowed'];
|
||||
this.emailSubscription = json['emailSubscription'];
|
||||
@@ -103,6 +105,7 @@ class Customer {
|
||||
"syncedDate": this.syncedDate == null ? null : DateFormat('yyyy-MM-dd HH:mm:ss').format(this.syncedDate!),
|
||||
"trialDate": this.trialDate == null ? null : DateFormat('yyyy-MM-dd HH:mm:ss').format(this.trialDate!),
|
||||
"firebaseRegToken": this.firebaseRegToken,
|
||||
"lang": this.lang,
|
||||
};
|
||||
|
||||
@override
|
||||
|
||||
@@ -38,6 +38,8 @@ class CustomerTrainingPlanDetails {
|
||||
|
||||
bool isTest = false;
|
||||
|
||||
double base1RM = -1;
|
||||
|
||||
CustomerTrainingPlanDetails();
|
||||
|
||||
CustomerTrainingPlanDetails.fromJson(Map json) {
|
||||
@@ -89,6 +91,8 @@ class CustomerTrainingPlanDetails {
|
||||
this.isTest = json['isTest'] == "true" ? true : false;
|
||||
|
||||
this.exerciseType = Cache().getExerciseTypeById(exerciseTypeId!);
|
||||
|
||||
this.base1RM = json['base1RM'];
|
||||
}
|
||||
|
||||
ExerciseType? getExerciseType() => exerciseType;
|
||||
@@ -118,6 +122,7 @@ class CustomerTrainingPlanDetails {
|
||||
'state': this.state.toStr(),
|
||||
"isTest": this.isTest,
|
||||
"dayId": this.dayId,
|
||||
"base1RM": this.base1RM,
|
||||
};
|
||||
|
||||
//print("Detail toJson $jsonMap");
|
||||
|
||||
@@ -21,7 +21,7 @@ class Mautic {
|
||||
"goal": this.goal,
|
||||
"databaseId": this.databaseId,
|
||||
"subscriptionDate": this.subscriptionDate,
|
||||
"language": this.language
|
||||
"lang": this.language
|
||||
};
|
||||
|
||||
String toForm() {
|
||||
@@ -33,7 +33,7 @@ class Mautic {
|
||||
form += this.goal == null ? "" : "&mauticform[goal]=${this.goal}";
|
||||
form += this.subscriptionDate == null ? "" : "&mauticform[subscribed]=${this.subscriptionDate}";
|
||||
form += this.databaseId == null ? "" : "&mauticform[databaseid]=${this.databaseId}";
|
||||
form += this.language == null ? "" : "&mauticform[language]=${this.language}";
|
||||
form += this.language == null ? "" : "&mauticform[lang]=${this.language}";
|
||||
form += this.purchaseDate == null ? "" : "&mauticform[purchase_date]=${this.purchaseDate}";
|
||||
form += this.exerciseDate == null ? "" : "&mauticform[last_exercise]=${this.exerciseDate}";
|
||||
form += this.trialDate == null ? "" : "&mauticform[trialdate]=${this.trialDate}";
|
||||
|
||||
@@ -36,7 +36,7 @@ class TrainingPlanDetail {
|
||||
"parallel": this.parallel,
|
||||
"dayId": this.dayId,
|
||||
"day": this.day,
|
||||
"summary": this.summary
|
||||
"summary": this.summary,
|
||||
};
|
||||
|
||||
@override
|
||||
|
||||
@@ -43,6 +43,7 @@ class MauticRepository {
|
||||
}
|
||||
mautic.fitnessLevel = customerRepository.customer!.fitnessLevel == null ? "" : customerRepository.customer!.fitnessLevel!;
|
||||
mautic.goal = customerRepository.customer!.goal == null ? "" : customerRepository.customer!.goal!;
|
||||
mautic.language = AppLanguage().appLocal.languageCode;
|
||||
|
||||
await MauticApi().sendMauticForm(mautic);
|
||||
}
|
||||
|
||||
@@ -102,6 +102,9 @@ class TrainingPlanRepository {
|
||||
//print("Detail $detail exerciseType: ${detail.exerciseType}");
|
||||
|
||||
detail.state = ExercisePlanDetailState.start;
|
||||
if (detail.weight != null && detail.weight! > 0) {
|
||||
detail.base1RM = Common.calculate1RM(detail.weight!, detail.repeats!.toDouble());
|
||||
}
|
||||
plan.details.add(detail);
|
||||
});
|
||||
|
||||
|
||||
@@ -194,11 +194,8 @@ mixin Common {
|
||||
}
|
||||
|
||||
static int calculateQuantityByChangedWeight(double initialRM, double weight, double repeat) {
|
||||
final double rmWendler = weight * repeat * 0.0333 + weight;
|
||||
final double rmOconner = weight * (1 + repeat / 40);
|
||||
|
||||
final double repeatWendler = (rmWendler - weight) / 0.0333 / weight;
|
||||
final double repeatOconner = (rmOconner / weight - 1) * 40;
|
||||
final double repeatWendler = (initialRM - weight) / 0.0333 / weight;
|
||||
final double repeatOconner = (initialRM / weight - 1) * 40;
|
||||
final newRepeat = ((repeatOconner + repeatWendler) / 2).ceil();
|
||||
print("Initial 1RM: $initialRM Weight: $weight repeatWendler: $repeatWendler repeat Oconner: $repeatOconner. NEW REPEAT: $newRepeat");
|
||||
return newRepeat;
|
||||
|
||||
@@ -26,7 +26,6 @@ class Track with Logging {
|
||||
Smartlook.setGlobalEventProperty(event.toString(), eventValue, false);
|
||||
FlutterUxcam.logEventWithProperties(event.enumToString(), {"value": eventValue});
|
||||
model.Tracking tracking = model.Tracking();
|
||||
//analytics.logEvent(name: event.enumToString(), parameters: {"value": eventValue});
|
||||
tracking.customerId = Cache().userLoggedIn == null ? 0 : Cache().userLoggedIn!.customerId!;
|
||||
tracking.event = event.enumToString();
|
||||
if (eventValue.isNotEmpty) {
|
||||
|
||||
@@ -21,7 +21,7 @@ class _CustomerWelcomePageState extends State<CustomerWelcomePage> with Trans {
|
||||
setContext(context);
|
||||
return Scaffold(
|
||||
appBar: AppBarMin(
|
||||
back: true,
|
||||
back: false,
|
||||
),
|
||||
body: Container(
|
||||
decoration: BoxDecoration(
|
||||
|
||||
@@ -134,9 +134,6 @@ class _ExerciseNewPageState extends State<ExerciseNewPage> with Trans, Logging {
|
||||
child: ExerciseSave(
|
||||
exerciseName: exerciseBloc.exerciseRepository.exerciseType!.nameTranslation,
|
||||
exerciseDescription: exerciseBloc.exerciseRepository.exerciseType!.descriptionTranslation,
|
||||
exerciseTask: exerciseBloc.exerciseRepository.exerciseType!.unitQuantityUnit != null
|
||||
? t("Please take a relative bigger weight and repeat 12-20 times and do your best! MAXIMIZE it!")
|
||||
: t("Please repeat as much times as you can! MAXIMIZE it!"),
|
||||
unit: exerciseBloc.exerciseRepository.exerciseType!.unit,
|
||||
unitQuantityUnit: exerciseBloc.exerciseRepository.exerciseType!.unitQuantityUnit,
|
||||
hasUnitQuantity: exerciseBloc.exerciseRepository.exerciseType!.unitQuantityUnit != null,
|
||||
|
||||
@@ -54,10 +54,10 @@ class RegistrationPage extends StatelessWidget with Trans {
|
||||
title: t("Successful Registration"),
|
||||
descriptions: t("Based on your initial data, we will generate the personalized training plan for you."),
|
||||
text: "OK",
|
||||
onTap: () => {Navigator.of(context).pushNamed('customerWelcomePage')},
|
||||
onTap: () => {Navigator.of(context).popAndPushNamed('customerWelcomePage')},
|
||||
onCancel: () => {
|
||||
trainingPlanRepository.generateTrainingPlan(),
|
||||
Navigator.of(context).pushNamed("customerWelcomePage"),
|
||||
Navigator.of(context).popAndPushNamed("customerWelcomePage"),
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
@@ -96,9 +96,6 @@ class TestSetNew extends StatelessWidget with Trans {
|
||||
return ExerciseSave(
|
||||
exerciseName: bloc.exerciseType.nameTranslation,
|
||||
exerciseDescription: bloc.exerciseType.descriptionTranslation,
|
||||
exerciseTask: bloc.exerciseType.unitQuantityUnit != null
|
||||
? t("Please take a relative bigger weight and repeat 12-20 times and do your best! MAXIMIZE it!")
|
||||
: t("Please repeat as much times as you can! MAXIMIZE it!"),
|
||||
unit: bloc.exerciseType.unit,
|
||||
unitQuantityUnit: bloc.exerciseType.unitQuantityUnit,
|
||||
hasUnitQuantity: bloc.exerciseType.unitQuantityUnit != null,
|
||||
|
||||
@@ -308,7 +308,7 @@ class _ExerciseListState extends State<ExerciseList> with Trans {
|
||||
|
||||
void animate() {
|
||||
offset = widget.bloc.getOffset();
|
||||
print("Offset: $offset");
|
||||
//print("Offset: $offset");
|
||||
if (scrollController.hasClients) {
|
||||
scrollController.animateTo(offset, duration: Duration(milliseconds: 300), curve: Curves.easeIn);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ class TrainingPlanExercise extends StatelessWidget with Trans {
|
||||
final CustomerTrainingPlanDetails detail = args['customerTrainingPlanDetails'];
|
||||
// ignore: close_sinks
|
||||
final TrainingPlanBloc bloc = BlocProvider.of<TrainingPlanBloc>(context);
|
||||
|
||||
setContext(context);
|
||||
return Scaffold(
|
||||
appBar: AppBarNav(depth: 1),
|
||||
@@ -89,7 +90,6 @@ class TrainingPlanExercise extends StatelessWidget with Trans {
|
||||
return ExerciseSave(
|
||||
exerciseName: detail.exerciseType!.nameTranslation,
|
||||
exerciseDescription: detail.exerciseType!.descriptionTranslation,
|
||||
exerciseTask: getExerciseTask(detail),
|
||||
unit: detail.exerciseType!.unit,
|
||||
unitQuantityUnit: detail.exerciseType!.unitQuantityUnit,
|
||||
hasUnitQuantity: detail.exerciseType!.unitQuantityUnit != null,
|
||||
@@ -116,28 +116,6 @@ class TrainingPlanExercise extends StatelessWidget with Trans {
|
||||
}
|
||||
}
|
||||
|
||||
String getExerciseTask(CustomerTrainingPlanDetails detail) {
|
||||
String desc = "";
|
||||
if (detail.exerciseType!.unit == "second") {
|
||||
return desc;
|
||||
}
|
||||
if (detail.exerciseType!.unitQuantityUnit != null) {
|
||||
if (detail.weight == -1) {
|
||||
return "Please take a relative bigger weight and at least 12 times and do your best! MAXIMIZE it!";
|
||||
} else if (detail.repeats == -1) {
|
||||
return "Please repeat as much times as you can! MAXIMIZE it!";
|
||||
} else {
|
||||
return "Please try to execute this exercise with exact weight and repeats what is suggested";
|
||||
}
|
||||
} else {
|
||||
if (detail.repeats == -1) {
|
||||
return "Please repeat as much times as you can! MAXIMIZE it!";
|
||||
} else {
|
||||
return "Please try to execute this exercise with exact repeats what is suggested";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Widget getDropSet(TrainingPlanBloc bloc, CustomerTrainingPlanDetails detail) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
|
||||
@@ -138,7 +138,6 @@ class ExerciseSave extends StatefulWidget {
|
||||
final String unit;
|
||||
final String exerciseName;
|
||||
final String exerciseDescription;
|
||||
final String exerciseTask;
|
||||
final int exerciseTypeId;
|
||||
final double? weight;
|
||||
final int? repeats;
|
||||
@@ -159,7 +158,6 @@ class ExerciseSave extends StatefulWidget {
|
||||
required this.unit,
|
||||
required this.exerciseName,
|
||||
required this.exerciseDescription,
|
||||
required this.exerciseTask,
|
||||
required this.exerciseTypeId,
|
||||
this.weight,
|
||||
this.repeats,
|
||||
@@ -214,7 +212,7 @@ class _ExerciseSaveState extends State<ExerciseSave> with Trans {
|
||||
|
||||
SchedulerBinding.instance!.addPostFrameCallback((_) {
|
||||
subscription = stream.listen((event) {
|
||||
_controller1.text = ExerciseSaveStream().weight.toStringAsFixed(0);
|
||||
//_controller1.text = ExerciseSaveStream().weight.toStringAsFixed(0);
|
||||
_controller2.text = ExerciseSaveStream().repeats.toStringAsFixed(0);
|
||||
});
|
||||
print("ExerciseSave weight ${widget.weight}");
|
||||
|
||||
Reference in New Issue
Block a user