Skip to content

Commit

Permalink
Merge pull request #284 from LiamMorrow/fix-dates
Browse files Browse the repository at this point in the history
  • Loading branch information
LiamMorrow authored Oct 6, 2024
2 parents 323491e + fa517a3 commit 3c667c4
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 16 deletions.
5 changes: 4 additions & 1 deletion LiftLog.Maui/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ protected override Window CreateWindow(IActivationState? activationState)
if (session?.LastExercise?.LastRecordedSet?.Set is not null)
{
var lastSet = session.LastExercise.LastRecordedSet.Set;
var lastSetTime = session.Date.ToDateTime(lastSet.CompletionTime);
var lastSetTime = session.Date.ToDateTime(
lastSet.CompletionTime,
DateTimeKind.Local
);
var timeSinceLastSet = DateTime.Now - lastSetTime;
if (
(timeSinceLastSet > TimeSpan.FromMinutes(30) && session.IsComplete)
Expand Down
5 changes: 4 additions & 1 deletion LiftLog.Ui/Models/SessionHistoryDao/SessionHistoryDaoV1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ Lib.Models.PotentialSet model
),
{ Set: { } } completed => new RecordedSetDaoV1(
RepsCompleted: model.Set.RepsCompleted,
CompletionTime: sessionDate.ToDateTime(completed.Set.CompletionTime),
CompletionTime: sessionDate.ToDateTime(
completed.Set.CompletionTime,
DateTimeKind.Local
),
Weight: completed.Weight
),
_ => null,
Expand Down
5 changes: 4 additions & 1 deletion LiftLog.Ui/Services/ProgressRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,10 @@ public ValueTask<
.SelectMany(x =>
x.RecordedExercises.Where(x => x.LastRecordedSet?.Set is not null)
.Select(ex => new DatedRecordedExercise(
x.Date.ToDateTime(ex.LastRecordedSet!.Set!.CompletionTime),
x.Date.ToDateTime(
ex.LastRecordedSet!.Set!.CompletionTime,
DateTimeKind.Local
),
ex
))
.ToAsyncEnumerable()
Expand Down
3 changes: 2 additions & 1 deletion LiftLog.Ui/Shared/Presentation/StatGraphCardContent.razor
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ else
Style = new()
{
Colors = new Color(GetColorString(AppState.Value.ColorScheme.OnSurface)),
}
},
DatetimeUTC = false,
},
AxisBorder = new()
{
Expand Down
5 changes: 4 additions & 1 deletion LiftLog.Ui/Store/Feed/FeedEffects.FeedItems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ await Task.WhenAll(
.Select(x => x.OrderByDescending(x => x.Timestamp).First())
.OrderByDescending(x =>
x is SessionFeedItem sessionFeedItem
? sessionFeedItem.Session.Date.ToDateTime(TimeOnly.MinValue)
? sessionFeedItem.Session.Date.ToDateTime(
TimeOnly.MinValue,
DateTimeKind.Local
)
: x.Timestamp
)
.ThenByDescending(x => x.Timestamp)
Expand Down
27 changes: 16 additions & 11 deletions LiftLog.Ui/Store/Stats/StatsEffects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public async Task HandleFetchStats(FetchOverallStatsAction _, IDispatcher dispat

var latestTime = DateOnly.FromDateTime(DateTime.Now);
var earliestTime = DateOnly.FromDateTime(
latestTime.ToDateTime(TimeOnly.MinValue) - state.Value.OverallViewTime
latestTime.ToDateTime(TimeOnly.MinValue, DateTimeKind.Local)
- state.Value.OverallViewTime
);

var filteringToCurrentSessions = "CURRENT_SESSIONS".Equals(
Expand All @@ -51,33 +52,37 @@ 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(
x.Date.ToDateTime(ex.LastRecordedSet!.Set!.CompletionTime),
x.Date.ToDateTime(
ex.LastRecordedSet!.Set!.CompletionTime,
DateTimeKind.Local
),
ex
))
)
.GroupBy(x => new KeyedExerciseBlueprint(x.RecordedExercise.Blueprint.Name))
.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 @@ -91,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 @@ -100,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 @@ -110,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 Expand Up @@ -141,7 +146,7 @@ private static StatisticOverTime CreateBodyweightStatistic(IEnumerable<Session>
sessions
.Where(x => x.Bodyweight is not null)
.Select(session => new TimeTrackedStatistic(
session.Date.ToDateTime(TimeOnly.MinValue),
session.Date.ToDateTime(TimeOnly.MinValue, DateTimeKind.Local),
session.Bodyweight!.Value
))
.ToImmutableList()
Expand All @@ -154,7 +159,7 @@ private static StatisticOverTime CreateSessionStatistic(IGrouping<string, Sessio
sessions.Key,
sessions
.Select(session => new TimeTrackedStatistic(
session.Date.ToDateTime(TimeOnly.MinValue),
session.Date.ToDateTime(TimeOnly.MinValue, DateTimeKind.Local),
session.TotalWeightLifted
))
.ToImmutableList()
Expand Down

0 comments on commit 3c667c4

Please sign in to comment.