Skip to content

Commit

Permalink
this importer is CCRAP
Browse files Browse the repository at this point in the history
  • Loading branch information
Desync-o-tron committed Oct 8, 2024
1 parent 4bc307f commit 7c9213c
Show file tree
Hide file tree
Showing 13 changed files with 328 additions and 213 deletions.
8 changes: 5 additions & 3 deletions lib/DOM/basic_user_info.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions lib/DOM/exercise_metadata.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dart run build_runner watch --delete-conflicting-outputs
@JsonSerializable()
class Exercise {
String? id;
//^does id matter? is it another thing to track? there *should not* be name dupes.
//todo ^does id matter? is it another thing to track? there *should not* be name dupes.
String name;
List<String>? alternateNames = [];
Force? force;
Expand All @@ -21,7 +21,7 @@ class Exercise {
// List<String> noteHistory; //todo
List<String>? setMetrics;
//todo^ not in the json schema. (time, weight, distance, speed, reps)
List<String> primaryMuscles;
late List<String> primaryMuscles;
List<String>? secondaryMuscles;
List<String>? instructions;
// powerlifting, strength, cardio, olympicWeightlifting, strongman, plyometrics,
Expand All @@ -34,15 +34,16 @@ class Exercise {
this.force,
this.level,
this.mechanic,
required this.equipment,
this.equipment,
this.notes,
this.setMetrics,
required this.primaryMuscles,
List<String>? primaryMuscles,
this.secondaryMuscles,
this.instructions,
this.category,
this.images,
}) {
this.primaryMuscles = primaryMuscles ?? [];
if (setMetrics == null) {
if (category == "cardio") {
setMetrics = ["time", "distance", "speed"];
Expand Down
4 changes: 2 additions & 2 deletions lib/DOM/exercise_metadata.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

132 changes: 75 additions & 57 deletions lib/DOM/history_importing_logic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import 'package:intl/intl.dart';
import 'training_metadata.dart';
import 'exercise_metadata.dart';

List<TrainingSession> importStrongCsv(String filepathORfileStr, Units units) {
List<TrainingSession> importStrongCsv(String filepathORfileStr, Units units,
[bool forTesting = false]) {
final List<String> rows;
if (kIsWeb) {
if (kIsWeb || forTesting) {
rows = filepathORfileStr.split("\n");
if (rows.last.isEmpty) {
rows.removeLast();
Expand All @@ -17,21 +18,11 @@ List<TrainingSession> importStrongCsv(String filepathORfileStr, Units units) {
}
rows.removeAt(0);

//todo we should save teh header & compare it to see if it ever changes and bricks shit
//todo save the header.. if it ever changes, lets make a pub/sub topic on gcs or some error medium to lmk!!!
List<TrainingSession> sessions = [];
Exercise exercise = Exercise(
name: "temp",
setMetrics: ['reps', 'weight', 'distance', 'time'],
equipment: 'temp',
notes: 'temp',
primaryMuscles: ['temp'],
);
TrainingSession session = TrainingSession(
name: "temp",
date: DateTime.now(),
);
SetsOfAnExercise setsOfExercise = SetsOfAnExercise(exercise);
Exercise exercise = Exercise(name: "temp");
TrainingSession session = TrainingSession(name: "temp", date: DateTime.now());
SetsOfAnExercise setsOfExercise = SetsOfAnExercise(exercise)..sets = [];
bool firstRun = true;

for (int i = 0; i < rows.length; i++) {
Expand All @@ -52,17 +43,9 @@ List<TrainingSession> importStrongCsv(String filepathORfileStr, Units units) {
final workoutNotes = rowList[0][10];

if (firstRun) {
exercise.name = exerciseName;
exercise.notes = notes;
}

//log the session
if ((duration != session.duration ||
session.name != workoutName ||
date != session.date ||
(i == rows.length - 1)) &&
!firstRun) {
sessions.add(session);
firstRun = false;
exercise = Exercise(name: exerciseName, notes: notes);
setsOfExercise = SetsOfAnExercise(exercise)..sets = [];
session = TrainingSession(
name: workoutName,
dateOfLastEdit: date,
Expand All @@ -71,38 +54,17 @@ List<TrainingSession> importStrongCsv(String filepathORfileStr, Units units) {
notes: workoutNotes,
);
}
bool newExercise = false;
if (exerciseName != exercise.name) {
newExercise = true;
}

//log the exercise
if ((exerciseName != exercise.name) || (i == rows.length - 1) && !firstRun) {
List<String> setMetrics = [];
//strong is going to give a value of 0 instead of null for things.
for (var set in setsOfExercise.sets) {
if (set.reps! > 0) setMetrics.add("reps");
if (set.weight! > 0) setMetrics.add("weight");
if (set.distance! > 0) setMetrics.add("distance");
if (set.time! > 0) setMetrics.add("time");
}
for (var set in setsOfExercise.sets) {
if (!setMetrics.contains('reps')) set.reps = null;
if (!setMetrics.contains('weight')) set.weight = null;
if (!setMetrics.contains('distance')) set.distance = null;
if (!setMetrics.contains('time')) set.time = null;
}
setsOfExercise.ex.setMetrics = setMetrics;
setsOfExercise.prevSet = setsOfExercise.sets.last;
session.trainingData.add(setsOfExercise);

exercise = Exercise(
name: exerciseName,
equipment: "temp",
primaryMuscles: ["temp"],
notes: notes,
setMetrics: ['reps', 'weight', 'distance', 'time'],
);
setsOfExercise = SetsOfAnExercise(exercise);
if ((i == rows.length - 1)) {
print("object");
}

//every loop is a new set!
//todo implement notes history.
exercise = Exercise(name: exerciseName, notes: notes);
final set = Set(exercise)
..reps = reps
..weight = weight
Expand All @@ -112,14 +74,70 @@ List<TrainingSession> importStrongCsv(String filepathORfileStr, Units units) {
..distanceUnits = units.preferredDistanceUnit
..completed = true;

setsOfExercise.sets.add(set);
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);
}
}

firstRun = false;
// 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.
// setMetrics: ['reps', 'weight', 'distance', 'time'],

return sessions;
}

bool isNewSession(
TrainingSession session, Duration duration, workoutName, DateTime date) {
return duration != session.duration ||
workoutName != session.name ||
date != session.date;
}

void setupSetMetrics(SetsOfAnExercise setsOfExercise) {
List<String> setMetrics = [];
//strong is going to give a value of 0 instead of null for things.
for (var set in setsOfExercise.sets) {
if (set.reps! > 0) setMetrics.add("reps");
if (set.weight! > 0) setMetrics.add("weight");
if (set.distance! > 0) setMetrics.add("distance");
if (set.time! > 0) setMetrics.add("time");
}
for (var set in setsOfExercise.sets) {
if (!setMetrics.contains('reps')) set.reps = null;
if (!setMetrics.contains('weight')) set.weight = null;
if (!setMetrics.contains('distance')) set.distance = null;
if (!setMetrics.contains('time')) set.time = null;
}
setsOfExercise.ex.setMetrics = setMetrics;
setsOfExercise.prevSet = Set(setsOfExercise.ex);
// setsOfExercise.prevSet = setsOfExercise.sets.last;
//TODO this is bs. need a function to run after we have sorted sets by time.
}

Duration parseStrongWorkoutDuration(String s) {
int hours = 0;
int minutes = 0;
Expand Down
4 changes: 3 additions & 1 deletion lib/DOM/training_metadata.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ class TrainingSession {
@JsonSerializable(explicitToJson: true)
class SetsOfAnExercise {
Exercise ex;
Set prevSet; //also functions as a header template

///prevSet also functions as a template for UI headers
Set prevSet;
List<Set> sets = [];

SetsOfAnExercise(this.ex) : prevSet = Set(ex) {
Expand Down
Loading

0 comments on commit 7c9213c

Please sign in to comment.