コード例 #1
0
        static void CreateBikeTempoWorkout()
        {
            var workoutSteps = new List <WorkoutStepMesg>();

            workoutSteps.Add(CreateWorkoutStep(messageIndex: workoutSteps.Count,
                                               durationType: WktStepDuration.Time,
                                               durationValue: 600000, // milliseconds
                                               targetType: WktStepTarget.HeartRate,
                                               targetValue: 1,
                                               intensity: Intensity.Warmup));

            workoutSteps.Add(CreateWorkoutStep(messageIndex: workoutSteps.Count,
                                               durationType: WktStepDuration.Time,
                                               durationValue: 2400000,  // milliseconds
                                               targetType: WktStepTarget.Power,
                                               targetValue: 3));

            workoutSteps.Add(CreateWorkoutStep(messageIndex: workoutSteps.Count,
                                               intensity: Intensity.Cooldown));

            var workoutMesg = new WorkoutMesg();

            workoutMesg.SetWktName("Tempo Bike");
            workoutMesg.SetSport(Sport.Cycling);
            workoutMesg.SetSubSport(SubSport.Invalid);
            workoutMesg.SetNumValidSteps((ushort)workoutSteps.Count);

            CreateWorkout(workoutMesg, workoutSteps);
        }
コード例 #2
0
        static void CreatePoolSwimWorkout()
        {
            var workoutSteps = new List <WorkoutStepMesg>();

            // Warm Up 200 yds
            workoutSteps.Add(CreateWorkoutStepSwim(messageIndex: workoutSteps.Count,
                                                   distance: 182.88f,
                                                   intensity: Intensity.Warmup));
            // Rest until lap button pressed
            workoutSteps.Add(CreateWorkoutStepSwimRest(messageIndex: workoutSteps.Count));

            // Drill w/ kickboard 200 yds
            workoutSteps.Add(CreateWorkoutStepSwim(messageIndex: workoutSteps.Count,
                                                   distance: 182.88f,
                                                   swimStroke: SwimStroke.Drill,
                                                   equipment: WorkoutEquipment.SwimKickboard));
            // Rest until lap button pressed
            workoutSteps.Add(CreateWorkoutStepSwimRest(messageIndex: workoutSteps.Count));

            // 5 x 100 yds on 2:00
            workoutSteps.Add(CreateWorkoutStepSwim(messageIndex: workoutSteps.Count,
                                                   distance: 91.44f,
                                                   swimStroke: SwimStroke.Freestyle));

            workoutSteps.Add(CreateWorkoutStepSwimRest(messageIndex: workoutSteps.Count,
                                                       durationType: WktStepDuration.RepetitionTime,
                                                       durationTime: 120.0f));

            workoutSteps.Add(CreateWorkoutStepRepeat(messageIndex: workoutSteps.Count, repeatFrom: 4, repetitions: 5));

            // Rest until lap button pressed
            workoutSteps.Add(CreateWorkoutStepSwimRest(messageIndex: workoutSteps.Count));

            // Cool Down 100 yds
            workoutSteps.Add(CreateWorkoutStepSwim(messageIndex: workoutSteps.Count,
                                                   distance: 91.44f,
                                                   intensity: Intensity.Cooldown));

            var workoutMesg = new WorkoutMesg();

            workoutMesg.SetWktName("Pool Swim");
            workoutMesg.SetSport(Sport.Swimming);
            workoutMesg.SetSubSport(SubSport.LapSwimming);
            workoutMesg.SetPoolLength(22.86f); // 25 yards
            workoutMesg.SetPoolLengthUnit(DisplayMeasure.Statute);
            workoutMesg.SetNumValidSteps((ushort)workoutSteps.Count);

            CreateWorkout(workoutMesg, workoutSteps);
        }
コード例 #3
0
        static void CreateRun800RepeatsWorkout()
        {
            var workoutSteps = new List <WorkoutStepMesg>();

            workoutSteps.Add(CreateWorkoutStep(messageIndex: workoutSteps.Count,
                                               durationType: WktStepDuration.Distance,
                                               durationValue: 400000,  // centimeters
                                               targetType: WktStepTarget.HeartRate,
                                               targetValue: 1,
                                               intensity: Intensity.Warmup));

            workoutSteps.Add(CreateWorkoutStep(messageIndex: workoutSteps.Count,
                                               durationType: WktStepDuration.Distance,
                                               durationValue: 80000,  // centimeters
                                               targetType: WktStepTarget.HeartRate,
                                               targetValue: 4));

            workoutSteps.Add(CreateWorkoutStep(messageIndex: workoutSteps.Count,
                                               durationType: WktStepDuration.Distance,
                                               durationValue: 20000,  // centimeters
                                               targetType: WktStepTarget.HeartRate,
                                               targetValue: 2,
                                               intensity: Intensity.Rest));

            workoutSteps.Add(CreateWorkoutStepRepeat(messageIndex: workoutSteps.Count, repeatFrom: 1, repetitions: 5));

            workoutSteps.Add(CreateWorkoutStep(messageIndex: workoutSteps.Count,
                                               durationType: WktStepDuration.Distance,
                                               durationValue: 100000,  // centimeters
                                               targetType: WktStepTarget.HeartRate,
                                               targetValue: 2,
                                               intensity: Intensity.Cooldown));

            var workoutMesg = new WorkoutMesg();

            workoutMesg.SetWktName("Running 800m Repeats");
            workoutMesg.SetSport(Sport.Running);
            workoutMesg.SetSubSport(SubSport.Invalid);
            workoutMesg.SetNumValidSteps((ushort)workoutSteps.Count);

            CreateWorkout(workoutMesg, workoutSteps);
        }
コード例 #4
0
        static void CreateCustomTargetValuesWorkout()
        {
            var workoutSteps = new List <WorkoutStepMesg>();

            workoutSteps.Add(CreateWorkoutStep(messageIndex: workoutSteps.Count,
                                               durationType: WktStepDuration.Time,
                                               durationValue: 600000,      // milliseconds
                                               targetType: WktStepTarget.HeartRate,
                                               customTargetValueLow: 235,  // 135 + 100
                                               customTargetValueHigh: 255, // 155 + 100
                                               intensity: Intensity.Warmup));

            workoutSteps.Add(CreateWorkoutStep(messageIndex: workoutSteps.Count,
                                               durationType: WktStepDuration.Time,
                                               durationValue: 2400000,        // milliseconds
                                               targetType: WktStepTarget.Power,
                                               customTargetValueLow: 1175,    // 175 + 1000
                                               customTargetValueHigh: 1195)); // 195 + 1000

            workoutSteps.Add(CreateWorkoutStep(messageIndex: workoutSteps.Count,
                                               durationType: WktStepDuration.Time,
                                               durationValue: 600000,       // milliseconds
                                               targetType: WktStepTarget.Speed,
                                               customTargetValueLow: 5556,  // 5.556 meters/second * 1000
                                               customTargetValueHigh: 6944, // 6.944 meters/second * 1000
                                               intensity: Intensity.Cooldown));

            var workoutMesg = new WorkoutMesg();

            workoutMesg.SetWktName("Custom Target Values");
            workoutMesg.SetSport(Sport.Cycling);
            workoutMesg.SetSubSport(SubSport.Invalid);
            workoutMesg.SetNumValidSteps((ushort)workoutSteps.Count);

            CreateWorkout(workoutMesg, workoutSteps);
        }
コード例 #5
0
        protected override Tuple <string, ICollection <Mesg> > Convert(Workout workout, WorkoutSamples workoutSamples)
        {
            // MESSAGE ORDER MATTERS
            var messages = new List <Mesg>();

            var startTime = GetStartTimeUtc(workout);
            var endTime   = GetEndTimeUtc(workout);
            var title     = WorkoutHelper.GetTitle(workout);
            var sport     = GetGarminSport(workout);
            var subSport  = GetGarminSubSport(workout);

            if (sport == Sport.Invalid)
            {
                Log.Warning("Unsupported Sport Type - Skipping {@Sport}", workout.Fitness_Discipline);
                return(new Tuple <string, ICollection <Mesg> >(string.Empty, null));
            }

            var fileIdMesg = new FileIdMesg();

            fileIdMesg.SetSerialNumber(_serialNumber);
            fileIdMesg.SetTimeCreated(startTime);
            fileIdMesg.SetManufacturer(_manufacturerId);
            fileIdMesg.SetProduct(_productId);
            fileIdMesg.SetType(Dynastream.Fit.File.Activity);
            messages.Add(fileIdMesg);

            var eventMesg = new EventMesg();

            eventMesg.SetTimestamp(startTime);
            eventMesg.SetData(0);
            eventMesg.SetEvent(Event.Timer);
            eventMesg.SetEventType(EventType.Start);
            eventMesg.SetEventGroup(0);
            messages.Add(eventMesg);

            var deviceInfoMesg = new DeviceInfoMesg();

            deviceInfoMesg.SetTimestamp(startTime);
            deviceInfoMesg.SetSerialNumber(_serialNumber);
            deviceInfoMesg.SetManufacturer(_manufacturerId);
            deviceInfoMesg.SetProduct(_productId);
            deviceInfoMesg.SetSoftwareVersion(_softwareVersion);
            deviceInfoMesg.SetDeviceIndex(0);
            deviceInfoMesg.SetSourceType(SourceType.Local);
            deviceInfoMesg.SetProductName("PelotonToGarmin");             // Max 20 Chars
            messages.Add(deviceInfoMesg);

            var userProfileMesg = new UserProfileMesg();

            userProfileMesg.SetPowerSetting(DisplayPower.PercentFtp);
            messages.Add(userProfileMesg);

            var sportMesg = new SportMesg();

            sportMesg.SetSport(sport);
            sportMesg.SetSubSport(subSport);
            messages.Add(sportMesg);

            var zoneTargetMesg = new ZonesTargetMesg();

            zoneTargetMesg.SetFunctionalThresholdPower((ushort)workout.Ftp_Info.Ftp);
            zoneTargetMesg.SetPwrCalcType(PwrZoneCalc.PercentFtp);
            var maxHr = GetUserMaxHeartRate(workoutSamples);

            if (maxHr is object)
            {
                zoneTargetMesg.SetMaxHeartRate(maxHr.Value);
                zoneTargetMesg.SetHrCalcType(HrZoneCalc.PercentMaxHr);
            }
            messages.Add(zoneTargetMesg);

            var trainingMesg = new TrainingFileMesg();

            trainingMesg.SetTimestamp(startTime);
            trainingMesg.SetTimeCreated(startTime);
            trainingMesg.SetSerialNumber(_serialNumber);
            trainingMesg.SetManufacturer(_manufacturerId);
            trainingMesg.SetProduct(_productId);
            trainingMesg.SetType(Dynastream.Fit.File.Workout);
            messages.Add(trainingMesg);

            AddMetrics(messages, workoutSamples, startTime);

            var workoutSteps = new List <WorkoutStepMesg>();
            var laps         = new List <LapMesg>();

            if (workoutSamples.Target_Performance_Metrics?.Target_Graph_Metrics?.FirstOrDefault(w => w.Type == "cadence")?.Graph_Data is object)
            {
                var stepsAndLaps = GetWorkoutStepsAndLaps(workoutSamples, startTime, sport, subSport);
                workoutSteps = stepsAndLaps.Values.Select(v => v.Item1).ToList();
                laps         = stepsAndLaps.Values.Select(v => v.Item2).ToList();
            }
            else
            {
                laps = GetWorkoutLaps(workoutSamples, startTime, sport, subSport).ToList();
            }

            var workoutMesg = new WorkoutMesg();

            workoutMesg.SetWktName(title.Replace(_spaceSeparator, " "));
            workoutMesg.SetCapabilities(32);
            workoutMesg.SetSport(sport);
            workoutMesg.SetSubSport(subSport);
            workoutMesg.SetNumValidSteps((ushort)workoutSteps.Count);
            messages.Add(workoutMesg);

            // add steps in order
            foreach (var step in workoutSteps)
            {
                messages.Add(step);
            }

            // Add laps in order
            foreach (var lap in laps)
            {
                messages.Add(lap);
            }

            messages.Add(GetSessionMesg(workout, workoutSamples, startTime, endTime, (ushort)laps.Count));

            var activityMesg = new ActivityMesg();

            activityMesg.SetTimestamp(endTime);
            activityMesg.SetTotalTimerTime(workoutSamples.Duration);
            activityMesg.SetNumSessions(1);
            activityMesg.SetType(Activity.Manual);
            activityMesg.SetEvent(Event.Activity);
            activityMesg.SetEventType(EventType.Stop);

            var timezoneOffset = (int)TimeZoneInfo.Local.GetUtcOffset(base.GetEndTimeUtc(workout)).TotalSeconds;
            var timeStamp      = (uint)((int)endTime.GetTimeStamp() + timezoneOffset);

            activityMesg.SetLocalTimestamp(timeStamp);

            messages.Add(activityMesg);

            return(new Tuple <string, ICollection <Mesg> >(title, messages));
        }