WT 1.26
This commit is contained in:
@@ -119,15 +119,9 @@ class CustomerChangeBloc extends Bloc<CustomerChangeEvent, CustomerChangeState>
|
||||
yield CustomerSaveSuccess();
|
||||
} else if (event is CustomerSaveWeight) {
|
||||
yield CustomerChangeLoading();
|
||||
if (customerRepository.customer!.getProperty("Weight") == null) {
|
||||
throw Exception("Please select your weight");
|
||||
}
|
||||
yield CustomerSaveSuccess();
|
||||
} else if (event is CustomerSaveHeight) {
|
||||
yield CustomerChangeLoading();
|
||||
if (customerRepository.customer!.getProperty("Height") == null) {
|
||||
throw Exception("Please select your height");
|
||||
}
|
||||
yield CustomerSaveSuccess();
|
||||
} else if (event is CustomerSave) {
|
||||
yield CustomerSaving();
|
||||
|
||||
@@ -1,28 +1,142 @@
|
||||
import 'package:intl/intl.dart';
|
||||
import 'dart:async';
|
||||
import 'dart:collection';
|
||||
|
||||
import 'package:aitrainer_app/model/cache.dart';
|
||||
import 'package:aitrainer_app/util/app_language.dart';
|
||||
import 'package:aitrainer_app/model/exercise.dart';
|
||||
import 'package:aitrainer_app/model/workout_menu_tree.dart';
|
||||
import 'package:aitrainer_app/repository/exercise_repository.dart';
|
||||
import 'package:aitrainer_app/repository/workout_tree_repository.dart';
|
||||
import 'package:aitrainer_app/service/logging.dart';
|
||||
import 'package:aitrainer_app/util/calculate.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/group_data.dart';
|
||||
import 'package:aitrainer_app/util/diagram_data.dart';
|
||||
import 'package:aitrainer_app/util/track.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fl_chart/fl_chart.dart';
|
||||
|
||||
part 'development_by_muscle_event.dart';
|
||||
|
||||
part 'development_by_muscle_state.dart';
|
||||
|
||||
enum DiagramType { sumMass, oneRepMax, percent }
|
||||
enum DiagramDateType { daily, weekly, monthly, yearly }
|
||||
|
||||
class GroupDate extends GroupData with Common {
|
||||
final List<Exercise> inputList;
|
||||
final List<DiagramData> outputList;
|
||||
|
||||
String? _origDatePart;
|
||||
late int _origExerciseTypeId;
|
||||
late Exercise _origExercise;
|
||||
|
||||
late double _sumQuantity;
|
||||
late double _maxQuantity;
|
||||
late int _countExercises;
|
||||
|
||||
late DiagramType diagramType;
|
||||
late DiagramDateType dateRate;
|
||||
|
||||
GroupDate({required this.inputList, required this.outputList});
|
||||
|
||||
double getQuantityByDate(Exercise exercise) {
|
||||
double sum = 0;
|
||||
if (this.diagramType == DiagramType.sumMass) {
|
||||
if (exercise.unitQuantity != null) {
|
||||
sum = exercise.quantity! * exercise.unitQuantity!;
|
||||
} else {
|
||||
sum = exercise.quantity!;
|
||||
}
|
||||
} else if (this.diagramType == DiagramType.oneRepMax || this.diagramType == DiagramType.percent) {
|
||||
if (exercise.unitQuantity != null) {
|
||||
sum = calculate1RM(exercise.quantity!, exercise.unitQuantity!);
|
||||
} else {
|
||||
sum = exercise.quantity!;
|
||||
}
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
@override
|
||||
void addTempData(Exercise exercise) {
|
||||
double newQuantity = getQuantityByDate(exercise);
|
||||
_sumQuantity = _sumQuantity + newQuantity;
|
||||
if (_maxQuantity < newQuantity) {
|
||||
_maxQuantity = newQuantity;
|
||||
}
|
||||
_countExercises = _countExercises + 1;
|
||||
_origDatePart = getDatePart(exercise.dateAdd!, dateRate);
|
||||
_origExerciseTypeId = exercise.exerciseTypeId!;
|
||||
_origExercise = exercise;
|
||||
}
|
||||
|
||||
@override
|
||||
bool checkNewType(Exercise exercise) {
|
||||
String exerciseDatePart = getDatePart(exercise.dateAdd!, dateRate);
|
||||
return _origDatePart == null || _origDatePart != exerciseDatePart || _origExerciseTypeId != exercise.exerciseTypeId;
|
||||
}
|
||||
|
||||
String getDatePart(DateTime date, DiagramDateType dateRate) {
|
||||
String datePart = DateFormat('MM.dd', AppLanguage().appLocal.toString()).format(date);
|
||||
if (dateRate == DiagramDateType.weekly) {
|
||||
datePart = weekNumber(date).toString();
|
||||
} else if (dateRate == DiagramDateType.monthly) {
|
||||
datePart = DateFormat('MMM', AppLanguage().appLocal.toString()).format(date);
|
||||
} else if (dateRate == DiagramDateType.yearly) {
|
||||
datePart = DateFormat('y', AppLanguage().appLocal.toString()).format(date);
|
||||
} else if (dateRate == DiagramDateType.daily) {
|
||||
datePart = DateFormat('MM.dd', AppLanguage().appLocal.toString()).format(date);
|
||||
}
|
||||
return datePart;
|
||||
}
|
||||
|
||||
@override
|
||||
void iteration() {
|
||||
this.resetTemp();
|
||||
Exercise? tempExercise;
|
||||
inputList.forEach((element) {
|
||||
tempExercise = element;
|
||||
if (this.checkNewType(element)) {
|
||||
if (_origDatePart == null) {
|
||||
this.addTempData(element);
|
||||
} else {
|
||||
this.temp2Output(_origExercise);
|
||||
this.resetTemp();
|
||||
this.addTempData(element);
|
||||
}
|
||||
} else {
|
||||
this.addTempData(element);
|
||||
}
|
||||
});
|
||||
if (tempExercise != null) {
|
||||
this.temp2Output(tempExercise!);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void temp2Output(Exercise exercise) {
|
||||
if (exercise.unitQuantity == null) {
|
||||
return;
|
||||
}
|
||||
Exercise newExercise = exercise.copy();
|
||||
newExercise.datePart = _origDatePart;
|
||||
if (this.diagramType == DiagramType.oneRepMax || this.diagramType == DiagramType.percent) {
|
||||
newExercise.calculated = _maxQuantity;
|
||||
} else {
|
||||
newExercise.calculated = _sumQuantity / _countExercises;
|
||||
}
|
||||
DiagramData data = DiagramData(newExercise.datePart!, newExercise.calculated);
|
||||
outputList.add(data);
|
||||
}
|
||||
|
||||
@override
|
||||
void resetTemp() {
|
||||
_countExercises = 0;
|
||||
_sumQuantity = 0;
|
||||
_maxQuantity = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
class DiagramType {
|
||||
static String sumMass = "sumMass";
|
||||
static String oneRepMax = "oneRepMax";
|
||||
@@ -33,7 +147,7 @@ class DiagramType {
|
||||
=========== GROUPDATE CLASS
|
||||
*/
|
||||
|
||||
class GroupDate extends GroupData with Calculate, Common {
|
||||
class GroupDate extends GroupData with Common {
|
||||
final List<Exercise> inputList;
|
||||
final List<Exercise> outputList;
|
||||
|
||||
@@ -136,7 +250,7 @@ class GroupDate extends GroupData with Calculate, Common {
|
||||
/*
|
||||
=========== CHART DATA CLASS
|
||||
*/
|
||||
class GroupChart extends GroupData with Calculate {
|
||||
class GroupChart extends GroupData with Common {
|
||||
final List<dynamic> inputList;
|
||||
LinkedHashMap<int, ChartDataExtended> outputList = LinkedHashMap();
|
||||
|
||||
@@ -186,9 +300,8 @@ class GroupChart extends GroupData with Calculate {
|
||||
_minData = diagramValue;
|
||||
}
|
||||
|
||||
BarChartGroupData data = BarChartGroupData(x: exercise.dateAdd!.millisecondsSinceEpoch, barRods: [
|
||||
BarChartRodData(y: diagramValue, width: 12, colors: [Colors.lightBlue, Colors.lightBlueAccent])
|
||||
]);
|
||||
BarChartGroupData data = BarChartGroupData(
|
||||
x: exercise.dateAdd!.millisecondsSinceEpoch, barRods: [BarChartRodData(toY: diagramValue, width: 12, color: Colors.lightBlue)]);
|
||||
_chartData.add(data);
|
||||
_origExerciseTypeId = exercise.exerciseTypeId!;
|
||||
}
|
||||
@@ -262,7 +375,7 @@ class ChartDataExtended {
|
||||
element.barRods.forEach((rods) {
|
||||
var barChartData = {
|
||||
'x': element.x,
|
||||
'y': rods.y,
|
||||
'y': rods.toY,
|
||||
};
|
||||
listBarChartData.add(barChartData);
|
||||
});
|
||||
@@ -274,20 +387,20 @@ class ChartDataExtended {
|
||||
};
|
||||
return chartData;
|
||||
}
|
||||
}
|
||||
} */
|
||||
|
||||
class DevelopmentByMuscleBloc extends Bloc<DevelopmentByMuscleEvent, DevelopmentByMuscleState> with Calculate, Logging {
|
||||
class DevelopmentByMuscleBloc extends Bloc<DevelopmentByMuscleEvent, DevelopmentByMuscleState> with Common, Logging {
|
||||
final WorkoutTreeRepository workoutTreeRepository;
|
||||
|
||||
final ExerciseRepository exerciseRepository = ExerciseRepository();
|
||||
LinkedHashMap<int, ChartDataExtended> listChartData = LinkedHashMap();
|
||||
late List<BarChartGroupData> chartData;
|
||||
String diagramType = DiagramType.sumMass;
|
||||
String dateRate = DateRate.daily;
|
||||
double basePercent = 0;
|
||||
final List<DiagramData> diagramData = [];
|
||||
int actualExerciseType = 0;
|
||||
DiagramType diagramType = DiagramType.sumMass;
|
||||
DiagramDateType diagramDateType = DiagramDateType.monthly;
|
||||
|
||||
@override
|
||||
DevelopmentByMuscleBloc({required this.workoutTreeRepository}) : super(DevelopmentByMuscleStateInitial());
|
||||
DevelopmentByMuscleBloc({required this.workoutTreeRepository}) : super(DevelopmentByMuscleStateInitial()) {
|
||||
on<DevelopmentByMuscleLoad>(_onLoad);
|
||||
}
|
||||
|
||||
Future<void> getData() async {
|
||||
workoutTreeRepository.sortedTree.clear();
|
||||
@@ -299,93 +412,13 @@ class DevelopmentByMuscleBloc extends Bloc<DevelopmentByMuscleEvent, Development
|
||||
workoutTree.selected = false;
|
||||
});
|
||||
});
|
||||
|
||||
this.getChartData();
|
||||
}
|
||||
|
||||
void getChartData() {
|
||||
List<Exercise>? exercises = exerciseRepository.getExerciseList();
|
||||
|
||||
//print("-- Start calculate --- ");
|
||||
exercises = this.groupByDate(exercises);
|
||||
|
||||
exercises = sort(exercises, true);
|
||||
/* exercises.forEach((exercise) {
|
||||
print ("Chart exercise " + exercise.toJsonDatePart().toString());
|
||||
});*/
|
||||
|
||||
listChartData = LinkedHashMap();
|
||||
GroupChart groupChart = GroupChart(inputList: exercises, outputList: listChartData);
|
||||
groupChart.diagramType = this.diagramType;
|
||||
groupChart.iteration();
|
||||
listChartData = groupChart.outputList;
|
||||
|
||||
listChartData.forEach((key, value) {
|
||||
//trace("typeid " + key.toString() + " chardata " + value.toJson().toString());
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
List<Exercise> groupByDate(List<Exercise>? exercises) {
|
||||
List<Exercise> groupedExercises = [];
|
||||
if (exercises != null) {
|
||||
exercises = sort(exercises, false);
|
||||
exercises.forEach((exercise) {
|
||||
//trace("Date exercise " + exercise.toJsonDatePart().toString());
|
||||
});
|
||||
|
||||
GroupDate groupDate = GroupDate(inputList: exercises, outputList: groupedExercises);
|
||||
groupDate.dateRate = this.dateRate;
|
||||
groupDate.diagramType = this.diagramType;
|
||||
groupDate.iteration();
|
||||
groupedExercises = groupDate.outputList;
|
||||
}
|
||||
|
||||
/* groupedExercises.forEach((element) {
|
||||
print("Grouped " + element.toJsonDatePart().toString());
|
||||
});*/
|
||||
|
||||
return groupedExercises;
|
||||
}
|
||||
|
||||
List<Exercise> sort(List<Exercise> exercises, bool asc) {
|
||||
exercises.sort((a, b) {
|
||||
var aDateId = a.exerciseTypeId.toString() + "_" + a.datePart.toString();
|
||||
var bDateId = b.exerciseTypeId.toString() + "_" + b.datePart.toString();
|
||||
|
||||
return asc ? aDateId.compareTo(bDateId) : bDateId.compareTo(aDateId);
|
||||
});
|
||||
return exercises;
|
||||
}
|
||||
|
||||
String getDateFormat(DateTime datetime) {
|
||||
return DateFormat('yMd', AppLanguage().appLocal.toString()).format(datetime);
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<DevelopmentByMuscleState> mapEventToState(DevelopmentByMuscleEvent event) async* {
|
||||
try {
|
||||
if (event is DevelopmentByMuscleLoad) {
|
||||
yield DevelopmentByMuscleLoadingState();
|
||||
Track().track(TrackingEvent.my_muscle_development);
|
||||
Cache().setActivityDonePrefs(ActivityDone.isMuscleDevelopmentSeen);
|
||||
await getData();
|
||||
yield DevelopmentByMuscleReadyState();
|
||||
} else if (event is DevelopmentByMuscleDiagramTypeChange) {
|
||||
yield DevelopmentByMuscleLoadingState();
|
||||
String type = event.diagramType;
|
||||
this.diagramType = type;
|
||||
getChartData();
|
||||
yield DevelopmentByMuscleReadyState();
|
||||
} else if (event is DevelopmentByMuscleDateRateChange) {
|
||||
yield DevelopmentByMuscleLoadingState();
|
||||
String dateRate = event.dateRate;
|
||||
this.dateRate = dateRate;
|
||||
getChartData();
|
||||
yield DevelopmentByMuscleReadyState();
|
||||
}
|
||||
} on Exception catch (e) {
|
||||
yield DevelopmentByMuscleErrorState(message: e.toString());
|
||||
}
|
||||
void _onLoad(DevelopmentByMuscleLoad event, Emitter<DevelopmentByMuscleState> emit) async {
|
||||
emit(DevelopmentByMuscleLoadingState());
|
||||
Track().track(TrackingEvent.my_muscle_development);
|
||||
Cache().setActivityDonePrefs(ActivityDone.isMuscleDevelopmentSeen);
|
||||
await getData();
|
||||
emit(DevelopmentByMuscleReadyState());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ class DevelopmentByMuscleLoad extends DevelopmentByMuscleEvent {
|
||||
}
|
||||
|
||||
class DevelopmentByMuscleDateRateChange extends DevelopmentByMuscleEvent {
|
||||
final String dateRate;
|
||||
final DiagramDateType dateRate;
|
||||
const DevelopmentByMuscleDateRateChange({required this.dateRate});
|
||||
|
||||
@override
|
||||
@@ -21,7 +21,7 @@ class DevelopmentByMuscleDateRateChange extends DevelopmentByMuscleEvent {
|
||||
}
|
||||
|
||||
class DevelopmentByMuscleDiagramTypeChange extends DevelopmentByMuscleEvent {
|
||||
final String diagramType;
|
||||
final DiagramType diagramType;
|
||||
const DevelopmentByMuscleDiagramTypeChange({required this.diagramType});
|
||||
|
||||
@override
|
||||
|
||||
@@ -0,0 +1,319 @@
|
||||
import 'package:aitrainer_app/util/app_language.dart';
|
||||
import 'package:aitrainer_app/util/common.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:aitrainer_app/model/cache.dart';
|
||||
import 'package:aitrainer_app/model/customer_property.dart';
|
||||
import 'package:aitrainer_app/model/exercise.dart';
|
||||
import 'package:aitrainer_app/repository/customer_repository.dart';
|
||||
import 'package:aitrainer_app/repository/exercise_repository.dart';
|
||||
import 'package:aitrainer_app/util/diagram_data.dart';
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
part 'development_diagram_event.dart';
|
||||
part 'development_diagram_state.dart';
|
||||
|
||||
enum DiagramDataSource { customerProperty, exercise }
|
||||
|
||||
extension DiagramDataSourceExt on DiagramDataSource {
|
||||
String toStr() => this.toString().split(".").last;
|
||||
bool equalsTo(DiagramDataSource filter) => this.toString() == filter.toString();
|
||||
bool equalsStringTo(String filter) => this.toString() == filter;
|
||||
}
|
||||
|
||||
enum DiagramDateFilter { daily, monthly, weekly, yearly }
|
||||
|
||||
extension DiagramDateFilterExt on DiagramDateFilter {
|
||||
String toStr() => this.toString().split(".").last;
|
||||
bool equalsTo(DiagramDateFilter filter) => this.toString() == filter.toString();
|
||||
bool equalsStringTo(String filter) => this.toString() == filter;
|
||||
}
|
||||
|
||||
enum DiagramGroup { none, sumMass, oneRepMax, percent }
|
||||
|
||||
extension DiagramGroupExt on DiagramDateFilter {
|
||||
String toStr() => this.toString().split(".").last;
|
||||
bool equalsTo(DiagramGroup filter) => this.toString() == filter.toString();
|
||||
bool equalsStringTo(String filter) => this.toString() == filter;
|
||||
}
|
||||
|
||||
class DevelopmentDiagramBloc extends Bloc<DevelopmentDiagramEvent, DevelopmentDiagramState> with Common {
|
||||
DiagramDateFilter dateFilter = DiagramDateFilter.monthly;
|
||||
DiagramGroup group = DiagramGroup.sumMass;
|
||||
final List<DiagramData> diagramData = [];
|
||||
|
||||
CustomerRepository? customerRepository;
|
||||
ExerciseRepository? exerciseRepository;
|
||||
String? propertyName;
|
||||
int? exerciseTypeId;
|
||||
final String diagramTitle;
|
||||
bool isGroup = true;
|
||||
|
||||
DevelopmentDiagramBloc({required this.diagramTitle, this.customerRepository, this.exerciseRepository, this.propertyName, this.exerciseTypeId})
|
||||
: super(DevelopmentDiagramInitial()) {
|
||||
_init();
|
||||
on<DevelopmentDiagramLoad>(_onLoad);
|
||||
on<DevelopmentDiagramChangeDateFormat>(_onChangeDateFormat);
|
||||
on<DevelopmentDiagramChangeGroup>(_onChangeGroup);
|
||||
}
|
||||
|
||||
void _onLoad(DevelopmentDiagramLoad event, Emitter<DevelopmentDiagramState> emit) {
|
||||
emit(DevelopmentDiagramLoading());
|
||||
if (Cache().userLoggedIn == null) {
|
||||
emit(DevelopmentDiagramError(message: "Please log in"));
|
||||
return;
|
||||
}
|
||||
|
||||
emit(DevelopmentDiagramReady());
|
||||
}
|
||||
|
||||
void _init() {
|
||||
if (customerRepository != null) {
|
||||
final List<CustomerProperty> properties = this.customerRepository!.getAllCustomerPropertyByName(this.propertyName!);
|
||||
this.fillDataCustomerProperty(properties, this.dateFilter);
|
||||
this.isGroup = false;
|
||||
} else {
|
||||
this.isGroup = true;
|
||||
this.getExerciseData();
|
||||
}
|
||||
this.dateFilter = DiagramDateFilter.monthly;
|
||||
}
|
||||
|
||||
void _onChangeDateFormat(DevelopmentDiagramChangeDateFormat event, Emitter<DevelopmentDiagramState> emit) {
|
||||
emit(DevelopmentDiagramLoading());
|
||||
this.dateFilter = event.dateFilter;
|
||||
print("Filter: ${this.dateFilter} - property: ${this.propertyName}");
|
||||
if (customerRepository != null) {
|
||||
final List<CustomerProperty> properties = this.customerRepository!.getAllCustomerPropertyByName(this.propertyName!);
|
||||
this.fillDataCustomerProperty(properties, this.dateFilter);
|
||||
} else {
|
||||
this.getExerciseData();
|
||||
}
|
||||
|
||||
emit(DevelopmentDiagramReady());
|
||||
}
|
||||
|
||||
void _onChangeGroup(DevelopmentDiagramChangeGroup event, Emitter<DevelopmentDiagramState> emit) {
|
||||
emit(DevelopmentDiagramLoading());
|
||||
this.group = event.group;
|
||||
this.getExerciseData();
|
||||
emit(DevelopmentDiagramReady());
|
||||
}
|
||||
|
||||
void getExerciseData() {
|
||||
this.diagramData.clear();
|
||||
this.getChartData();
|
||||
}
|
||||
|
||||
List<DiagramData> getChartData() {
|
||||
List<Exercise>? exercises = exerciseRepository!.getExerciseList();
|
||||
List<Exercise> _exercises = [];
|
||||
if (this.exerciseTypeId != null) {
|
||||
exercises!.forEach((element) {
|
||||
if (element.exerciseTypeId == this.exerciseTypeId) {
|
||||
_exercises.add(element);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
_exercises = sort(_exercises, true);
|
||||
|
||||
GroupDate groupDate = GroupDate(inputList: _exercises, outputList: this.diagramData);
|
||||
groupDate.dateRate = this.dateFilter;
|
||||
groupDate.diagramType = this.group;
|
||||
groupDate.iteration();
|
||||
|
||||
return this.diagramData;
|
||||
}
|
||||
|
||||
List<Exercise> sort(List<Exercise> _exercises, bool asc) {
|
||||
_exercises.sort((a, b) {
|
||||
var aDateId = a.exerciseTypeId.toString() + "_" + a.datePart.toString();
|
||||
var bDateId = b.exerciseTypeId.toString() + "_" + b.datePart.toString();
|
||||
|
||||
return asc ? aDateId.compareTo(bDateId) : bDateId.compareTo(aDateId);
|
||||
});
|
||||
return _exercises;
|
||||
}
|
||||
|
||||
void fillDataCustomerProperty(List<CustomerProperty> customerProperties, DiagramDateFilter filter) {
|
||||
this.diagramData.clear();
|
||||
this.dateFilter = filter;
|
||||
customerProperties.sort((a, b) => a.dateAdd!.compareTo(b.dateAdd!) > 0 ? 1 : -1);
|
||||
|
||||
double avg = 0;
|
||||
String? preFilter;
|
||||
if (this.dateFilter == DiagramDateFilter.daily) {
|
||||
preFilter = customerProperties[0].dateYmd;
|
||||
} else if (this.dateFilter == DiagramDateFilter.weekly) {
|
||||
preFilter = customerProperties[0].dateYmd;
|
||||
} else if (this.dateFilter == DiagramDateFilter.monthly) {
|
||||
preFilter = customerProperties[0].dateYm;
|
||||
} else if (this.dateFilter == DiagramDateFilter.yearly) {
|
||||
preFilter = customerProperties[0].dateY;
|
||||
}
|
||||
int counter = 0;
|
||||
customerProperties.forEach((element) {
|
||||
String? condition;
|
||||
if (this.dateFilter == DiagramDateFilter.daily) {
|
||||
condition = element.dateYmd;
|
||||
} else if (this.dateFilter == DiagramDateFilter.monthly) {
|
||||
condition = element.dateYm;
|
||||
} else if (this.dateFilter == DiagramDateFilter.weekly) {
|
||||
condition = element.dateYm;
|
||||
} else if (this.dateFilter == DiagramDateFilter.yearly) {
|
||||
condition = element.dateY;
|
||||
}
|
||||
|
||||
if (preFilter != condition) {
|
||||
int count = counter == 0 ? 1 : counter;
|
||||
DiagramData data = DiagramData(preFilter!, avg / count);
|
||||
//print("Sum: $avg count: $count Data: $data");
|
||||
diagramData.add(data);
|
||||
counter = 1;
|
||||
preFilter = condition;
|
||||
avg = element.propertyValue;
|
||||
} else {
|
||||
avg += element.propertyValue;
|
||||
counter++;
|
||||
}
|
||||
});
|
||||
int count = counter == 0 ? 1 : counter;
|
||||
if (preFilter != null) {
|
||||
DiagramData data = DiagramData(preFilter!, avg / count);
|
||||
diagramData.add(data);
|
||||
}
|
||||
print("Diagramdata: --- ${this.diagramData}");
|
||||
}
|
||||
}
|
||||
|
||||
class GroupDate extends GroupData with Common {
|
||||
final List<Exercise> inputList;
|
||||
final List<DiagramData> outputList;
|
||||
|
||||
String? _origDatePart;
|
||||
late int _origExerciseTypeId;
|
||||
late Exercise _origExercise;
|
||||
|
||||
late double _sumQuantity;
|
||||
late double _maxQuantity;
|
||||
late int _countExercises;
|
||||
double? _basePercent;
|
||||
|
||||
late DiagramGroup diagramType;
|
||||
late DiagramDateFilter dateRate;
|
||||
|
||||
GroupDate({required this.inputList, required this.outputList});
|
||||
|
||||
double getQuantityByDate(Exercise exercise) {
|
||||
double sum = 0;
|
||||
if (this.diagramType == DiagramGroup.sumMass) {
|
||||
if (exercise.unitQuantity != null) {
|
||||
sum = exercise.quantity! * exercise.unitQuantity!;
|
||||
} else {
|
||||
sum = exercise.quantity!;
|
||||
}
|
||||
} else if (this.diagramType == DiagramGroup.oneRepMax) {
|
||||
if (exercise.unitQuantity != null) {
|
||||
sum = calculate1RM(exercise.unitQuantity!, exercise.quantity!);
|
||||
} else {
|
||||
sum = exercise.quantity!;
|
||||
}
|
||||
} else if (this.diagramType == DiagramGroup.percent) {
|
||||
if (exercise.unitQuantity != null) {
|
||||
sum = calculate1RM(exercise.unitQuantity!, exercise.quantity!);
|
||||
if (_basePercent == null) {
|
||||
_basePercent = sum;
|
||||
}
|
||||
sum = (sum / this._basePercent!) * 100;
|
||||
} else {
|
||||
sum = exercise.quantity!;
|
||||
if (_basePercent == null) {
|
||||
_basePercent = sum;
|
||||
}
|
||||
sum = (sum / this._basePercent!) * 100;
|
||||
}
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
@override
|
||||
void addTempData(Exercise exercise) {
|
||||
double newQuantity = getQuantityByDate(exercise);
|
||||
_sumQuantity = _sumQuantity + newQuantity;
|
||||
if (_maxQuantity < newQuantity) {
|
||||
_maxQuantity = newQuantity;
|
||||
}
|
||||
_countExercises = _countExercises + 1;
|
||||
_origDatePart = getDatePart(exercise.dateAdd!, dateRate);
|
||||
_origExerciseTypeId = exercise.exerciseTypeId!;
|
||||
_origExercise = exercise;
|
||||
}
|
||||
|
||||
@override
|
||||
bool checkNewType(Exercise exercise) {
|
||||
String exerciseDatePart = getDatePart(exercise.dateAdd!, dateRate);
|
||||
return _origDatePart == null || _origDatePart != exerciseDatePart || _origExerciseTypeId != exercise.exerciseTypeId;
|
||||
}
|
||||
|
||||
String getDatePart(DateTime date, DiagramDateFilter dateRate) {
|
||||
String datePart = DateFormat('yy.MM.dd', AppLanguage().appLocal.toString()).format(date);
|
||||
if (dateRate == DiagramDateFilter.weekly) {
|
||||
datePart = weekNumber(date).toString();
|
||||
} else if (dateRate == DiagramDateFilter.monthly) {
|
||||
datePart = DateFormat('yy.MM', AppLanguage().appLocal.toString()).format(date);
|
||||
} else if (dateRate == DiagramDateFilter.yearly) {
|
||||
datePart = DateFormat('y', AppLanguage().appLocal.toString()).format(date);
|
||||
} else if (dateRate == DiagramDateFilter.daily) {
|
||||
datePart = DateFormat('yy.MM.dd', AppLanguage().appLocal.toString()).format(date);
|
||||
}
|
||||
return datePart;
|
||||
}
|
||||
|
||||
@override
|
||||
void iteration() {
|
||||
this.resetTemp();
|
||||
Exercise? tempExercise;
|
||||
inputList.forEach((element) {
|
||||
tempExercise = element;
|
||||
if (this.checkNewType(element)) {
|
||||
if (_origDatePart == null) {
|
||||
this.addTempData(element);
|
||||
} else {
|
||||
this.temp2Output(_origExercise);
|
||||
this.resetTemp();
|
||||
this.addTempData(element);
|
||||
}
|
||||
} else {
|
||||
this.addTempData(element);
|
||||
}
|
||||
});
|
||||
if (tempExercise != null) {
|
||||
this.temp2Output(tempExercise!);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void temp2Output(Exercise exercise) {
|
||||
if (exercise.unitQuantity == null) {
|
||||
return;
|
||||
}
|
||||
Exercise newExercise = exercise.copy();
|
||||
newExercise.datePart = _origDatePart;
|
||||
if (this.diagramType == DiagramGroup.oneRepMax || this.diagramType == DiagramGroup.percent) {
|
||||
newExercise.calculated = _maxQuantity;
|
||||
} else {
|
||||
newExercise.calculated = _sumQuantity / _countExercises;
|
||||
}
|
||||
DiagramData data = DiagramData(newExercise.datePart!, newExercise.calculated);
|
||||
print("chart add $data");
|
||||
outputList.add(data);
|
||||
}
|
||||
|
||||
@override
|
||||
void resetTemp() {
|
||||
_countExercises = 0;
|
||||
_sumQuantity = 0;
|
||||
_maxQuantity = 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
part of 'development_diagram_bloc.dart';
|
||||
|
||||
abstract class DevelopmentDiagramEvent extends Equatable {
|
||||
const DevelopmentDiagramEvent();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class DevelopmentDiagramLoad extends DevelopmentDiagramEvent {
|
||||
const DevelopmentDiagramLoad();
|
||||
}
|
||||
|
||||
class DevelopmentDiagramChangeDateFormat extends DevelopmentDiagramEvent {
|
||||
final DiagramDateFilter dateFilter;
|
||||
const DevelopmentDiagramChangeDateFormat({required this.dateFilter});
|
||||
}
|
||||
|
||||
class DevelopmentDiagramChangeGroup extends DevelopmentDiagramEvent {
|
||||
final DiagramGroup group;
|
||||
const DevelopmentDiagramChangeGroup({required this.group});
|
||||
}
|
||||
|
||||
class DevelopmentDiagramInitCustomerData extends DevelopmentDiagramEvent {
|
||||
final CustomerRepository customerRepository;
|
||||
final String propertyName;
|
||||
|
||||
const DevelopmentDiagramInitCustomerData({required this.customerRepository, required this.propertyName});
|
||||
@override
|
||||
List<Object> get props => [customerRepository, propertyName];
|
||||
}
|
||||
|
||||
class DevelopmentDiagramInitExerciseData extends DevelopmentDiagramEvent {
|
||||
final ExerciseRepository exerciseRepository;
|
||||
final int exerciseTypeId;
|
||||
|
||||
const DevelopmentDiagramInitExerciseData({required this.exerciseRepository, required this.exerciseTypeId});
|
||||
@override
|
||||
List<Object> get props => [exerciseRepository, exerciseTypeId];
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
part of 'development_diagram_bloc.dart';
|
||||
|
||||
abstract class DevelopmentDiagramState extends Equatable {
|
||||
const DevelopmentDiagramState();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class DevelopmentDiagramInitial extends DevelopmentDiagramState {
|
||||
const DevelopmentDiagramInitial();
|
||||
}
|
||||
|
||||
class DevelopmentDiagramLoading extends DevelopmentDiagramState {
|
||||
const DevelopmentDiagramLoading();
|
||||
}
|
||||
|
||||
class DevelopmentDiagramReady extends DevelopmentDiagramState {
|
||||
const DevelopmentDiagramReady();
|
||||
}
|
||||
|
||||
class DevelopmentDiagramError extends DevelopmentDiagramState {
|
||||
final String message;
|
||||
const DevelopmentDiagramError({required this.message});
|
||||
|
||||
@override
|
||||
List<Object> get props => [this.message];
|
||||
}
|
||||
@@ -1,5 +1,3 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:aitrainer_app/model/cache.dart';
|
||||
import 'package:aitrainer_app/repository/customer_repository.dart';
|
||||
import 'package:bloc/bloc.dart';
|
||||
@@ -11,22 +9,26 @@ part 'development_sizes_state.dart';
|
||||
class DevelopmentSizesBloc extends Bloc<DevelopmentSizesEvent, DevelopmentSizesState> {
|
||||
final CustomerRepository customerRepository;
|
||||
DevelopmentSizesBloc({required this.customerRepository}) : super(DevelopmentSizesInitial()) {
|
||||
isMan = Cache().userLoggedIn!.sex == "m";
|
||||
isMan = true;
|
||||
if ( Cache().userLoggedIn == null) {
|
||||
isMan = Cache().userLoggedIn!.sex == "m";
|
||||
}
|
||||
|
||||
on<DevelopmentSizesLoad>(_onLoad);
|
||||
}
|
||||
|
||||
late bool isMan;
|
||||
|
||||
@override
|
||||
Stream<DevelopmentSizesState> mapEventToState(
|
||||
DevelopmentSizesEvent event,
|
||||
) async* {
|
||||
try {
|
||||
if (state is DevelopmentSizesLoad) {
|
||||
yield DevelopmentSizesLoading();
|
||||
yield DevelopmentSizesReady();
|
||||
}
|
||||
} on Exception catch (e) {
|
||||
yield DevelopmentSizesError(message: e.toString());
|
||||
void _onLoad(DevelopmentSizesLoad event, Emitter<DevelopmentSizesState> emit) {
|
||||
emit( DevelopmentSizesLoading());
|
||||
if ( Cache().userLoggedIn == null) {
|
||||
emit(DevelopmentSizesError(message: "Please log in" ));
|
||||
return;
|
||||
}
|
||||
customerRepository.customer = Cache().userLoggedIn!;
|
||||
emit( DevelopmentSizesReady());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ import 'package:aitrainer_app/util/purchases.dart';
|
||||
import 'package:aitrainer_app/util/track.dart';
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:purchases_flutter/offering_wrapper.dart';
|
||||
import 'package:purchases_flutter/models/offering_wrapper.dart';
|
||||
|
||||
part 'sales_event.dart';
|
||||
part 'sales_state.dart';
|
||||
|
||||
@@ -12,7 +12,7 @@ import 'package:flutter/material.dart';
|
||||
part 'training_evaluation_event.dart';
|
||||
part 'training_evaluation_state.dart';
|
||||
|
||||
class TrainingEvaluationBloc extends Bloc<TrainingEvaluationEvent, TrainingEvaluationState> {
|
||||
class TrainingEvaluationBloc extends Bloc<TrainingEvaluationEvent, TrainingEvaluationState> with Common {
|
||||
final TrainingPlanBloc trainingPlanBloc;
|
||||
final String day;
|
||||
TrainingEvaluationBloc({required this.trainingPlanBloc, required this.day}) : super(TrainingEvaluationInitial()) {
|
||||
@@ -42,32 +42,6 @@ class TrainingEvaluationBloc extends Bloc<TrainingEvaluationEvent, TrainingEvalu
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@override
|
||||
Stream<TrainingEvaluationState> mapEventToState(
|
||||
TrainingEvaluationEvent event,
|
||||
) async* {
|
||||
try {
|
||||
if (event is TrainingEvaluationLoad) {
|
||||
//yield TrainingEvaluationLoading();
|
||||
await saveResult();
|
||||
getDuration();
|
||||
getTotalLift();
|
||||
getMaxRepeats();
|
||||
getTotalRepeats();
|
||||
createEvaluationData();
|
||||
getMaxLift();
|
||||
if (end == null || DateTime.now().difference(end!).inMinutes > 5) {
|
||||
yield TrainingEvaluationReady();
|
||||
} else {
|
||||
yield TrainingEvaluationVictoryReady();
|
||||
}
|
||||
}
|
||||
} on Exception catch (e) {
|
||||
yield TrainingEvaluationError(message: e.toString());
|
||||
}
|
||||
} */
|
||||
|
||||
void createEvaluationData() {
|
||||
if (trainingPlanBloc.getMyPlan() == null || trainingPlanBloc.getMyPlan()!.days[day] == null) {
|
||||
return;
|
||||
@@ -114,7 +88,7 @@ class TrainingEvaluationBloc extends Bloc<TrainingEvaluationEvent, TrainingEvalu
|
||||
exercise.trend = getTrendEvaluationRepeats(exercise);
|
||||
} else {
|
||||
exercise.type = TrainingEvaluationExerciseType.weightBased;
|
||||
exercise.oneRepMax = Common.calculate1RM(detail.weight!, detail.repeats!.toDouble());
|
||||
exercise.oneRepMax = calculate1RM(detail.weight!, detail.repeats!.toDouble());
|
||||
exercise.max1RM = getMax1RMByExerciseType(detail.exerciseTypeId!);
|
||||
exercise.totalLift = getTotalLiftBySameExercise(detail.exerciseTypeId!);
|
||||
exercise.maxTotalLift = getMaxTotalLiftByExerciseType(detail.exerciseTypeId!);
|
||||
@@ -300,7 +274,7 @@ class TrainingEvaluationBloc extends Bloc<TrainingEvaluationEvent, TrainingEvalu
|
||||
if (element.dateAdd != null) {
|
||||
final String formattedExerciseDate = formatter.format(element.dateAdd!);
|
||||
if (element.exerciseTypeId == exerciseTypeId && formattedToday != formattedExerciseDate) {
|
||||
final double oneRepMax = Common.calculate1RM(element.unitQuantity!, element.quantity!);
|
||||
final double oneRepMax = calculate1RM(element.unitQuantity!, element.quantity!);
|
||||
if (max1RM < oneRepMax) {
|
||||
max1RM = oneRepMax;
|
||||
}
|
||||
@@ -330,7 +304,7 @@ class TrainingEvaluationBloc extends Bloc<TrainingEvaluationEvent, TrainingEvalu
|
||||
if (detail.weight == null) {
|
||||
return 0;
|
||||
}
|
||||
return Common.calculate1RM(detail.weight!, detail.repeats!.toDouble());
|
||||
return calculate1RM(detail.weight!, detail.repeats!.toDouble());
|
||||
}
|
||||
|
||||
double getTotalLiftExercise(CustomerTrainingPlanDetails detail) {
|
||||
|
||||
@@ -27,7 +27,7 @@ import 'package:flutter/material.dart';
|
||||
part 'training_plan_event.dart';
|
||||
part 'training_plan_state.dart';
|
||||
|
||||
class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> {
|
||||
class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> with Common {
|
||||
final TrainingPlanRepository trainingPlanRepository;
|
||||
final MenuBloc menuBloc;
|
||||
TrainingPlanBloc({required this.trainingPlanRepository, required this.menuBloc}) : super(TrainingPlanInitial()) {
|
||||
@@ -198,7 +198,6 @@ class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> {
|
||||
|
||||
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) {
|
||||
@@ -214,7 +213,7 @@ class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> {
|
||||
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());
|
||||
nextDetail.baseOneRepMax = 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);
|
||||
@@ -223,22 +222,21 @@ class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> {
|
||||
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());
|
||||
nextDetail.baseOneRepMax = 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!;
|
||||
nextDetail.baseOneRepMax = calculate1RM(nextDetail.weight!, nextDetail.repeats!.toDouble());
|
||||
} 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());
|
||||
nextDetail.baseOneRepMax = calculate1RM(nextDetail.weight!, nextDetail.repeats!.toDouble());
|
||||
} else if (id != 0) {
|
||||
// calculate weight and repeat based on the first baseOneRepMax
|
||||
if (baseCustomerTrainingPlanDetailsId != 0) {
|
||||
@@ -918,8 +916,7 @@ class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> {
|
||||
if (_myDetail == null || _myDetail!.exerciseType == null) {
|
||||
return exerciseName;
|
||||
}
|
||||
exerciseName =
|
||||
AppLanguage().appLocal == Locale("en") ? getMyDetail()!.exerciseType!.name : getMyDetail()!.exerciseType!.nameTranslation;
|
||||
exerciseName = AppLanguage().appLocal == Locale("en") ? getMyDetail()!.exerciseType!.name : getMyDetail()!.exerciseType!.nameTranslation;
|
||||
return exerciseName;
|
||||
}
|
||||
|
||||
@@ -1007,8 +1004,7 @@ class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> {
|
||||
if (listDetail.exercises.length >= listDetail.set!) {
|
||||
listDetail.state = ExercisePlanDetailState.finished;
|
||||
}
|
||||
allFinished =
|
||||
allFinished && (listDetail.exercises.length >= listDetail.set! || listDetail.state.equalsTo(ExercisePlanDetailState.skipped));
|
||||
allFinished = allFinished && (listDetail.exercises.length >= listDetail.set! || listDetail.state.equalsTo(ExercisePlanDetailState.skipped));
|
||||
}
|
||||
//print("All finished: $allFinished for ${detail.exerciseTypeId}");
|
||||
return allFinished;
|
||||
|
||||
Reference in New Issue
Block a user