Skip to content

Commit

Permalink
[610] feat: add more workout details to Sync page (#611)
Browse files Browse the repository at this point in the history
  • Loading branch information
philosowaffle authored Jan 13, 2024
1 parent 3420165 commit 63495c6
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 12 deletions.
8 changes: 6 additions & 2 deletions src/Api.Contract/PelotonWorkoutsRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,21 @@ public PelotonWorkout(Workout workout)
{
Id = workout.Id;
Status = workout.Status;
ClassTypeTitle = workout.Title;
PelotonFitnessDiscipline = workout.Fitness_Discipline.ToString();
IsOutdoor = workout.Is_Outdoor;
WorkoutTitle = workout.Ride?.Title;
InstructorName = workout.Ride?.Instructor?.Name;
Name = workout.Name;
CreatedAt = workout.Created_At;
ImageUrl = workout.Ride?.Image_Url;
}

public string? Id { get; init; }
public string? Status { get; init; }
public string? ClassTypeTitle { get; init; }
public string? PelotonFitnessDiscipline { get; init; }
public bool IsOutdoor { get; init; }
public string? WorkoutTitle { get; init; }
public string? InstructorName { get; init; }
public string? Name { get; init; }
public long CreatedAt { get; init; }
public Uri? ImageUrl { get; set; }
Expand Down
21 changes: 13 additions & 8 deletions src/Conversion/IConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -565,17 +565,22 @@ protected static Metric GetMetric(string slug, WorkoutSamples workoutSamples)

protected async Task<GarminDeviceInfo> GetDeviceInfoAsync(FitnessDiscipline sport, Settings settings)
{
GarminDeviceInfo userProvidedDeviceInfo = await _settingsService.GetCustomDeviceInfoAsync(settings.Garmin.Email);
GarminDeviceInfo deviceInfo = null;
deviceInfo = await _settingsService.GetCustomDeviceInfoAsync(settings.Garmin.Email);

if (userProvidedDeviceInfo is object) return userProvidedDeviceInfo;

if(sport == FitnessDiscipline.Cycling)
return CyclingDevice;
if (deviceInfo is null)
{
if (sport == FitnessDiscipline.Cycling)
deviceInfo = CyclingDevice;
else if (sport == FitnessDiscipline.Caesar)
deviceInfo = RowingDevice;
else
deviceInfo = DefaultDevice;
}

if (sport == FitnessDiscipline.Caesar)
return RowingDevice;
_logger.Debug("Using device: {@DeviceName}, {@DeviceProdId}, {@DeviceManufacturerId}, {@DeviceVersion}", deviceInfo.Name, deviceInfo.ProductID, deviceInfo.ManufacturerId, deviceInfo.Version);

return DefaultDevice;
return deviceInfo;
}

protected ushort? GetCyclingFtp(Workout workout, UserData userData)
Expand Down
2 changes: 1 addition & 1 deletion src/Peloton/ApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public async Task<PagedPelotonResponse<Workout>> GetWorkoutsAsync(int pageSize,
limit = pageSize,
sort_by = "-created",
page = page,
joins= "ride"
joins= "ride,ride.instructor"
})
.StripSensitiveDataFromLogging(auth.Email, auth.Password)
.GetJsonAsync<PagedPelotonResponse<Workout>>();
Expand Down
4 changes: 3 additions & 1 deletion src/SharedUI/Pages/Sync.razor
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
<Columns>
<HxGridColumn TItem="PelotonWorkout" HeaderText="Date" ItemTextSelector="@(item => DateTimeOffset.FromUnixTimeSeconds(item.CreatedAt).LocalDateTime.ToString())" />
<HxGridColumn TItem="PelotonWorkout" HeaderText="Title" ItemTextSelector="@(item => item.WorkoutTitle ?? item.Name)" />
<HxGridColumn TItem="PelotonWorkout" HeaderText="Status" ItemTextSelector="@(item => item.Status)" />
<HxGridColumn TItem="PelotonWorkout" HeaderText="Instructor" ItemTextSelector="@(item => item.InstructorName)" />
<HxGridColumn TItem="PelotonWorkout" HeaderText="Workout Type" ItemTextSelector="@(item => item.PelotonFitnessDiscipline)" />
<HxGridColumn TItem="PelotonWorkout" HeaderText="Is Outdoor?" ItemTextSelector="@(item => item.IsOutdoor.ToString())" />
</Columns>
</HxGrid>

Expand Down
12 changes: 12 additions & 0 deletions src/SharedUI/Shared/AppSettingsForm.razor
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
<HxCard>
<HeaderTemplate>
<HxSwitch Text="Automatic Syncing" @bind-Value="appSettings.EnablePolling" Inline="true" />
<HxPopover Trigger="PopoverTrigger.Hover|PopoverTrigger.Click|PopoverTrigger.Focus"
Title="<b>Automatic Syncing</b>"
Content="@AutomaticSyncingDocumentation"
Html="true">
<HxBadge Type="BadgeType.RoundedPill" Color="ThemeColor.Info">?</HxBadge>
</HxPopover>
</HeaderTemplate>
<BodyTemplate>
<HxFormState Enabled="@appSettings.EnablePolling">
Expand All @@ -26,6 +32,7 @@

@code {
private App appSettings;
private string configDocumentation;

public AppSettingsForm()

Check warning on line 37 in src/SharedUI/Shared/AppSettingsForm.razor

View workflow job for this annotation

GitHub Actions / Publish UI Distribution (7.0.400, net7.0-windows10.0.22621.0, win10-x64)

Non-nullable field 'configDocumentation' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.
{
Expand All @@ -45,6 +52,9 @@
var settings = await _apiClient.SettingsGetAsync();

appSettings = settings.App;

var systemInfo = await _apiClient.SystemInfoGetAsync(new SystemInfoGetRequest() { CheckForUpdate = settings.App.CheckForUpdates });
configDocumentation = systemInfo.Documentation + "/configuration/json/#app-config";
}

protected async Task SaveAppSettings()
Expand All @@ -69,4 +79,6 @@
Log.Error("UI - Failed to save App settings.", e);
}
}

private string AutomaticSyncingDocumentation => $"P2G can periodically and automatically sync workouts. By enabling this setting, P2G will check for workouts every X seconds and sync them. The number of workouts that P2G will fetch per sync can be configured on the <b>Peloton Settings</b> tab.<br /><br /><b>WARNING:</b> Setting this to a frequency of hourly or less may get you flagged by Peloton as a bad actor and they may reset your password. The default is set to Daily.<br /><br /><a href='{configDocumentation}'>Documentation</a><br ?><small>(click the <b>?</b> to pin this window)</small>";
}
1 change: 1 addition & 0 deletions vNextReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

## Features

- [#610] UI - Add more workout data to Sync page

## Fixes

Expand Down

0 comments on commit 63495c6

Please sign in to comment.