WT 1.26
This commit is contained in:
@@ -22,7 +22,8 @@ class CustomerRepository with Logging {
|
||||
Customer? customer;
|
||||
Customer? _trainee;
|
||||
List<Customer>? _trainees;
|
||||
List<CustomerProperty>? _allProperties;
|
||||
List<CustomerProperty>? _properties;
|
||||
List<CustomerProperty>? _allCustomerProperties;
|
||||
final PropertyRepository propertyRepository = PropertyRepository();
|
||||
final List<Property> womanSizes = [];
|
||||
final List<Property> manSizes = [];
|
||||
@@ -43,6 +44,8 @@ class CustomerRepository with Logging {
|
||||
if (Cache().userLoggedIn != null) {
|
||||
isMan = (Cache().userLoggedIn!.sex == "m");
|
||||
}
|
||||
|
||||
_allCustomerProperties = Cache().getCustomerPropertyAll();
|
||||
}
|
||||
|
||||
String? getGenderByName(String name) {
|
||||
@@ -164,7 +167,9 @@ class CustomerRepository with Logging {
|
||||
}
|
||||
|
||||
setCustomerProperty(String propertyName, double value, {id = 0}) {
|
||||
if (this.customer == null) throw Exception("Initialize the customer object");
|
||||
if (this.customer == null) {
|
||||
throw Exception("Initialize the customer object");
|
||||
}
|
||||
if (this.customer!.properties[propertyName] == null) {
|
||||
this.customer!.properties[propertyName] = CustomerProperty(
|
||||
propertyId: propertyRepository.getPropertyByName("Height")!.propertyId,
|
||||
@@ -179,6 +184,7 @@ class CustomerRepository with Logging {
|
||||
if (id > 0) {
|
||||
this.customer!.properties[propertyName]!.customerPropertyId = id;
|
||||
}
|
||||
Cache().addCustomerProperty(this.customer!.properties[propertyName]!);
|
||||
}
|
||||
|
||||
double getWeight() {
|
||||
@@ -277,7 +283,7 @@ class CustomerRepository with Logging {
|
||||
}
|
||||
|
||||
Future<void> savePropertyByName(String name) async {
|
||||
await Future.forEach(this._allProperties!, (element) async {
|
||||
await Future.forEach(this._properties!, (element) async {
|
||||
final CustomerProperty customerProperty = element as CustomerProperty;
|
||||
final Property? property = propertyRepository.getPropertyByName(name);
|
||||
if (property != null) {
|
||||
@@ -303,12 +309,12 @@ class CustomerRepository with Logging {
|
||||
Future<List<CustomerProperty>> getAllCustomerProperties() async {
|
||||
int customerId = Cache().userLoggedIn!.customerId!;
|
||||
final results = await CustomerApi().getAllProperties(customerId);
|
||||
this._allProperties = results;
|
||||
this._properties = results;
|
||||
return results;
|
||||
}
|
||||
|
||||
List<CustomerProperty>? getAllProperties() {
|
||||
return this._allProperties;
|
||||
return this._properties;
|
||||
}
|
||||
|
||||
List<Customer>? getTraineesList() {
|
||||
@@ -547,4 +553,21 @@ class CustomerRepository with Logging {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
List<CustomerProperty> getAllCustomerPropertyByName(String propertyName) {
|
||||
List<CustomerProperty> allProperties = [];
|
||||
|
||||
Property? property = propertyRepository.getPropertyByName(propertyName);
|
||||
print(property);
|
||||
if (property == null || Cache().getCustomerPropertyAll() == null) {
|
||||
return allProperties;
|
||||
}
|
||||
|
||||
Cache().getCustomerPropertyAll()!.forEach((element) {
|
||||
if (element.propertyId == property.propertyId) {
|
||||
allProperties.add(element);
|
||||
}
|
||||
});
|
||||
return allProperties;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import 'package:aitrainer_app/repository/training_plan_day_repository.dart';
|
||||
import 'package:aitrainer_app/util/app_language.dart';
|
||||
import 'package:aitrainer_app/util/common.dart';
|
||||
|
||||
class TrainingPlanRepository {
|
||||
class TrainingPlanRepository with Common {
|
||||
ExerciseTree? parentTree;
|
||||
List<TrainingPlan> getPlansByParent(String parent) {
|
||||
final List<TrainingPlan> resultList = [];
|
||||
@@ -165,7 +165,7 @@ class TrainingPlanRepository {
|
||||
|
||||
detail.state = ExercisePlanDetailState.start;
|
||||
if (detail.weight != null && detail.weight! > 0) {
|
||||
detail.baseOneRepMax = Common.calculate1RM(detail.weight!, detail.repeats!.toDouble());
|
||||
detail.baseOneRepMax = calculate1RM(detail.weight!, detail.repeats!.toDouble());
|
||||
}
|
||||
|
||||
// first repeat: 50% more
|
||||
@@ -173,7 +173,7 @@ class TrainingPlanRepository {
|
||||
CustomerTrainingPlanDetails firstDetail = CustomerTrainingPlanDetails();
|
||||
firstDetail.copy(detail);
|
||||
firstDetail.repeats = (detail.repeats! * 1.5).round();
|
||||
firstDetail.baseOneRepMax = Common.calculate1RM(firstDetail.weight!, firstDetail.repeats!.toDouble());
|
||||
firstDetail.baseOneRepMax = calculate1RM(firstDetail.weight!, firstDetail.repeats!.toDouble());
|
||||
firstDetail.set = 1;
|
||||
detail.set = detail.set! - 1;
|
||||
if (detail.set! > 0) {
|
||||
@@ -189,8 +189,7 @@ class TrainingPlanRepository {
|
||||
return list;
|
||||
}
|
||||
|
||||
CustomerTrainingPlanDetails isWeightCalculatedByExerciseType(
|
||||
int exerciseTypeId, CustomerTrainingPlanDetails detail, CustomerTrainingPlan plan) {
|
||||
CustomerTrainingPlanDetails isWeightCalculatedByExerciseType(int exerciseTypeId, CustomerTrainingPlanDetails detail, CustomerTrainingPlan plan) {
|
||||
CustomerTrainingPlanDetails calculated = detail;
|
||||
for (var element in plan.details) {
|
||||
if (element.exerciseTypeId == exerciseTypeId) {
|
||||
@@ -290,7 +289,7 @@ class TrainingPlanRepository {
|
||||
actual.dateAdd!.year == exercise.dateAdd!.year &&
|
||||
actual.dateAdd!.month == exercise.dateAdd!.month &&
|
||||
actual.dateAdd!.day == exercise.dateAdd!.day) {
|
||||
double oneRepMax = Common.calculate1RM(exercise.unitQuantity!, exercise.quantity!);
|
||||
double oneRepMax = calculate1RM(exercise.unitQuantity!, exercise.quantity!);
|
||||
if (max1RM < oneRepMax) {
|
||||
max1RM = oneRepMax;
|
||||
}
|
||||
@@ -350,16 +349,14 @@ class TrainingPlanRepository {
|
||||
}
|
||||
int originalRepeats = getOriginalRepeats(trainingPlanId, detail);
|
||||
|
||||
detail.weight =
|
||||
Common.calculateWeigthByChangedQuantity(detailWithData.weight!, detailWithData.repeats!.toDouble(), originalRepeats.toDouble());
|
||||
detail.weight = Common.calculateWeigthByChangedQuantity(detailWithData.weight!, detailWithData.repeats!.toDouble(), originalRepeats.toDouble());
|
||||
detail.weight = Common.roundWeight(detail.weight!);
|
||||
print("Recalculated weight: ${detail.weight}");
|
||||
detail.repeats = originalRepeats;
|
||||
return detail;
|
||||
}
|
||||
|
||||
CustomerTrainingPlanDetails recalculateDetail(
|
||||
int trainingPlanId, CustomerTrainingPlanDetails detail, CustomerTrainingPlanDetails nextDetail) {
|
||||
CustomerTrainingPlanDetails recalculateDetail(int trainingPlanId, CustomerTrainingPlanDetails detail, CustomerTrainingPlanDetails nextDetail) {
|
||||
CustomerTrainingPlanDetails recalculatedDetail = nextDetail;
|
||||
|
||||
// 1. get original repeats
|
||||
@@ -379,8 +376,7 @@ class TrainingPlanRepository {
|
||||
});
|
||||
|
||||
// 2 get recalculated repeats
|
||||
recalculatedDetail.weight =
|
||||
Common.calculateWeigthByChangedQuantity(detail.weight!, detail.repeats!.toDouble(), originalRepeats.toDouble());
|
||||
recalculatedDetail.weight = Common.calculateWeigthByChangedQuantity(detail.weight!, detail.repeats!.toDouble(), originalRepeats.toDouble());
|
||||
recalculatedDetail.weight = Common.roundWeight(recalculatedDetail.weight!);
|
||||
print("recalculated repeats for $originalRepeats: ${recalculatedDetail.weight}");
|
||||
//recalculatedDetail.repeats = originalRepeats;
|
||||
|
||||
Reference in New Issue
Block a user