Skip to content

Commit

Permalink
convert to meters
Browse files Browse the repository at this point in the history
  • Loading branch information
philosowaffle committed Jan 2, 2025
1 parent a175b96 commit 22cf127
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/Conversion/FitConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -375,15 +375,15 @@ private SessionMesg GetSessionMesg(Workout workout, WorkoutSamples workoutSample
sessionMesg.SetMaxPosGrade(GetMaxGrade(workoutSamples));
sessionMesg.SetMaxNegGrade(0.0f);

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

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

0 comments on commit 22cf127

Please sign in to comment.