-
-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[453] strength - handle cases where some exercises are missed from th…
…e class plan (#459) * [453] strength - handle cases where some exercises are missed from the class plan * [453] polish
- Loading branch information
1 parent
487b288
commit abb1e57
Showing
8 changed files
with
170 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
using Common.Dto.Peloton; | ||
using Common.Dto; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Peloton; | ||
|
||
public static class P2GWorkoutExerciseMapper | ||
{ | ||
public static ICollection<P2GExercise> GetWorkoutExercises(Workout workout, RideSegments rideSegments) | ||
{ | ||
var exercises = GetExercisesTrackedByMovementTracker(workout); | ||
|
||
var segments = rideSegments?.Segments?.Segment_List; | ||
if (segments is null || segments.Count <= 0) return exercises; | ||
|
||
foreach (var segment in segments) | ||
{ | ||
if (segment?.SubSegments_V2 is null || segment.SubSegments_V2.Count <= 0) continue; | ||
|
||
foreach (var subSegment in segment.SubSegments_V2) | ||
{ | ||
if (subSegment?.Movements is null || subSegment.Movements.Count <= 0) continue; | ||
|
||
foreach (var movement in subSegment.Movements) | ||
{ | ||
if (movement is null) continue; | ||
|
||
if (exercises.Any(e => e.StartOffsetSeconds == subSegment.Offset && e.Id == movement.Id)) | ||
continue; // we likely already have this movement accounted for from the TrackedMovements | ||
|
||
var exercise = new P2GExercise() | ||
{ | ||
Id = movement.Id, | ||
Name = movement.Name, | ||
Type = MovementTargetType.Time, | ||
StartOffsetSeconds = subSegment.Offset.GetValueOrDefault(), | ||
DurationSeconds = subSegment.Length.GetValueOrDefault() / subSegment.Movements.Count, // if this is a group of movements, divide up the time per movement | ||
Reps = subSegment.Rounds | ||
}; | ||
exercises.Add(exercise); | ||
} | ||
} | ||
} | ||
|
||
var sorted = exercises.OrderBy(e => e.StartOffsetSeconds).ToList(); | ||
return sorted; | ||
} | ||
|
||
public static ICollection<P2GExercise> GetExercisesTrackedByMovementTracker(Workout workout) | ||
{ | ||
var movements = new List<P2GExercise>(); | ||
|
||
var trackedRepData = workout?.Movement_Tracker_Data?.Completed_Movements_Summary_Data?.Repetition_Summary_Data; | ||
if (trackedRepData is not null && trackedRepData.Count > 0) | ||
{ | ||
foreach (var repData in trackedRepData) | ||
{ | ||
var movement = new P2GExercise() | ||
{ | ||
Id = repData.Movement_Id, | ||
Name = repData.Movement_Name, | ||
Type = repData.Is_Hold ? MovementTargetType.Time : MovementTargetType.Reps, | ||
StartOffsetSeconds = repData.Offset, | ||
DurationSeconds = repData.Length, | ||
Reps = repData.Completed_Number, | ||
Weight = new P2GWeight() | ||
{ | ||
Unit = repData?.Weight?.FirstOrDefault()?.Weight_Data?.Weight_Unit, | ||
Value = repData?.Weight?.FirstOrDefault()?.Weight_Data?.Weight_Value ?? 0 | ||
} | ||
}; | ||
movements.Add(movement); | ||
} | ||
} | ||
|
||
return movements; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using NUnit.Framework; | ||
using Peloton; | ||
using System.Collections.Generic; | ||
using Common.Dto.Peloton; | ||
using FluentAssertions; | ||
|
||
namespace UnitTests.Peloton; | ||
|
||
public class P2GWorkoutExerciseMapperTests | ||
{ | ||
public static Workout[] Workouts = | ||
{ | ||
null, | ||
new Workout(), | ||
new Workout() { Movement_Tracker_Data = new MovementTrackerData() }, | ||
new Workout() { Movement_Tracker_Data = new MovementTrackerData() { Completed_Movements_Summary_Data = new CompletedMovementsSummaryData() } }, | ||
new Workout() { Movement_Tracker_Data = new MovementTrackerData() { Completed_Movements_Summary_Data = new CompletedMovementsSummaryData() { Repetition_Summary_Data = new List<RepetitionSummaryData>() } } }, | ||
}; | ||
|
||
[Test, TestCaseSource(nameof(Workouts))] | ||
public void GetExercisesTrackedByMovementTracker_WhenNoData(Workout workout) | ||
{ | ||
var exercises = P2GWorkoutExerciseMapper.GetExercisesTrackedByMovementTracker(workout); | ||
exercises.Should().NotBeNull(); | ||
exercises.Should().BeEmpty(); | ||
} | ||
|
||
[Test] | ||
public void GetExercisesTrackedByMovementTracker_WhenNoWeight() | ||
{ | ||
var workout = new Workout() | ||
{ | ||
Movement_Tracker_Data = new MovementTrackerData() | ||
{ | ||
Completed_Movements_Summary_Data = new CompletedMovementsSummaryData() | ||
{ | ||
Repetition_Summary_Data = new List<RepetitionSummaryData>() | ||
{ | ||
new RepetitionSummaryData() | ||
{ | ||
Weight = null | ||
}, | ||
new RepetitionSummaryData() | ||
{ | ||
Weight = new List<Weight>() | ||
}, | ||
new RepetitionSummaryData() | ||
{ | ||
Weight = new List<Weight>() { new Weight() } | ||
}, | ||
new RepetitionSummaryData() | ||
{ | ||
Weight = new List<Weight>() { new Weight() { Weight_Data = null } } | ||
}, | ||
new RepetitionSummaryData() | ||
{ | ||
Weight = new List<Weight>() { new Weight() { Weight_Data = new WeightData() | ||
{ | ||
Weight_Unit = null, | ||
} } } | ||
}, | ||
} | ||
} | ||
} | ||
}; | ||
|
||
var exercises = P2GWorkoutExerciseMapper.GetExercisesTrackedByMovementTracker(workout); | ||
exercises.Should().NotBeNull(); | ||
exercises.Should().HaveCount(5); | ||
exercises.Should().OnlyContain(e => e.Weight != null); | ||
exercises.Should().OnlyContain(e => e.Weight.Unit == null); | ||
exercises.Should().OnlyContain(e => e.Weight.Value == 0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters