Skip to content

Commit

Permalink
Include exercises with different reps in previous history
Browse files Browse the repository at this point in the history
This commit relaxes the restriction of having to have the exact same name/reps/sets to show up in the exercise history list
  • Loading branch information
LiamMorrow committed Oct 2, 2024
1 parent f86e8ee commit 7527026
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
31 changes: 28 additions & 3 deletions LiftLog.Lib/Models/BlueprintModels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,35 @@ public record ExerciseBlueprint(
string Notes
);

public record KeyedExerciseBlueprint(string Name, int Sets, int RepsPerSet)
public sealed record KeyedExerciseBlueprint : IEquatable<KeyedExerciseBlueprint>
{
public static implicit operator KeyedExerciseBlueprint(ExerciseBlueprint e) =>
new(e.Name, e.Sets, e.RepsPerSet);
private readonly string normalizedName = string.Empty;
public string Name { get; }

public KeyedExerciseBlueprint(string name)
{
Name = name;
normalizedName = NormalizeName(name);
}

public static implicit operator KeyedExerciseBlueprint(ExerciseBlueprint e) => new(e.Name);

public bool Equals(KeyedExerciseBlueprint? other) => other?.normalizedName == normalizedName;

public override int GetHashCode() => normalizedName.GetHashCode();

private static string NormalizeName(string name)
{
var lowerName = name.ToLower().Trim().Replace("flies", "flys").Replace("flyes", "flys");
var withoutPlural = lowerName switch
{
string when lowerName.EndsWith("es") => lowerName[..^2],
string when lowerName.EndsWith('s') => lowerName[..^1],
_ => lowerName,
};

return withoutPlural;
}
}

public record Rest(TimeSpan MinRest, TimeSpan MaxRest, TimeSpan FailureRest)
Expand Down
17 changes: 2 additions & 15 deletions LiftLog.Ui/Store/Stats/StatsEffects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ state.Value.OverallViewSessionName is null
ex
))
)
.GroupBy(x => NormalizeName(x.RecordedExercise.Blueprint.Name))
.GroupBy(x => new KeyedExerciseBlueprint(x.RecordedExercise.Blueprint.Name))
.Select(CreateExerciseStatistic)
.ToImmutableList();
Expand Down Expand Up @@ -103,7 +103,7 @@ state.Value.OverallViewSessionName is null
var exerciseMostTimeSpent = sessions
.SelectMany(x => x.RecordedExercises)
.Where(x => x.LastRecordedSet?.Set is not null)
.GroupBy(x => NormalizeName(x.Blueprint.Name))
.GroupBy(x => new KeyedExerciseBlueprint(x.Blueprint.Name))
.Select(x => new TimeSpentExercise(
x.First().Blueprint.Name,
x.Select(x => x.TimeSpent).Aggregate((a, b) => a + b)
Expand Down Expand Up @@ -134,19 +134,6 @@ state.Value.OverallViewSessionName is null
});
}

private static string NormalizeName(string name)
{
var lowerName = name.ToLower().Trim().Replace("flies", "flys").Replace("flyes", "flys");
var withoutPlural = lowerName switch
{
string when lowerName.EndsWith("es") => lowerName[..^2],
string when lowerName.EndsWith('s') => lowerName[..^1],
_ => lowerName,
};

return withoutPlural;
}

private static StatisticOverTime CreateBodyweightStatistic(IEnumerable<Session> sessions)
{
return new(
Expand Down

0 comments on commit 7527026

Please sign in to comment.