-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #182 from LiamMorrow/auto-screenshots
- Loading branch information
Showing
41 changed files
with
717 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#if DEBUG | ||
using LiftLog.Ui.Pages.Screenshot; | ||
|
||
namespace LiftLog.App.Services; | ||
|
||
public class AppScreenshotStatsImportsProvider : IScreenshotStatsImportsProvider | ||
{ | ||
public async Task<Stream> GetImportBytesAsync() | ||
{ | ||
var result = await FileSystem.OpenAppPackageFileAsync( | ||
"wwwroot/_content/LiftLog.Ui/export.liftlogbackup.gz" | ||
); | ||
return result; | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#if DEBUG | ||
using LiftLog.Lib.Models; | ||
using LiftLog.Ui.Store.App; | ||
using LiftLog.Ui.Store.CurrentSession; | ||
|
||
namespace LiftLog.Ui.Pages.Screenshot; | ||
|
||
public partial class ScreenshotCollectorPage | ||
{ | ||
private async Task HandleAiPageScreenshotCollection() | ||
{ | ||
Dispatcher.Dispatch(new NavigateAction("/settings/ai-planner")); | ||
await Task.Yield(); | ||
} | ||
} | ||
#endif |
24 changes: 24 additions & 0 deletions
24
LiftLog.Ui/Pages/Screenshot/ScreenshotCollectorPage.ExerciseEditPage.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#if DEBUG | ||
using LiftLog.Lib.Models; | ||
using LiftLog.Ui.Store.App; | ||
using LiftLog.Ui.Store.CurrentSession; | ||
using LiftLog.Ui.Store.Program; | ||
|
||
namespace LiftLog.Ui.Pages.Screenshot; | ||
|
||
public partial class ScreenshotCollectorPage | ||
{ | ||
private async Task HandleExerciseEditorScreenshotCollection() | ||
{ | ||
Dispatcher.Dispatch( | ||
new SetProgramSessionsAction(ProgramState.Value.ActivePlanId, [demoSessionBlueprint]) | ||
); | ||
Dispatcher.Dispatch( | ||
new NavigateAction( | ||
$"/settings/manage-workouts/manage-session/0?editingExercise=0&planId={ProgramState.Value.ActivePlanId}" | ||
) | ||
); | ||
await Task.Yield(); | ||
} | ||
} | ||
#endif |
59 changes: 59 additions & 0 deletions
59
LiftLog.Ui/Pages/Screenshot/ScreenshotCollectorPage.Home.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#if DEBUG | ||
using LiftLog.Lib.Models; | ||
using LiftLog.Ui.Services; | ||
using LiftLog.Ui.Store.App; | ||
using LiftLog.Ui.Store.CurrentSession; | ||
using LiftLog.Ui.Store.Program; | ||
|
||
namespace LiftLog.Ui.Pages.Screenshot; | ||
|
||
public partial class ScreenshotCollectorPage | ||
{ | ||
private SessionBlueprint demoSessionBlueprint = | ||
new( | ||
Name: "Session 1", | ||
Exercises: | ||
[ | ||
new ExerciseBlueprint( | ||
Name: "Squat", | ||
Sets: 3, | ||
RepsPerSet: 10, | ||
WeightIncreaseOnSuccess: 2.5m, | ||
RestBetweenSets: Rest.Medium, | ||
SupersetWithNext: false | ||
), | ||
new ExerciseBlueprint( | ||
Name: "Bench Press", | ||
Sets: 3, | ||
RepsPerSet: 10, | ||
WeightIncreaseOnSuccess: 2.5m, | ||
RestBetweenSets: Rest.Medium, | ||
SupersetWithNext: false | ||
), | ||
new ExerciseBlueprint( | ||
Name: "Deadlift", | ||
Sets: 3, | ||
RepsPerSet: 10, | ||
WeightIncreaseOnSuccess: 2.5m, | ||
RestBetweenSets: Rest.Medium, | ||
SupersetWithNext: false | ||
) | ||
] | ||
); | ||
|
||
private async Task HandleHomeScreenshotCollection() | ||
{ | ||
var builtInProgram = BuiltInProgramService.BuiltInPrograms.First(); | ||
Dispatcher.Dispatch(new SetCurrentSessionAction(SessionTarget.WorkoutSession, null)); | ||
Dispatcher.Dispatch(new SetActiveProgramAction(builtInProgram.Key)); | ||
Dispatcher.Dispatch( | ||
new SetProgramSessionsAction( | ||
ProgramState.Value.ActivePlanId, | ||
builtInProgram.Value.Sessions | ||
) | ||
); | ||
Dispatcher.Dispatch(new NavigateAction($"/")); | ||
await Task.Yield(); | ||
} | ||
} | ||
#endif |
50 changes: 50 additions & 0 deletions
50
LiftLog.Ui/Pages/Screenshot/ScreenshotCollectorPage.Stats.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#if DEBUG | ||
using System.IO.Compression; | ||
using LiftLog.Lib.Models; | ||
using LiftLog.Ui.Store.App; | ||
using LiftLog.Ui.Store.CurrentSession; | ||
using LiftLog.Ui.Store.Settings; | ||
using LiftLog.Ui.Store.Stats; | ||
using Microsoft.AspNetCore.Components; | ||
|
||
namespace LiftLog.Ui.Pages.Screenshot; | ||
|
||
public partial class ScreenshotCollectorPage | ||
{ | ||
[Inject] | ||
public HttpClient HttpClient { get; set; } = null!; | ||
|
||
[Inject] | ||
public IScreenshotStatsImportsProvider ScreenshotStatsImportsProvider { get; set; } = null!; | ||
|
||
private async Task HandleStatsScreenshotCollection() | ||
{ | ||
var imported = await ScreenshotStatsImportsProvider.GetImportBytesAsync(); | ||
using GZipStream gzip = new(imported, CompressionMode.Decompress); | ||
using MemoryStream memoryStream = new(); | ||
await gzip.CopyToAsync(memoryStream); | ||
var bytes = memoryStream.ToArray(); | ||
Dispatcher.Dispatch(new ImportDataBytesAction(bytes)); | ||
var latestSession = await ProgressRepository.GetOrderedSessions().FirstAsync(); | ||
var dateDiffToNow = ( | ||
DateTime.Now - latestSession.Date.ToDateTime(TimeOnly.FromDateTime(DateTime.Now)) | ||
).Days; | ||
|
||
var remappedToTodaySessions = await ProgressRepository | ||
.GetOrderedSessions() | ||
.Select(session => session with { Date = session.Date.AddDays(dateDiffToNow) }) | ||
.ToListAsync(); | ||
|
||
await ProgressRepository.SaveCompletedSessionsAsync(remappedToTodaySessions); | ||
|
||
Dispatcher.Dispatch(new SetPinnedExerciseStatsAction([new("Bench Press")])); | ||
Dispatcher.Dispatch(new SetShowBodyweightAction(false)); | ||
Dispatcher.Dispatch(new NavigateAction("/stats")); | ||
} | ||
} | ||
|
||
public interface IScreenshotStatsImportsProvider | ||
{ | ||
Task<Stream> GetImportBytesAsync(); | ||
} | ||
#endif |
23 changes: 23 additions & 0 deletions
23
LiftLog.Ui/Pages/Screenshot/ScreenshotCollectorPage.WorkoutPage.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#if DEBUG | ||
using LiftLog.Lib.Models; | ||
using LiftLog.Ui.Store.App; | ||
using LiftLog.Ui.Store.CurrentSession; | ||
|
||
namespace LiftLog.Ui.Pages.Screenshot; | ||
|
||
public partial class ScreenshotCollectorPage | ||
{ | ||
private async Task HandleWorkoutPageScreenshotCollection() | ||
{ | ||
var demoSession = demoSessionBlueprint.GetEmptySession(); | ||
Dispatcher.Dispatch(new SetCurrentSessionAction(SessionTarget.WorkoutSession, demoSession)); | ||
Dispatcher.Dispatch(new UpdateExerciseWeightAction(SessionTarget.WorkoutSession, 0, 100)); | ||
Dispatcher.Dispatch(new UpdateExerciseWeightAction(SessionTarget.WorkoutSession, 1, 60)); | ||
Dispatcher.Dispatch(new UpdateExerciseWeightAction(SessionTarget.WorkoutSession, 2, 120)); | ||
Dispatcher.Dispatch(new UpdateBodyweightAction(SessionTarget.WorkoutSession, 85)); | ||
Dispatcher.Dispatch(new CycleExerciseRepsAction(SessionTarget.WorkoutSession, 0, 0)); | ||
Dispatcher.Dispatch(new NavigateAction("/session")); | ||
await Task.Yield(); | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@page "/screenshot-collection" |
61 changes: 61 additions & 0 deletions
61
LiftLog.Ui/Pages/Screenshot/ScreenshotCollectorPage.razor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#if DEBUG | ||
using Fluxor; | ||
using LiftLog.Ui.Services; | ||
using LiftLog.Ui.Store.Program; | ||
using LiftLog.Ui.Store.Settings; | ||
using Microsoft.AspNetCore.Components; | ||
|
||
namespace LiftLog.Ui.Pages.Screenshot; | ||
|
||
public partial class ScreenshotCollectorPage : ComponentBase | ||
{ | ||
[Inject] | ||
public IDispatcher Dispatcher { get; set; } = null!; | ||
|
||
[Inject] | ||
public ProgressRepository ProgressRepository { get; set; } = null!; | ||
|
||
[Inject] | ||
public IState<ProgramState> ProgramState { get; set; } = null!; | ||
|
||
[Parameter] | ||
[SupplyParameterFromQuery(Name = "type")] | ||
public string ScreenshotCollectionType { get; set; } = ""; | ||
|
||
protected override async Task OnInitializedAsync() | ||
{ | ||
await ProgressRepository.ClearAsync(); | ||
Dispatcher.Dispatch(new SetProgramSessionsAction(ProgramState.Value.ActivePlanId, [])); | ||
Dispatcher.Dispatch(new SetUseImperialUnitsAction(false)); | ||
Dispatcher.Dispatch(new SetShowBodyweightAction(true)); | ||
Dispatcher.Dispatch(new SetShowFeedAction(true)); | ||
Dispatcher.Dispatch(new SetShowTipsAction(false)); | ||
Dispatcher.Dispatch( | ||
new SetThemeAction( | ||
uint.Parse("00AA00", System.Globalization.NumberStyles.HexNumber), | ||
ThemePreference.Light | ||
) | ||
); | ||
|
||
switch (ScreenshotCollectionType.ToLower()) | ||
{ | ||
case "workoutpage": | ||
await HandleWorkoutPageScreenshotCollection(); | ||
break; | ||
case "home": | ||
await HandleHomeScreenshotCollection(); | ||
break; | ||
case "exerciseeditor": | ||
await HandleExerciseEditorScreenshotCollection(); | ||
break; | ||
case "stats": | ||
await HandleStatsScreenshotCollection(); | ||
break; | ||
case "ai": | ||
await HandleAiPageScreenshotCollection(); | ||
break; | ||
} | ||
await base.OnInitializedAsync(); | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.