Skip to content

Commit

Permalink
Show bodyweight stats even when there are no exercises
Browse files Browse the repository at this point in the history
  • Loading branch information
LiamMorrow committed Oct 6, 2024
1 parent b3c5a32 commit fa517a3
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions LiftLog.Ui/Store/Stats/StatsEffects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,22 @@ state.Value.OverallViewSessionName is null
&& currentSessionNames.Contains(session.Blueprint.Name)
)
)
.Where(x => x.RecordedExercises.Any())
.ToListAsync();
var sessionsWithExercises = sessions.Where(x => x.RecordedExercises.Any()).ToList();
if (sessions.Count == 0)
{
dispatcher.Dispatch(new SetStatsIsLoadingAction(false));
dispatcher.Dispatch(new SetOverallStatsAction(null));
return;
}

var bodyweightStats = CreateBodyweightStatistic(sessions);
var sessionStats = sessions
var sessionStats = sessionsWithExercises
.GroupBy(session => session.Blueprint.Name)
.Select(CreateSessionStatistic)
.ToImmutableList();

var exerciseStats = sessions
var exerciseStats = sessionsWithExercises
.SelectMany(x =>
x.RecordedExercises.Where(y => y.LastRecordedSet?.Set is not null)
.Select(ex => new DatedRecordedExercise(
Expand All @@ -81,7 +82,7 @@ state.Value.OverallViewSessionName is null
.Select(CreateExerciseStatistic)
.ToImmutableList();

var averageTimeBetweenSets = sessions
var averageTimeBetweenSets = sessionsWithExercises
.SelectMany(x => x.RecordedExercises)
.SelectMany(x =>
x.PotentialSets.Select(set => set.Set?.CompletionTime.ToTimeSpan())
Expand All @@ -95,7 +96,7 @@ state.Value.OverallViewSessionName is null
acc => acc.RunningAvg != 0 ? acc.Zero / acc.RunningAvg : TimeSpan.Zero
);

var averageSessionLength = sessions
var averageSessionLength = sessionsWithExercises
.Select(session => session.SessionLength)
.WhereNotNull()
.Aggregate(
Expand All @@ -104,7 +105,7 @@ state.Value.OverallViewSessionName is null
acc => acc.Item2 != 0 ? acc.Zero / acc.Item2 : TimeSpan.Zero
);

var exerciseMostTimeSpent = sessions
var exerciseMostTimeSpent = sessionsWithExercises
.SelectMany(x => x.RecordedExercises)
.Where(x => x.LastRecordedSet?.Set is not null)
.GroupBy(x => new KeyedExerciseBlueprint(x.Blueprint.Name))
Expand All @@ -114,7 +115,7 @@ state.Value.OverallViewSessionName is null
))
.MaxBy(x => x.TimeSpent);

var heaviestLift = sessions
var heaviestLift = sessionsWithExercises
.SelectMany(x => x.RecordedExercises)
.Where(x => x.FirstRecordedSet is not null)
.MaxBy(x => x.MaxWeightLifted);
Expand Down

0 comments on commit fa517a3

Please sign in to comment.