Skip to content

Commit

Permalink
testie
Browse files Browse the repository at this point in the history
  • Loading branch information
Desync-o-tron committed Oct 8, 2024
1 parent 7c9213c commit 118db8e
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 32 deletions.
94 changes: 62 additions & 32 deletions lib/DOM/history_importing_logic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,54 +54,84 @@ List<TrainingSession> importStrongCsv(String filepathORfileStr, Units units,
notes: workoutNotes,
);
}

bool newExercise = false;
if (exerciseName != exercise.name) {
newExercise = true;
}
bool newSession = isNewSession(session, duration, workoutName, date);
bool lastSetEver = (i == rows.length - 1);

if ((i == rows.length - 1)) {
print("object");
}

//todo implement notes history.
exercise = Exercise(name: exerciseName, notes: notes);
final set = Set(exercise)
..reps = reps
..weight = weight
..distance = distance
..time = seconds.toDouble()
..massUnits = units.preferredMassUnit
..distanceUnits = units.preferredDistanceUnit
..completed = true;

if (!newExercise) {
setsOfExercise.sets.add(set);
}
if ((newExercise) || (i == rows.length - 1)) {
session.trainingData.add(setsOfExercise);
setsOfExercise = SetsOfAnExercise(exercise)..sets = [set];
if ((i == rows.length - 1) && !isNewSession(session, duration, workoutName, date)) {
session.trainingData.add(setsOfExercise);
}
}

// if (isNewSession(session, duration, workoutName, date) || (i == rows.length - 1)) {
// sessions.add(session);
// }
if (isNewSession(session, duration, workoutName, date)) {
//we have to save & renew the session FIRST, as it's going to get stuff added to it.
if (newSession) {
sessions.add(session);
session = TrainingSession(
name: workoutName,
dateOfLastEdit: date,
date: date,
duration: duration,
notes: workoutNotes,
trainingData: [setsOfExercise],
);
}
if (i == rows.length - 1) {
if (newExercise) {
session.trainingData.add(setsOfExercise);
setsOfExercise = SetsOfAnExercise(exercise);
}

//todo implement notes history.
exercise = Exercise(name: exerciseName, notes: notes);
final set = Set.full(
ex: exercise,
reps: reps,
weight: weight,
distance: distance,
time: seconds.toDouble(),
massUnits: units.preferredMassUnit,
distanceUnits: units.preferredDistanceUnit,
completed: true,
);

if (newExercise) {
setsOfExercise.sets = [set];
} else {
setsOfExercise.sets.add(set);
}

if (lastSetEver) {
session.trainingData.add(setsOfExercise);
sessions.add(session);
}

/////
////
// if (!newExercise) {
// setsOfExercise.sets.add(set);
// }
// if ((newExercise) || (i == rows.length - 1)) {
// session.trainingData.add(setsOfExercise);
// setsOfExercise = SetsOfAnExercise(exercise)..sets = [set];
// if ((i == rows.length - 1) && !isNewSession(session, duration, workoutName, date)) {
// session.trainingData.add(setsOfExercise);
// }
// }

// // if (isNewSession(session, duration, workoutName, date) || (i == rows.length - 1)) {
// // sessions.add(session);
// // }
// if (isNewSession(session, duration, workoutName, date)) {
// sessions.add(session);
// session = TrainingSession(
// name: workoutName,
// dateOfLastEdit: date,
// date: date,
// duration: duration,
// notes: workoutNotes,
// trainingData: [setsOfExercise],
// );
// }
// if (i == rows.length - 1) {
// sessions.add(session);
// }
}

//TODO lets run through all the sessions and update the setMetrics.
Expand Down
15 changes: 15 additions & 0 deletions lib/DOM/training_metadata.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,21 @@ class Set {
//if contains anythign else, throw error
}

// New constructor that takes all members as parameters
Set.full({
required this.ex,
this.reps,
this.time,
this.weight,
this.distance,
this.speed,
this.massUnits,
this.distanceUnits,
this.completed = false,
}) {
Set(ex);
}

factory Set.fromJson(Map<String, dynamic> json) => _$SetFromJson(json);
Map<String, dynamic> toJson() => _$SetToJson(this);
}
Expand Down

0 comments on commit 118db8e

Please sign in to comment.