Skip to content

Commit

Permalink
[564] feature: use custom workout title prefix (#579)
Browse files Browse the repository at this point in the history
* [564] feature: use custom workout title prefix

* update release notes
  • Loading branch information
philosowaffle authored Dec 29, 2023
1 parent da5bc2c commit d7b08aa
Show file tree
Hide file tree
Showing 37 changed files with 250 additions and 190 deletions.
4 changes: 3 additions & 1 deletion mkdocs/docs/configuration/json.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ This section provides settings related to conversions and what formats should be
},
"Strength": {
"DefaultSecondsPerRep": 3
}
},
"WorkoutTitlePrefix": "Peloton - "
}
```

Expand All @@ -131,6 +132,7 @@ This section provides settings related to conversions and what formats should be
| Rowing.PreferredLapType | no | `Default` | `Conversion Tab` | The preferred [lap type to use](#lap-types). |
| Strength | no | `null` | `Conversion Tab` | Configuration specific to Strength workouts. |
| Strength.DefaultSecondsPerRep | no | `3` | `Conversion Tab` | For exercises that are done for time instead of reps, P2G can estimate how many reps you completed using this value. Ex. If `DefaultSecondsPerRep=3` and you do Curls for 15s, P2G will estimate you completed 5 reps. |
| WorkoutTitlePrefix | no | `null` | `Conversion Tab` | A Title Prefix to apply to all workouts. By default applies no prefix. |

### Understanding Custom Zones

Expand Down
8 changes: 4 additions & 4 deletions src/Api.Contract/SettingsContracts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ public static SettingsPelotonPostRequest Map(this SettingsPelotonGetResponse res
};
}

public static Peloton Map(this SettingsPelotonPostRequest request)
public static PelotonSettings Map(this SettingsPelotonPostRequest request)
{
return new Peloton()
return new ()
{
Email = request.Email,
Password = request.Password,
Expand All @@ -121,9 +121,9 @@ public static SettingsGarminPostRequest Map(this SettingsGarminGetResponse respo
};
}

public static Garmin Map(this SettingsGarminPostRequest request)
public static GarminSettings Map(this SettingsGarminPostRequest request)
{
return new Garmin()
return new ()
{
Email = request.Email,
Password = request.Password,
Expand Down
1 change: 1 addition & 0 deletions src/Api.Service/Validators/SyncValidators.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Api.Contract;
using Api.Service.Helpers;
using Common;
using Common.Dto;
using Common.Stateful;
using Microsoft.AspNetCore.Mvc;

Expand Down
1 change: 1 addition & 0 deletions src/Api/Controllers/SettingsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Api.Service;
using Api.Service.Helpers;
using Common;
using Common.Dto;
using Common.Service;
using Microsoft.AspNetCore.Mvc;

Expand Down
1 change: 1 addition & 0 deletions src/Api/Services/BackgroundSyncJob.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Common;
using Common.Database;
using Common.Dto;
using Common.Observe;
using Common.Service;
using Common.Stateful;
Expand Down
2 changes: 1 addition & 1 deletion src/ClientUI/ServiceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public async Task<SettingsGetResponse> SettingsGetAsync()
}
}

public async Task<Common.App> SettingsAppPostAsync(Common.App appSettings)
public async Task<Common.Dto.App> SettingsAppPostAsync(Common.Dto.App appSettings)
{
try
{
Expand Down
139 changes: 2 additions & 137 deletions src/Common/Configuration.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using Common.Dto;
using Common.Stateful;
using Microsoft.Extensions.Configuration;
using System.Collections.Generic;
using System.IO;

namespace Common;

Expand All @@ -12,8 +9,8 @@ public static void LoadConfigValues(IConfiguration provider, Settings config)
{
provider.GetSection(nameof(App)).Bind(config.App);
provider.GetSection(nameof(Format)).Bind(config.Format);
provider.GetSection(nameof(Peloton)).Bind(config.Peloton);
provider.GetSection(nameof(Garmin)).Bind(config.Garmin);
provider.GetSection(nameof(PelotonSettings)).Bind(config.Peloton);
provider.GetSection(nameof(GarminSettings)).Bind(config.Garmin);
}

public static void LoadConfigValues(IConfiguration provider, AppConfiguration config)
Expand Down Expand Up @@ -44,131 +41,6 @@ public AppConfiguration()
public Developer Developer { get; set; }
}

/// <summary>
/// Settings that can be looked up after app start, changed on demand, and saved to the SettingsDb.
/// </summary>
public class Settings
{
public Settings()
{
App = new App();
Format = new Format();
Peloton = new Peloton();
Garmin = new Garmin();
}

public App App { get; set; }
public Format Format { get; set; }
public Peloton Peloton { get; set; }
public Garmin Garmin { get; set; }
}

public class App
{
public App()
{
CheckForUpdates = true;
EnablePolling = false;
PollingIntervalSeconds = 86400; // 1 day
}

public bool EnablePolling { get; set; }
public int PollingIntervalSeconds { get; set; }
public bool CheckForUpdates { get; set; }

public static string DataDirectory => Path.GetFullPath(Path.Join(Statics.DefaultDataDirectory, "data"));

public string WorkingDirectory => Statics.DefaultTempDirectory;
public string OutputDirectory => Statics.DefaultOutputDirectory;
public string FailedDirectory => Path.GetFullPath(Path.Join(OutputDirectory, "failed"));
public string DownloadDirectory => Path.GetFullPath(Path.Join(WorkingDirectory, "downloaded"));
public string UploadDirectory => Path.GetFullPath(Path.Join(WorkingDirectory, "upload"));


}

public class Format
{
public Format()
{
Cycling = new Cycling();
Running = new Running();
Rowing = new Rowing();
Strength= new Strength();
}

public bool Fit { get; set; }
public bool Json { get; set; }
public bool Tcx { get; set; }
public bool SaveLocalCopy { get; set; }
public bool IncludeTimeInHRZones { get; set; }
public bool IncludeTimeInPowerZones { get; set; }
public string DeviceInfoPath { get; set; }
public Cycling Cycling { get; set; }
public Running Running { get; set; }
public Rowing Rowing { get; init; }
public Strength Strength { get; init; }
}

public record Cycling
{
public PreferredLapType PreferredLapType { get; set; }
}

public record Running
{
public PreferredLapType PreferredLapType { get; set; }
}

public record Rowing
{
public PreferredLapType PreferredLapType { get; set; }
}

public record Strength
{
/// <summary>
/// When no Rep information is provided by Peloton, P2G will calculate number
/// of reps based on this default value. Example, if your DefaultNumSecondsPerRep is 3,
/// and the Exercise duration was 15 seconds, then P2G would credit you with 5 reps for that
/// exercise.
/// </summary>
public int DefaultSecondsPerRep { get; set; } = 3;
}

public enum PreferredLapType
{
Default = 0,
Distance = 1,
Class_Segments = 2,
Class_Targets = 3
}

public class Peloton : ICredentials
{
public Peloton()
{
ExcludeWorkoutTypes = new List<WorkoutType>();
NumWorkoutsToDownload = 5;
}

public EncryptionVersion EncryptionVersion { get; set; }
public string Email { get; set; }
public string Password { get; set; }
public int NumWorkoutsToDownload { get; set; }
public ICollection<WorkoutType> ExcludeWorkoutTypes { get; set; }
}

public class Garmin : ICredentials
{
public EncryptionVersion EncryptionVersion { get; set; }
public string Email { get; set; }
public string Password { get; set; }
public bool TwoStepVerificationEnabled { get; set; }
public bool Upload { get; set; }
public FileFormat FormatToUpload { get; set; }
}

public class ApiSettings
{
public ApiSettings()
Expand Down Expand Up @@ -219,13 +91,6 @@ public class Developer
public string UserAgent { get; set; }
}

public enum FileFormat : byte
{
Fit = 0,
Tcx = 1,
Json = 2
}

public enum EncryptionVersion : byte
{
None = 0,
Expand Down
2 changes: 1 addition & 1 deletion src/Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ public static class Constants
public const string WebUIName = "p2g_webui";
public const string ClientUIName = "p2g_clientui";

public const string AppVersion = "4.0.0";
public const string AppVersion = "4.1.0";
}
}
3 changes: 2 additions & 1 deletion src/Common/Database/DbBase.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Common.Observe;
using Common.Dto;
using Common.Observe;
using JsonFlatFileDataStore;
using Serilog;
using System;
Expand Down
4 changes: 2 additions & 2 deletions src/Common/Database/SettingsDb.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using Common.Helpers;
using Common.Dto;
using Common.Helpers;
using Common.Observe;
using JsonFlatFileDataStore;
using Prometheus;
using Serilog;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

namespace Common.Database
Expand Down
Loading

0 comments on commit d7b08aa

Please sign in to comment.