private static WorkoutStepMesg CreateWorkoutStepRepeat(int messageIndex, uint repeatFrom, uint repetitions) { var workoutStepMesg = new WorkoutStepMesg(); workoutStepMesg.SetMessageIndex((ushort)messageIndex); workoutStepMesg.SetDurationType(WktStepDuration.RepeatUntilStepsCmplt); workoutStepMesg.SetDurationValue(repeatFrom); workoutStepMesg.SetTargetType(WktStepTarget.Open); workoutStepMesg.SetTargetValue(repetitions); return(workoutStepMesg); }
private static WorkoutStepMesg CreateWorkoutStep(int messageIndex, String name = null, String notes = null, Intensity intensity = Intensity.Active, WktStepDuration durationType = WktStepDuration.Open, uint?durationValue = null, WktStepTarget targetType = WktStepTarget.Open, uint targetValue = 0, uint?customTargetValueLow = null, uint?customTargetValueHigh = null) { if (durationType == WktStepDuration.Invalid) { return(null); } var workoutStepMesg = new WorkoutStepMesg(); workoutStepMesg.SetMessageIndex((ushort)messageIndex); if (name != null) { workoutStepMesg.SetWktStepName(name); } if (notes != null) { workoutStepMesg.SetNotes(notes); } workoutStepMesg.SetIntensity(intensity); workoutStepMesg.SetDurationType(durationType); if (durationValue.HasValue) { workoutStepMesg.SetDurationValue(durationValue); } if (targetType != WktStepTarget.Invalid && customTargetValueLow.HasValue && customTargetValueHigh.HasValue) { workoutStepMesg.SetTargetType(targetType); workoutStepMesg.SetTargetValue(0); workoutStepMesg.SetCustomTargetValueLow(customTargetValueLow); workoutStepMesg.SetCustomTargetValueHigh(customTargetValueHigh); } else if (targetType != WktStepTarget.Invalid) { workoutStepMesg.SetTargetType(targetType); workoutStepMesg.SetTargetValue(targetValue); workoutStepMesg.SetCustomTargetValueLow(0); workoutStepMesg.SetCustomTargetValueHigh(0); } return(workoutStepMesg); }
private Dictionary <int, Tuple <WorkoutStepMesg, LapMesg> > GetWorkoutStepsAndLaps(WorkoutSamples workoutSamples, Dynastream.Fit.DateTime startTime, Sport sport, SubSport subSport) { var stepsAndLaps = new Dictionary <int, Tuple <WorkoutStepMesg, LapMesg> >(); if (workoutSamples is null) { return(stepsAndLaps); } var cadenceTargets = workoutSamples.Target_Performance_Metrics?.Target_Graph_Metrics?.FirstOrDefault(w => w.Type == "cadence")?.Graph_Data; if (cadenceTargets is null) { return(stepsAndLaps); } uint previousCadenceLower = 0; uint previousCadenceUpper = 0; ushort stepIndex = 0; var duration = 0; float lapDistanceInMeters = 0; WorkoutStepMesg workoutStep = null; LapMesg lapMesg = null; var speedMetrics = GetSpeedSummary(workoutSamples); foreach (var secondSinceStart in workoutSamples.Seconds_Since_Pedaling_Start) { var index = secondSinceStart <= 0 ? 0 : secondSinceStart - 1; duration++; if (speedMetrics is object && index < speedMetrics.Values.Length) { var currentSpeedInMPS = ConvertToMetersPerSecond(speedMetrics.GetValue(index), workoutSamples); lapDistanceInMeters += 1 * currentSpeedInMPS; } var currentCadenceLower = index < cadenceTargets.Lower.Length ? (uint)cadenceTargets.Lower[index] : 0; var currentCadenceUpper = index < cadenceTargets.Upper.Length ? (uint)cadenceTargets.Upper[index] : 0; if (currentCadenceLower != previousCadenceLower || currentCadenceUpper != previousCadenceUpper) { if (workoutStep != null && lapMesg != null) { workoutStep.SetDurationValue((uint)duration * 1000); // milliseconds var lapEndTime = new Dynastream.Fit.DateTime(startTime); lapEndTime.Add(secondSinceStart); lapMesg.SetTotalElapsedTime(duration); lapMesg.SetTotalTimerTime(duration); lapMesg.SetTimestamp(lapEndTime); lapMesg.SetEventType(EventType.Stop); lapMesg.SetTotalDistance(lapDistanceInMeters); stepsAndLaps.Add(stepIndex, new Tuple <WorkoutStepMesg, LapMesg>(workoutStep, lapMesg)); stepIndex++; duration = 0; lapDistanceInMeters = 0; } workoutStep = new WorkoutStepMesg(); workoutStep.SetDurationType(WktStepDuration.Time); workoutStep.SetMessageIndex(stepIndex); workoutStep.SetTargetType(WktStepTarget.Cadence); workoutStep.SetCustomTargetValueHigh(currentCadenceUpper); workoutStep.SetCustomTargetValueLow(currentCadenceLower); workoutStep.SetIntensity(currentCadenceUpper > 60 ? Intensity.Active : Intensity.Rest); lapMesg = new LapMesg(); var lapStartTime = new Dynastream.Fit.DateTime(startTime); lapStartTime.Add(secondSinceStart); lapMesg.SetStartTime(lapStartTime); lapMesg.SetWktStepIndex(stepIndex); lapMesg.SetMessageIndex(stepIndex); lapMesg.SetEvent(Event.Lap); lapMesg.SetLapTrigger(LapTrigger.Time); lapMesg.SetSport(sport); lapMesg.SetSubSport(subSport); previousCadenceLower = currentCadenceLower; previousCadenceUpper = currentCadenceUpper; } } return(stepsAndLaps); }