1.1.26+3 development

This commit is contained in:
bossanyit
2022-06-04 08:28:06 +02:00
parent e59e225582
commit 82bed75528
4 changed files with 67 additions and 7 deletions
@@ -1,5 +1,6 @@
import 'dart:collection';
import 'package:aitrainer_app/model/exercise.dart';
import 'package:aitrainer_app/util/enums.dart';
import 'package:intl/intl.dart';
import 'dart:async';
import 'package:aitrainer_app/bloc/development_diagram/development_diagram_bloc.dart';
@@ -23,9 +24,11 @@ class BodyDevelopmentBloc extends Bloc<BodyDevelopmentEvent, BodyDevelopmentStat
List<String> legendsFmlm = ['First month', '1 month ago', 'last month'];
List<String> legendsL3m = ['2 months ago', '1 month ago', 'last month'];
List<String> legends = [];
List<String> dateGroups = ["", "", ""];
List<int> radarTicks = [];
List<String> radarFeatures = [];
List<List<int>> radarData = [];
List<List<double>> tempRadarData = [];
DiagramGroup group = DiagramGroup.sumMass;
DiagramDateFilterGroup filter = DiagramDateFilterGroup.l3t;
@@ -43,19 +46,71 @@ class BodyDevelopmentBloc extends Bloc<BodyDevelopmentEvent, BodyDevelopmentStat
Colors.orange,
];
void resetTempData() {
this.tempRadarData.clear();
this.tempRadarData = [
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0]
];
}
void getExerciseData() {
workoutTreeRepository.sortedTree.clear();
workoutTreeRepository.sortByMuscleType();
this.resetTempData();
int index = 0;
this.workoutTreeRepository.sortedTree.forEach((name, list) {
print("name: $name");
int elementIndex = 0;
list.forEach((element) {
exerciseRepository.exerciseList = exerciseRepository.getExercisesByExerciseTypeId(element.exerciseTypeId);
exerciseRepository.sortByDate();
int exerciseIndex = 0;
exerciseRepository.exerciseList!.forEach((exercise) {
final HashMap<String, dynamic> dateGroup = this.getDateGroup(exercise, elementIndex);
if (dateGroup['dateGroupIndex'] != -1) {
double unitQuantity = exercise.unitQuantity == null ? 1 : exercise.unitQuantity!;
//print("index ${dateGroup['dateGroupIndex']} -- dateGroup: ${dateGroup['dateGroup']} -- value ${exercise.quantity! * unitQuantity}");
tempRadarData[dateGroup['dateGroupIndex']][index] += (exercise.quantity! * unitQuantity) / (elementIndex + exerciseIndex + 1);
exerciseIndex++;
}
});
elementIndex++;
});
index++;
});
print(" temp $tempRadarData");
}
HashMap<String, dynamic> getDateGroup(Exercise exercise, int elementIndex) {
HashMap<String, dynamic> rc = HashMap();
rc['dateGroupIndex'] = -1;
if (elementIndex == 0) {
rc['dateGroupIndex'] = 0;
rc['dateGroup'] = DateFormat(DateFormat.YEAR_MONTH, AppLanguage().appLocal.toString()).format(exercise.dateAdd!);
dateGroups[0] = rc['dateGroup'];
dateGroups[1] =
DateFormat(DateFormat.YEAR_MONTH, AppLanguage().appLocal.toString()).format(DateTime.now().subtract(Duration(days: 32)));
dateGroups[2] = DateFormat(DateFormat.YEAR_MONTH, AppLanguage().appLocal.toString()).format(DateTime.now());
print("DateGroups: ==== $dateGroups");
} else {
final String dateGroup = DateFormat(DateFormat.YEAR_MONTH, AppLanguage().appLocal.toString()).format(exercise.dateAdd!);
if (dateGroup == dateGroups[0]) {
rc['dateGroup'] = dateGroup;
rc['dateGroupIndex'] = 0;
} else if (dateGroup == dateGroups[1]) {
rc['dateGroup'] = dateGroup;
rc['dateGroupIndex'] = 1;
} else if (dateGroup == dateGroups[2]) {
rc['dateGroup'] = dateGroup;
rc['dateGroupIndex'] = 2;
}
}
return rc;
}
Future<void> getData() async {