Skip to content

Commit

Permalink
Show per set weights as chip like things in summaries / stats
Browse files Browse the repository at this point in the history
  • Loading branch information
LiamMorrow committed Aug 8, 2024
1 parent b189f99 commit 53abc44
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 17 deletions.
12 changes: 9 additions & 3 deletions LiftLog.Lib/Models/SessionModels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,23 +110,29 @@ bool PerSetWeight
PotentialSets.All(x => x.Set is not null && x.Set.RepsCompleted >= Blueprint.RepsPerSet)
&& PotentialSets.Any(x => x.Weight >= Weight);

[NotNullIfNotNull("FirstRecordedSet")]
[NotNullIfNotNull(nameof(FirstRecordedSet))]
public PotentialSet? LastRecordedSet =>
PotentialSets
.OrderByDescending(x => x.Set?.CompletionTime)
.FirstOrDefault(x => x.Set is not null);

[NotNullIfNotNull("LastRecordedSet")]
[NotNullIfNotNull(nameof(LastRecordedSet))]
public PotentialSet? FirstRecordedSet =>
PotentialSets.OrderBy(x => x.Set?.CompletionTime).FirstOrDefault(x => x.Set is not null);

public TimeSpan TimeSpent =>
LastRecordedSet?.Set?.CompletionTime - FirstRecordedSet?.Set?.CompletionTime
?? TimeSpan.Zero;

public decimal OneRepMax => Math.Floor(Weight / (1.0278m - (0.0278m * Blueprint.RepsPerSet)));
public decimal OneRepMax =>
Math.Floor(MaxWeightLifted / (1.0278m - (0.0278m * Blueprint.RepsPerSet)));

public bool HasRemainingSets => PotentialSets.Any(x => x.Set is null);

public decimal MaxWeightLifted =>
PerSetWeight
? PotentialSets.Where(x => x.Set is not null).Select(x => x.Weight).Append(Weight).Max()
: Weight;
}

public record RecordedSet(int RepsCompleted, TimeOnly CompletionTime);
Expand Down
34 changes: 29 additions & 5 deletions LiftLog.Ui/Shared/Presentation/SessionSummary.razor
Original file line number Diff line number Diff line change
@@ -1,17 +1,39 @@

<div class="grid @GridRows gap-x-4 text-start" data-cy="session-summary">
<div class="grid @GridRows gap-x-4 gap-y-0.5 text-start" data-cy="session-summary">
@foreach (var exercise in Session.RecordedExercises)
{
var splitWeights = exercise.PerSetWeight && !exercise.PotentialSets.All(s => s.Weight == exercise.Weight);
<span>@exercise.Blueprint.Name</span>
@if (ShowSets)
@if (ShowSets && !splitWeights)
{
<span class="flex items-center">@(exercise.Blueprint.Sets)x@(exercise.Blueprint.RepsPerSet) </span>
<span class="flex items-center justify-end">
<span class="@ChipClass">
@(exercise.Blueprint.Sets)x@(exercise.Blueprint.RepsPerSet)
</span>
</span>
}

@if (ShowWeight)
@if (ShowWeight && !splitWeights)
{
<span class="flex justify-end">
<WeightFormat Weight="@exercise.Weight"/>
<span class="@ChipClass">
<WeightFormat Weight="@exercise.Weight"/>
</span>
</span>
}

@if (ShowWeight && splitWeights)
{
<span class="flex justify-end gap-1 items-center col-span-2">
@foreach(var set in exercise.PotentialSets)
{
<span class="flex gap-0.5 @ChipClass">
@if (ShowSets){
<span>@(set.Set?.RepsCompleted ?? exercise.Blueprint.RepsPerSet)</span><span>x</span>
}
<WeightFormat Weight="@set.Weight"/>
</span>
}
</span>
}
}
Expand All @@ -25,6 +47,8 @@
[Parameter] public bool ShowWeight { get; set; } = true;
private string ChipClass => "bg-surface-container-highest text-on-surface-variant rounded-md py-0.5 px-1";

private string GridRows => (ShowSets, ShowWeight) switch
{
(true, true) => "grid-cols-[1fr,max-content,max-content]",
Expand Down
17 changes: 8 additions & 9 deletions LiftLog.Ui/Store/Stats/StatsEffects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,26 +79,25 @@ state.Value.OverallViewSessionName is null
var averageTimeBetweenSets = sessions
.SelectMany(x => x.RecordedExercises)
.Select(x =>
.SelectMany(x =>
x.PotentialSets.Select(set => set.Set?.CompletionTime.ToTimeSpan())
.WhereNotNull()
.Order()
.Pairwise((a, b) => b - a)
)
.SelectMany(x => x)
.Aggregate(
(TimeSpan.Zero, 0),
(acc, x) => (acc.Item1 + x, acc.Item2 + 1),
acc => acc.Item2 != 0 ? acc.Item1 / acc.Item2 : TimeSpan.Zero
(TimeSpan.Zero, RunningAvg: 0),
(acc, x) => (acc.Zero + x, acc.RunningAvg + 1),
acc => acc.RunningAvg != 0 ? acc.Zero / acc.RunningAvg : TimeSpan.Zero
);
var averageSessionLength = sessions
.Select(session => session.SessionLength)
.WhereNotNull()
.Aggregate(
(TimeSpan.Zero, 0),
(acc, x) => (acc.Item1 + x, acc.Item2 + 1),
acc => acc.Item2 != 0 ? acc.Item1 / acc.Item2 : TimeSpan.Zero
(acc, x) => (acc.Zero + x, acc.Item2 + 1),
acc => acc.Item2 != 0 ? acc.Zero / acc.Item2 : TimeSpan.Zero
);
var exerciseMostTimeSpent = sessions
Expand All @@ -114,7 +113,7 @@ state.Value.OverallViewSessionName is null
var heaviestLift = sessions
.SelectMany(x => x.RecordedExercises)
.Where(x => x.FirstRecordedSet is not null)
.MaxBy(x => x.Weight);
.MaxBy(x => x.MaxWeightLifted);
dispatcher.Dispatch(
new SetOverallStatsAction(
Expand Down Expand Up @@ -186,7 +185,7 @@ IGrouping<T, DatedRecordedExercise> exercises
exercises
.Select(exercise => new TimeTrackedStatistic(
exercise.DateTime,
exercise.RecordedExercise.Weight
exercise.RecordedExercise.MaxWeightLifted
))
.ToImmutableList()
),
Expand Down

0 comments on commit 53abc44

Please sign in to comment.