From 22cf127a07117984afbd885b46fca702c911cb13 Mon Sep 17 00:00:00 2001 From: Bailey Date: Thu, 2 Jan 2025 10:16:10 -0600 Subject: [PATCH] convert to meters --- src/Conversion/FitConverter.cs | 8 ++++---- src/UnitTests/AdHocTests.cs | 22 +++++++++++++++++----- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/Conversion/FitConverter.cs b/src/Conversion/FitConverter.cs index b9397bedf..785d60bbe 100644 --- a/src/Conversion/FitConverter.cs +++ b/src/Conversion/FitConverter.cs @@ -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); } } diff --git a/src/UnitTests/AdHocTests.cs b/src/UnitTests/AdHocTests.cs index 1dc5a0256..f160048ef 100644 --- a/src/UnitTests/AdHocTests.cs +++ b/src/UnitTests/AdHocTests.cs @@ -1,5 +1,6 @@ using Common; using Common.Dto; +using Common.Dto.Garmin; using Common.Dto.Peloton; using Common.Helpers; using Common.Http; @@ -26,6 +27,7 @@ using System.Security.Cryptography; using System.Text.Json; using System.Threading.Tasks; +using PelotonApiClient = Peloton.ApiClient; namespace UnitTests { @@ -115,7 +117,7 @@ public void Setup() // var email = ""; // var password = ""; - // var workoutId = "631fe107823048708d4c9f18a2888c6e"; + // var workoutId = "98c617d5c56f4f1ab6fc250afc9aea5f"; // var settings = new Settings() // { @@ -127,16 +129,26 @@ public void Setup() // }; // var autoMocker = new AutoMocker(); - // var settingMock = autoMocker.GetMock(); - // settingMock.Setup(s => s.GetSettingsAsync()).ReturnsAsync(settings); + // var settingsService = autoMocker.GetMock(); + // settingsService.Setup(s => s.GetSettingsAsync()).ReturnsAsync(settings); + // settingsService.Setup(s => s.GetCustomDeviceInfoAsync(It.IsAny())).ReturnsAsync(GarminDevices.EpixDevice); // var fileHandler = autoMocker.GetMock(); - // 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]