Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include exercises with different reps in previous history #280

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading