WT 1.1.0+39 evaluation, health data
This commit is contained in:
@@ -12,6 +12,7 @@ class ExerciseRepository {
|
||||
Customer customer;
|
||||
ExerciseType exerciseType;
|
||||
List<Exercise> exerciseList;
|
||||
List<Exercise> actualExerciseList = List();
|
||||
|
||||
double rmWendler = 0;
|
||||
double rmMcglothlin = 0;
|
||||
@@ -20,28 +21,35 @@ class ExerciseRepository {
|
||||
double rmOconner = 0;
|
||||
double rmWathen = 0;
|
||||
|
||||
DateTime start;
|
||||
DateTime end;
|
||||
|
||||
ExerciseRepository() {
|
||||
this.createNew();
|
||||
}
|
||||
|
||||
createNew() {
|
||||
this.exercise = Exercise();
|
||||
exercise.dateAdd = DateTime.now();
|
||||
}
|
||||
|
||||
setQuantity(double quantity) {
|
||||
if ( this.exercise == null ) {
|
||||
if (this.exercise == null) {
|
||||
this.createNew();
|
||||
}
|
||||
this.exercise.quantity = quantity;
|
||||
}
|
||||
|
||||
setUnitQuantity(double unitQuantity) {
|
||||
if ( this.exercise == null ) {
|
||||
if (this.exercise == null) {
|
||||
this.createNew();
|
||||
}
|
||||
|
||||
this.exercise.unitQuantity = unitQuantity;
|
||||
}
|
||||
|
||||
setUnit( String unit) {
|
||||
if ( this.exercise == null ) {
|
||||
setUnit(String unit) {
|
||||
if (this.exercise == null) {
|
||||
this.createNew();
|
||||
}
|
||||
|
||||
@@ -49,7 +57,7 @@ class ExerciseRepository {
|
||||
}
|
||||
|
||||
setDatetimeExercise(DateTime datetimeExercise) {
|
||||
if ( this.exercise == null ) {
|
||||
if (this.exercise == null) {
|
||||
this.createNew();
|
||||
}
|
||||
|
||||
@@ -66,11 +74,16 @@ class ExerciseRepository {
|
||||
final Exercise modelExercise = this.exercise;
|
||||
modelExercise.customerId = this.customer.customerId;
|
||||
modelExercise.exerciseTypeId = this.exerciseType.exerciseTypeId;
|
||||
if (exerciseType.unitQuantity != "1") {
|
||||
modelExercise.unitQuantity = null;
|
||||
}
|
||||
this.actualExerciseList.add(modelExercise);
|
||||
Exercise savedExercise = await ExerciseApi().addExercise(modelExercise);
|
||||
if ( customer.customerId == Cache().userLoggedIn.customerId) {
|
||||
Cache().addExercise(savedExercise);
|
||||
} else if ( Cache().getTrainee() != null && customer.customerId == Cache().getTrainee().customerId ) {
|
||||
Cache().addExerciseTrainee(savedExercise);
|
||||
|
||||
if (customer.customerId == Cache().userLoggedIn.customerId) {
|
||||
Cache().addExercise(savedExercise);
|
||||
} else if (Cache().getTrainee() != null && customer.customerId == Cache().getTrainee().customerId) {
|
||||
Cache().addExerciseTrainee(savedExercise);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,21 +91,17 @@ class ExerciseRepository {
|
||||
await ExerciseApi().deleteExercise(exercise);
|
||||
}
|
||||
|
||||
|
||||
setCustomer(Customer customer) => this.customer = customer;
|
||||
|
||||
setExerciseType( ExerciseType exerciseType) => this.exerciseType = exerciseType;
|
||||
setExerciseType(ExerciseType exerciseType) => this.exerciseType = exerciseType;
|
||||
|
||||
|
||||
Future<List<Exercise>> getExercisesByCustomer( int customerId ) async {
|
||||
final results = await ExerciseApi().getExercisesByCustomer(customerId);
|
||||
Future<List<Exercise>> getExercisesByCustomer(int customerId) async {
|
||||
final results = await ExerciseApi().getExercisesByCustomer(customerId);
|
||||
this.exerciseList = results;
|
||||
if ( Cache().userLoggedIn != null ) {
|
||||
if (Cache().userLoggedIn != null) {
|
||||
if (customerId == Cache().userLoggedIn.customerId) {
|
||||
Cache().setExercises(exerciseList);
|
||||
} else if (Cache().getTrainee() != null && customerId == Cache()
|
||||
.getTrainee()
|
||||
.customerId) {
|
||||
} else if (Cache().getTrainee() != null && customerId == Cache().getTrainee().customerId) {
|
||||
Cache().setExercisesTrainee(exerciseList);
|
||||
}
|
||||
}
|
||||
@@ -110,11 +119,11 @@ class ExerciseRepository {
|
||||
}
|
||||
|
||||
String nextMissingBaseExercise(SplayTreeMap sortedTree) {
|
||||
if ( exerciseList == null ) {
|
||||
if (exerciseList == null) {
|
||||
exerciseList = Cache().getExercises();
|
||||
}
|
||||
|
||||
if ( exerciseList == null ) {
|
||||
if (exerciseList == null) {
|
||||
return "";
|
||||
}
|
||||
String missingTreeName;
|
||||
@@ -127,12 +136,12 @@ class ExerciseRepository {
|
||||
treeName = treeName.substring(3);
|
||||
foundTreeName = null;
|
||||
listByMuscle.forEach((exercise) {
|
||||
if ( missingTreeName == null ) {
|
||||
if (missingTreeName == null) {
|
||||
missingTreeName = treeName;
|
||||
}
|
||||
if ( exercise.base ) {
|
||||
exerciseList.forEach((element) {
|
||||
if ( element.exerciseTypeId == exercise.exerciseTypeId ) {
|
||||
if (exercise.base) {
|
||||
exerciseList.forEach((element) {
|
||||
if (element.exerciseTypeId == exercise.exerciseTypeId) {
|
||||
foundTreeName = treeName;
|
||||
//print("Found " + foundTreeName + " Missing actual: " + missingTreeName);
|
||||
isBreak = true;
|
||||
@@ -140,7 +149,7 @@ class ExerciseRepository {
|
||||
});
|
||||
}
|
||||
});
|
||||
if ( foundTreeName == null &&! isBreak ) {
|
||||
if (foundTreeName == null && !isBreak) {
|
||||
missingTreeName = treeName;
|
||||
isBreak = true;
|
||||
}
|
||||
@@ -156,40 +165,38 @@ class ExerciseRepository {
|
||||
int count1RMExercises = 0;
|
||||
LinkedHashMap<String, WorkoutMenuTree> tree = Cache().getWorkoutMenuTree();
|
||||
|
||||
if ( tree == null ) {
|
||||
if (tree == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
tree.forEach((key, value) {
|
||||
WorkoutMenuTree treeItem = value;
|
||||
if (treeItem.exerciseType != null &&
|
||||
treeItem.exerciseType.base == true &&
|
||||
!baseTreeItem.contains(treeItem.parent)) {
|
||||
if (treeItem.exerciseType != null && treeItem.exerciseType.base == true && !baseTreeItem.contains(treeItem.parent)) {
|
||||
baseTreeItem.add(treeItem.parent);
|
||||
}
|
||||
});
|
||||
|
||||
if ( exerciseList == null ) {
|
||||
if (exerciseList == null) {
|
||||
exerciseList = Cache().getExercises();
|
||||
}
|
||||
|
||||
if ( exerciseList == null ) {
|
||||
if (exerciseList == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
exerciseList.forEach((element) {
|
||||
Exercise exercise = element;
|
||||
if ( !checkedExerciseTypeId.contains(exercise.exerciseTypeId )) {
|
||||
if (!checkedExerciseTypeId.contains(exercise.exerciseTypeId)) {
|
||||
checkedExerciseTypeId.add(exercise.exerciseTypeId);
|
||||
tree.forEach((key, value) {
|
||||
WorkoutMenuTree treeItem = value;
|
||||
if (treeItem.exerciseType != null
|
||||
&& treeItem.exerciseType.base == true
|
||||
&& exercise.exerciseTypeId == treeItem.exerciseType.exerciseTypeId
|
||||
&& !checkedBaseTreeItem.contains(treeItem.parent)) {
|
||||
//print ("id: " + exercise.exerciseTypeId.toString());
|
||||
checkedBaseTreeItem.add(treeItem.parent);
|
||||
count1RMExercises++;
|
||||
if (treeItem.exerciseType != null &&
|
||||
treeItem.exerciseType.base == true &&
|
||||
exercise.exerciseTypeId == treeItem.exerciseType.exerciseTypeId &&
|
||||
!checkedBaseTreeItem.contains(treeItem.parent)) {
|
||||
//print ("id: " + exercise.exerciseTypeId.toString());
|
||||
checkedBaseTreeItem.add(treeItem.parent);
|
||||
count1RMExercises++;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -207,7 +214,7 @@ class ExerciseRepository {
|
||||
Exercise lastExercise = exercises[0];
|
||||
exercises.forEach((element) {
|
||||
Exercise actualExercise = element;
|
||||
if ( actualExercise.dateAdd.compareTo(lastExercise.dateAdd) > 0 ) {
|
||||
if (actualExercise.dateAdd.compareTo(lastExercise.dateAdd) > 0) {
|
||||
lastExercise = actualExercise;
|
||||
}
|
||||
});
|
||||
@@ -221,16 +228,15 @@ class ExerciseRepository {
|
||||
ExerciseType actualExerciseType;
|
||||
Cache().getExerciseTypes().forEach((element) {
|
||||
ExerciseType exerciseType = element;
|
||||
if ( exerciseType.exerciseTypeId == exerciseTypeId) {
|
||||
if (exerciseType.exerciseTypeId == exerciseTypeId) {
|
||||
actualExerciseType = exerciseType;
|
||||
}
|
||||
});
|
||||
if ( actualExerciseType == null ) {
|
||||
throw Exception("Data error, no ExerciseType for exerciseTypeId $exerciseTypeId" );
|
||||
if (actualExerciseType == null) {
|
||||
throw Exception("Data error, no ExerciseType for exerciseTypeId $exerciseTypeId");
|
||||
}
|
||||
return actualExerciseType;
|
||||
}
|
||||
|
||||
void sortByDate() => exerciseList.sort( (a, b) => b.dateAdd.compareTo(a.dateAdd) );
|
||||
|
||||
}
|
||||
void sortByDate() => exerciseList.sort((a, b) => b.dateAdd.compareTo(a.dateAdd));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import 'package:aitrainer_app/model/result.dart';
|
||||
|
||||
enum ResultType { running, man, woman, none }
|
||||
|
||||
extension ResultTypeExt on ResultType {
|
||||
bool equals(ResultType type) => this.toString() == type.toString();
|
||||
}
|
||||
|
||||
class ExerciseResultRepository {
|
||||
final List<ResultExt> _results = List();
|
||||
ResultType resultType;
|
||||
|
||||
ExerciseResultRepository({this.resultType}) {
|
||||
if (resultType == null) {
|
||||
resultType = ResultType.man;
|
||||
}
|
||||
if (resultType.equals(ResultType.man) || resultType.equals(ResultType.woman)) {
|
||||
//_results.add(ResultExt(itemString: ResultItem.time.description));
|
||||
_results.add(ResultExt(itemString: ResultItem.reps_volume.description));
|
||||
_results.add(ResultExt(itemString: ResultItem.weight_volume.description));
|
||||
_results.add(ResultExt(itemString: ResultItem.bpm_max.description));
|
||||
_results.add(ResultExt(itemString: ResultItem.calorie.description));
|
||||
_results.add(ResultExt(itemString: ResultItem.bpm_avg.description));
|
||||
_results.add(ResultExt(itemString: ResultItem.fatburn_percent.description));
|
||||
_results.add(ResultExt(itemString: ResultItem.bpm_min.description));
|
||||
} else {
|
||||
//_results.add(ResultExt(itemString: ResultItem.time.description));
|
||||
_results.add(ResultExt(itemString: ResultItem.distance.description));
|
||||
_results.add(ResultExt(itemString: ResultItem.bpm_max.description));
|
||||
_results.add(ResultExt(itemString: ResultItem.calorie.description));
|
||||
_results.add(ResultExt(itemString: ResultItem.bpm_avg.description));
|
||||
_results.add(ResultExt(itemString: ResultItem.fatburn_percent.description));
|
||||
_results.add(ResultExt(itemString: ResultItem.bpm_min.description));
|
||||
_results.add(ResultExt(itemString: ResultItem.steps.description));
|
||||
_results.add(ResultExt(itemString: ResultItem.speed_max.description));
|
||||
}
|
||||
}
|
||||
|
||||
List<ResultExt> getResults() => this._results;
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'dart:collection';
|
||||
import 'package:aitrainer_app/localization/app_language.dart';
|
||||
import 'package:aitrainer_app/model/cache.dart';
|
||||
import 'package:aitrainer_app/model/exercise_ability.dart';
|
||||
import 'package:aitrainer_app/model/exercise_tree.dart';
|
||||
import 'package:aitrainer_app/model/exercise_type.dart';
|
||||
import 'package:aitrainer_app/model/workout_menu_tree.dart';
|
||||
@@ -32,6 +33,7 @@ class WorkoutTreeRepository {
|
||||
final LinkedHashMap tree = LinkedHashMap<String, WorkoutMenuTree>();
|
||||
SplayTreeMap sortedTree = SplayTreeMap<String, List<WorkoutMenuTree>>();
|
||||
bool isEnglish;
|
||||
WorkoutType workoutType;
|
||||
|
||||
final Map<String, int> _antagonist = {
|
||||
Antagonist.chest: Antagonist.chestNr,
|
||||
@@ -59,60 +61,71 @@ class WorkoutTreeRepository {
|
||||
}
|
||||
|
||||
exerciseTree.forEach((treeItem) async {
|
||||
//print(" -- TreeItem " + treeItem.toJson().toString());
|
||||
//print(" -- TreeItem " + treeItem.toJson().toString() + " active " + treeItem.active.toString());
|
||||
if (treeItem.active == true) {
|
||||
String treeName = isEnglish ? treeItem.name : treeItem.nameTranslation;
|
||||
String assetImage = 'asset/menu/' + treeItem.imageUrl.substring(7);
|
||||
|
||||
String treeName = isEnglish ? treeItem.name : treeItem.nameTranslation;
|
||||
String assetImage = 'asset/menu/' + treeItem.imageUrl.substring(7);
|
||||
bool is1RM = treeItem.name == 'One Rep Max' ? true : false;
|
||||
if (is1RM == false && treeItem.parentId != 0) {
|
||||
is1RM = isParent1RM(treeItem.parentId);
|
||||
}
|
||||
|
||||
bool is1RM = treeItem.name == 'One Rep Max' ? true : false;
|
||||
if (is1RM == false && treeItem.parentId != 0) {
|
||||
is1RM = isParent1RM(treeItem.parentId);
|
||||
bool isEndurance = treeItem.name == 'Endurance' ? true : false;
|
||||
if (isEndurance == false && treeItem.parentId != 0) {
|
||||
isEndurance = isParentEndurance(treeItem.parentId);
|
||||
}
|
||||
|
||||
bool isRunning = treeItem.name == "Cardio" ? true : false;
|
||||
if (isRunning == false && treeItem.parentId != 0) {
|
||||
isRunning = isParentRunning(treeItem.parentId);
|
||||
}
|
||||
|
||||
WorkoutMenuTree menuItem = WorkoutMenuTree(
|
||||
treeItem.treeId,
|
||||
treeItem.parentId,
|
||||
treeName,
|
||||
assetImage,
|
||||
Colors.white,
|
||||
30,
|
||||
false,
|
||||
0,
|
||||
null,
|
||||
false,
|
||||
is1RM,
|
||||
isEndurance,
|
||||
isRunning,
|
||||
treeItem.name,
|
||||
);
|
||||
menuItem = this.setWorkoutTypes(menuItem, treeItem);
|
||||
this.tree[treeItem.name + "_" + treeItem.parentId.toString()] = menuItem;
|
||||
//print("WorkoutMenuTree item " + menuItem.toJson().toString());
|
||||
}
|
||||
|
||||
bool isEndurance = treeItem.name == 'Endurance' ? true : false;
|
||||
if (isEndurance == false && treeItem.parentId != 0) {
|
||||
isEndurance = isParentEndurance(treeItem.parentId);
|
||||
}
|
||||
|
||||
final WorkoutMenuTree menuItem = WorkoutMenuTree(
|
||||
treeItem.treeId,
|
||||
treeItem.parentId,
|
||||
treeName,
|
||||
assetImage,
|
||||
Colors.white,
|
||||
30,
|
||||
false,
|
||||
0,
|
||||
null,
|
||||
false,
|
||||
is1RM,
|
||||
isEndurance,
|
||||
treeItem.name,
|
||||
);
|
||||
this.tree[treeItem.name + "_" + treeItem.parentId.toString()] = menuItem;
|
||||
//print("WorkoutMenuTree item " + menuItem.toJson().toString());
|
||||
});
|
||||
|
||||
exerciseTypes.forEach((exerciseType) {
|
||||
if (!(exerciseType.imageUrl.isEmpty || exerciseType.name.isEmpty || exerciseType.nameTranslation.isEmpty)) {
|
||||
if (!(exerciseType.imageUrl.isEmpty || exerciseType.name.isEmpty || exerciseType.nameTranslation.isEmpty) &&
|
||||
exerciseType.active == true) {
|
||||
String exerciseTypeName = isEnglish ? exerciseType.name : exerciseType.nameTranslation;
|
||||
String assetImage = 'asset/menu/' + exerciseType.imageUrl.substring(7);
|
||||
if (exerciseType.parents.isNotEmpty) {
|
||||
exerciseType.parents.forEach((parentId) {
|
||||
bool is1RM = this.isParent1RM(parentId);
|
||||
bool isEndurance = this.isParentEndurance(parentId);
|
||||
exerciseType.is1RM = is1RM;
|
||||
exerciseType.isEndurance = isEndurance;
|
||||
if (is1RM) exerciseType.setAbility(ExerciseAbility.oneRepMax);
|
||||
if (isEndurance) exerciseType.setAbility(ExerciseAbility.endurance);
|
||||
bool isRunning = this.isParentRunning(parentId);
|
||||
if (isRunning) exerciseType.setAbility(ExerciseAbility.running);
|
||||
WorkoutMenuTree menuItem = WorkoutMenuTree(exerciseType.exerciseTypeId, parentId, exerciseTypeName, assetImage, Colors.white,
|
||||
24, true, exerciseType.exerciseTypeId, exerciseType, exerciseType.base, is1RM, isEndurance, exerciseType.name);
|
||||
24, true, exerciseType.exerciseTypeId, exerciseType, exerciseType.base, is1RM, isEndurance, isRunning, exerciseType.name);
|
||||
this.tree[exerciseType.name] = menuItem;
|
||||
//print("WorkoutMenuTree item " + menuItem.toJson().toString());
|
||||
/*print("ExerciseType in Menu item " +
|
||||
print("WorkoutMenuTree item " + menuItem.toJson().toString());
|
||||
print("ExerciseType in Menu item " +
|
||||
exerciseType.toJson().toString() +
|
||||
" is1RM: " +
|
||||
is1RM.toString() +
|
||||
" isEndurance: " +
|
||||
isEndurance.toString());*/
|
||||
isEndurance.toString());
|
||||
});
|
||||
} else {
|
||||
//print("No Parents " + exerciseType.toJson().toString());
|
||||
@@ -127,6 +140,39 @@ class WorkoutTreeRepository {
|
||||
exerciseRepository.getBaseExerciseFinishedPercent();
|
||||
}
|
||||
|
||||
WorkoutMenuTree setWorkoutTypes(WorkoutMenuTree menu, ExerciseTree treeItem) {
|
||||
WorkoutType.values.forEach((workoutType) {
|
||||
if (workoutType.equalsString(treeItem.name) || existWorkoutTypeInTree(workoutType)) {
|
||||
menu.workoutTypes.add(workoutType);
|
||||
}
|
||||
});
|
||||
return menu;
|
||||
}
|
||||
|
||||
bool existWorkoutTypeInTree(WorkoutType workoutType) {
|
||||
bool exists = false;
|
||||
this.tree.forEach((key, treeItem) {
|
||||
if (workoutType.equalsString(treeItem.name)) {
|
||||
exists = true;
|
||||
}
|
||||
});
|
||||
return exists;
|
||||
}
|
||||
|
||||
bool isParentRunning(int treeId) {
|
||||
bool isTreeItemRunning = false;
|
||||
|
||||
this.tree.forEach((key, value) {
|
||||
WorkoutMenuTree treeItem = value as WorkoutMenuTree;
|
||||
if (treeItem.id == treeId) {
|
||||
isTreeItemRunning = isTreeItemRunning || treeItem.isRunning;
|
||||
//print (treeItem.name + " 1RM " + treeItem.is1RM.toString() );
|
||||
}
|
||||
});
|
||||
|
||||
return isTreeItemRunning;
|
||||
}
|
||||
|
||||
bool isParent1RM(int treeId) {
|
||||
bool isTreeItem1RM = false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user