WT 1.1.26+3 bloc migration
This commit is contained in:
@@ -1,12 +1,9 @@
|
||||
import 'package:intl/intl.dart';
|
||||
import 'dart:async';
|
||||
import 'package:aitrainer_app/model/cache.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/app_language.dart';
|
||||
|
||||
import 'package:aitrainer_app/util/common.dart';
|
||||
import 'package:aitrainer_app/util/enums.dart';
|
||||
import 'package:aitrainer_app/util/diagram_data.dart';
|
||||
@@ -18,391 +15,17 @@ import 'package:flutter/material.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";
|
||||
static String percent = "percent";
|
||||
}
|
||||
|
||||
/*
|
||||
=========== GROUPDATE CLASS
|
||||
*/
|
||||
|
||||
class GroupDate extends GroupData with Common {
|
||||
final List<Exercise> inputList;
|
||||
final List<Exercise> outputList;
|
||||
|
||||
String? _origDatePart;
|
||||
late int _origExerciseTypeId;
|
||||
late Exercise _origExercise;
|
||||
|
||||
late double _sumQuantity;
|
||||
late double _maxQuantity;
|
||||
late int _countExercises;
|
||||
|
||||
late String diagramType;
|
||||
late String 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;
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
outputList.add(newExercise);
|
||||
}
|
||||
|
||||
@override
|
||||
void resetTemp() {
|
||||
_countExercises = 0;
|
||||
_sumQuantity = 0;
|
||||
_maxQuantity = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
=========== CHART DATA CLASS
|
||||
*/
|
||||
class GroupChart extends GroupData with Common {
|
||||
final List<dynamic> inputList;
|
||||
LinkedHashMap<int, ChartDataExtended> outputList = LinkedHashMap();
|
||||
|
||||
int? _origExerciseTypeId;
|
||||
late double _minData = 999999999999;
|
||||
late double _maxData = 0;
|
||||
late List<BarChartGroupData> _chartData;
|
||||
late double _basePercent;
|
||||
|
||||
String diagramType = DiagramType.sumMass;
|
||||
|
||||
GroupChart({required this.inputList, required this.outputList});
|
||||
|
||||
double getBasePercent(Exercise exercise) {
|
||||
if (exercise.unitQuantity != null) {
|
||||
this._basePercent = calculate1RM(exercise.quantity!, exercise.unitQuantity!);
|
||||
} else {
|
||||
this._basePercent = exercise.quantity!;
|
||||
}
|
||||
return this._basePercent;
|
||||
}
|
||||
|
||||
double getDiagramValue(Exercise exercise) {
|
||||
double value = 0;
|
||||
|
||||
if (diagramType == DiagramType.percent) {
|
||||
if (exercise.unitQuantity != null) {
|
||||
double oneRepMax = calculate1RM(exercise.quantity!, exercise.unitQuantity!);
|
||||
value = (oneRepMax / this._basePercent) * 100;
|
||||
} else {
|
||||
value = (exercise.quantity! / this._basePercent) * 100;
|
||||
}
|
||||
} else if (diagramType == DiagramType.oneRepMax || diagramType == DiagramType.sumMass) {
|
||||
value = exercise.calculated!;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
@override
|
||||
void addTempData(Exercise exercise) {
|
||||
double diagramValue = this.getDiagramValue(exercise);
|
||||
|
||||
if (_maxData < diagramValue) {
|
||||
_maxData = diagramValue;
|
||||
}
|
||||
if (_minData > diagramValue) {
|
||||
_minData = diagramValue;
|
||||
}
|
||||
|
||||
BarChartGroupData data = BarChartGroupData(
|
||||
x: exercise.dateAdd!.millisecondsSinceEpoch, barRods: [BarChartRodData(toY: diagramValue, width: 12, color: Colors.lightBlue)]);
|
||||
_chartData.add(data);
|
||||
_origExerciseTypeId = exercise.exerciseTypeId!;
|
||||
}
|
||||
|
||||
@override
|
||||
bool checkNewType(Exercise exercise) {
|
||||
return _origExerciseTypeId == null || _origExerciseTypeId != exercise.exerciseTypeId;
|
||||
}
|
||||
|
||||
@override
|
||||
void iteration() {
|
||||
this.resetTemp();
|
||||
Exercise? tempExercise;
|
||||
inputList.forEach((element) {
|
||||
tempExercise = element;
|
||||
|
||||
if (this.checkNewType(element)) {
|
||||
if (_origExerciseTypeId == null) {
|
||||
_basePercent = getBasePercent(element);
|
||||
this.addTempData(element);
|
||||
} else {
|
||||
this.temp2Output(element);
|
||||
this.resetTemp();
|
||||
_basePercent = getBasePercent(element);
|
||||
this.addTempData(element);
|
||||
}
|
||||
} else {
|
||||
this.addTempData(element);
|
||||
}
|
||||
});
|
||||
if (tempExercise != null) {
|
||||
this.temp2Output(tempExercise!);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void temp2Output(Exercise exercise) {
|
||||
double dInterval = ((_maxData + _minData) / 8).roundToDouble();
|
||||
int gridInterval = (dInterval / 3).floor();
|
||||
|
||||
ChartDataExtended extended;
|
||||
if (outputList[_origExerciseTypeId] == null) {
|
||||
extended = ChartDataExtended(data: _chartData, interval: dInterval, gridInterval: gridInterval);
|
||||
outputList[_origExerciseTypeId!] = extended;
|
||||
} else {
|
||||
extended = outputList[_origExerciseTypeId]!;
|
||||
_chartData.forEach((element) {
|
||||
extended.data.add(element);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void resetTemp() {
|
||||
_minData = 999999999999;
|
||||
_maxData = 0;
|
||||
_chartData = [];
|
||||
}
|
||||
}
|
||||
|
||||
class ChartDataExtended {
|
||||
final List<BarChartGroupData> data;
|
||||
final double interval;
|
||||
final int gridInterval;
|
||||
|
||||
const ChartDataExtended({required this.data, required this.interval, required this.gridInterval});
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
List listBarChartData = [];
|
||||
data.forEach((element) {
|
||||
element.barRods.forEach((rods) {
|
||||
var barChartData = {
|
||||
'x': element.x,
|
||||
'y': rods.toY,
|
||||
};
|
||||
listBarChartData.add(barChartData);
|
||||
});
|
||||
});
|
||||
var chartData = {
|
||||
"data": listBarChartData.toString(),
|
||||
"interval": interval.toString(),
|
||||
"gridInterval": gridInterval,
|
||||
};
|
||||
return chartData;
|
||||
}
|
||||
} */
|
||||
|
||||
class DevelopmentByMuscleBloc extends Bloc<DevelopmentByMuscleEvent, DevelopmentByMuscleState> with Common, Logging {
|
||||
final WorkoutTreeRepository workoutTreeRepository;
|
||||
final ExerciseRepository exerciseRepository = ExerciseRepository();
|
||||
final List<DiagramData> diagramData = [];
|
||||
int actualExerciseType = 0;
|
||||
DiagramType diagramType = DiagramType.sumMass;
|
||||
DiagramDateType diagramDateType = DiagramDateType.monthly;
|
||||
|
||||
@override
|
||||
DevelopmentByMuscleBloc({required this.workoutTreeRepository}) : super(DevelopmentByMuscleStateInitial()) {
|
||||
on<DevelopmentByMuscleLoad>(_onLoad);
|
||||
}
|
||||
|
||||
Future<void> getData() async {
|
||||
void getTree() {
|
||||
workoutTreeRepository.sortedTree.clear();
|
||||
workoutTreeRepository.sortByMuscleType();
|
||||
|
||||
@@ -414,11 +37,11 @@ class DevelopmentByMuscleBloc extends Bloc<DevelopmentByMuscleEvent, Development
|
||||
});
|
||||
}
|
||||
|
||||
void _onLoad(DevelopmentByMuscleLoad event, Emitter<DevelopmentByMuscleState> emit) async {
|
||||
void _onLoad(DevelopmentByMuscleLoad event, Emitter<DevelopmentByMuscleState> emit) {
|
||||
emit(DevelopmentByMuscleLoadingState());
|
||||
Track().track(TrackingEvent.my_muscle_development);
|
||||
Cache().setActivityDonePrefs(ActivityDone.isMuscleDevelopmentSeen);
|
||||
await getData();
|
||||
getTree();
|
||||
emit(DevelopmentByMuscleReadyState());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,19 +11,3 @@ abstract class DevelopmentByMuscleEvent extends Equatable {
|
||||
class DevelopmentByMuscleLoad extends DevelopmentByMuscleEvent {
|
||||
const DevelopmentByMuscleLoad();
|
||||
}
|
||||
|
||||
class DevelopmentByMuscleDateRateChange extends DevelopmentByMuscleEvent {
|
||||
final DiagramDateType dateRate;
|
||||
const DevelopmentByMuscleDateRateChange({required this.dateRate});
|
||||
|
||||
@override
|
||||
List<Object> get props => [dateRate];
|
||||
}
|
||||
|
||||
class DevelopmentByMuscleDiagramTypeChange extends DevelopmentByMuscleEvent {
|
||||
final DiagramType diagramType;
|
||||
const DevelopmentByMuscleDiagramTypeChange({required this.diagramType});
|
||||
|
||||
@override
|
||||
List<Object> get props => [diagramType];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user