Skip to content

Commit

Permalink
[476] feat: sync tread total ascent/elevation to FIT file (#701)
Browse files Browse the repository at this point in the history
* [476] feat: sync tread total ascent/elevation to FIT file

* convert to meters
  • Loading branch information
philosowaffle authored Jan 2, 2025
1 parent 14fff4b commit 6feda09
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Common/Dto/Peloton/Summary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ public class Summary
public string Display_Name { get; set; }
public string Display_Unit { get; set; }
public double? Value { get; set; }
public string Slug { get; set; } // enum
public string Slug { get; set; } // enum: total_output, distance, elevation, calories
}
}
12 changes: 12 additions & 0 deletions src/Conversion/FitConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,18 @@ private SessionMesg GetSessionMesg(Workout workout, WorkoutSamples workoutSample
sessionMesg.SetMaxPosGrade(GetMaxGrade(workoutSamples));
sessionMesg.SetMaxNegGrade(0.0f);

var totalElevation = workoutSamples.Summaries.FirstOrDefault(s => s.Slug == "elevation");
if (totalElevation?.Value > 0)
{
try
{
sessionMesg.SetTotalAscent((ushort)ConvertDistanceToMeters(totalElevation.Value.GetValueOrDefault(), totalElevation.Display_Unit));
} catch (Exception e)
{
_logger.Warning($"Failed to cast elevation of {totalElevation?.Value} to ushort after converting to meters. Skipping data point.", e);
}
}

if (sport == Sport.Rowing)
{
var strokeCountSummary = workoutSamples.Summaries.FirstOrDefault(m => m.Slug == "stroke_count");
Expand Down
22 changes: 17 additions & 5 deletions src/UnitTests/AdHocTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Common;
using Common.Dto;
using Common.Dto.Garmin;
using Common.Dto.Peloton;
using Common.Helpers;
using Common.Http;
Expand All @@ -26,6 +27,7 @@
using System.Security.Cryptography;
using System.Text.Json;
using System.Threading.Tasks;
using PelotonApiClient = Peloton.ApiClient;

namespace UnitTests
{
Expand Down Expand Up @@ -115,7 +117,7 @@ public void Setup()
// var email = "";
// var password = "";

// var workoutId = "631fe107823048708d4c9f18a2888c6e";
// var workoutId = "98c617d5c56f4f1ab6fc250afc9aea5f";

// var settings = new Settings()
// {
Expand All @@ -127,16 +129,26 @@ public void Setup()
// };

// var autoMocker = new AutoMocker();
// var settingMock = autoMocker.GetMock<ISettingsService>();
// settingMock.Setup(s => s.GetSettingsAsync()).ReturnsAsync(settings);
// var settingsService = autoMocker.GetMock<ISettingsService>();
// settingsService.Setup(s => s.GetSettingsAsync()).ReturnsAsync(settings);
// settingsService.Setup(s => s.GetCustomDeviceInfoAsync(It.IsAny<Workout>())).ReturnsAsync(GarminDevices.EpixDevice);

// var fileHandler = autoMocker.GetMock<IFileHandling>();

// var client = new ApiClient(settingMock.Object);
// var service = new PelotonService(settingMock.Object, client, fileHandler.Object);
// var client = new PelotonApiClient(settingsService.Object);
// var service = new PelotonService(settingsService.Object, client, fileHandler.Object);

// var p2gWorkout = await service.GetWorkoutDetailsAsync(workoutId);
// SaveData(p2gWorkout, workoutId, DataDirectory);

// // CONVERT TO FIT & SAVE
// //var fitConverter = new ConverterInstance(settingsService.Object, new IOWrapper());
// //var file = Path.Join(DataDirectory, $"{workoutId}_workout.json");
// //var messages = await fitConverter.Convert(file, settings);

// //var output = Path.Join(DataDirectory, "output.fit");

// //fitConverter.Save(messages, output);
//}

//[Test]
Expand Down
1 change: 1 addition & 0 deletions vNextReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
## Features

- [#698] If using docker, you can now mount the config directory instead of the config file itself. Additionally, the location of the config directory can be overriddien via environment variable: `P2G_CONFIG_DIRECTORY`.
- [#476] Tread - Sync Total Ascent/Elevation to FIT file.

## Docker Tags

Expand Down

0 comments on commit 6feda09

Please sign in to comment.