示例#1
0
        public bool loadWorkout(int workoutToStart)
        {
            if (workoutRunning)
            {
                return(false);
            }
            if (workoutToStart >= workOutList.Count)
            {
                return(false);
            }
            if (workoutEventHandler == null)
            {
                return(false);
            }

            activeSegment        = -1;
            activeWorkout        = workOutList[workoutToStart];
            msTimeForNextSegment = activeWorkout.segments[0].length * 1000;

            workoutEventArgs wEA = getDefaultEventData();

            wEA.message        = "Loading Workout " + activeWorkout.title;
            wEA.segmentTotalMS = activeWorkout.segments[0].length * 1000;
            wEA.workoutTotalMS = activeWorkout.length * 1000;
            wEA.starting       = true;
            workoutEventHandler(this, wEA);
            workOutSeconds = 0;
            return(true);
        }
示例#2
0
        public void load_Workout(workoutDef workout)
        {
            activeWorkout = workout;
            draw_workout();

            spdline.Clear();
            cadline.Clear();
            hrline.Clear();
            pwrline.Clear();

            spdData.Clear();
            cadData.Clear();
            hrData.Clear();
            pwrData.Clear();
        }
示例#3
0
        public cWorkout()
        {
            // Read working Directory for files named "workoutX.xml"
            // Create Workouts from them.

            workOutList = new List <workoutDef>();
            workoutDef newWorkout = new workoutDef();

            newWorkout.segments = new List <segmentDef>();
            segmentDef newSegment = new segmentDef();

            bIsPaused   = false;
            bIsFinished = false;

            bIsRunning     = false;
            workOutSeconds = 0;

            workoutPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "CycleSoft\\Workouts\\");
            Directory.CreateDirectory(workoutPath);
            workoutFileArray = Directory.GetFiles(workoutPath, "*.xml");

            for (int i = 0; i < workoutFileArray.Length; i++)
            {
                Stream workOutContents = File.Open(workoutFileArray[i], FileMode.Open);
                reader = XmlReader.Create(workOutContents);
                long totalLength = 0;
                while (!reader.EOF)
                {
                    /* Content Like:
                     * <Workout Title = "Test Workout 4 Seg">
                     *          <segment type = "Ramp" id = "WarmUp" length = "30">
                     *                  <effort start = ".50" finish = ".7" plus = ".15" minus = ".02"/>
                     *                  <cad target = "0" plus = "200" minus = "0"/>
                     *          </segment>
                     *          <segment type = "SteadyState" id = "SteadyState" length = "60">
                     *                  <effort start = ".90" plus = ".15" minus = ".02"/>
                     *                  <cad target = "90" plus = "20" minus = "0"/>
                     *          </segment>
                     *          <segment type = "OverUnder" id = "OverUnder" length = "120">
                     *                  <effort start = ".95" finish = "1.10" plus = ".05" min = ".01" undertime = "20" overtime = "10" />
                     *                  <cad target = "0" plus = "200" minus = "0"/>
                     *          </segment>
                     *          <segment id = "CoolDown" type = "ramp" length = "30">
                     *                  <effort start = ".55" plus = ".15" minus = ".02" finish = ".4"/>
                     *                  <cad target = "0" plus = "200" minus = "0"/>
                     *          </segment>
                     *  </Workout>
                     */
                    reader.Read();
                    switch (reader.Name)
                    {
                    case "Workout":
                        if (reader.HasAttributes)
                        {
                            newWorkout.title     = reader.GetAttribute("Title");
                            newWorkout.videopath = reader.GetAttribute("Video");
                        }
                        break;

                    case "segment":
                        newSegment.segmentName = reader.GetAttribute("id");
                        newSegment.type        = reader.GetAttribute("type");
                        newSegment.length      = Convert.ToInt64(reader.GetAttribute("length"));
                        totalLength           += newSegment.length;
                        break;

                    case "effort":
                        newSegment.effort       = Convert.ToDouble(reader.GetAttribute("start"));
                        newSegment.effortFinish = Convert.ToDouble(reader.GetAttribute("finish"));
                        newSegment.ptsPlus      = Convert.ToDouble(reader.GetAttribute("plus"));
                        newSegment.ptsMinus     = Convert.ToDouble(reader.GetAttribute("minus"));
                        newSegment.underTime    = Convert.ToInt64(reader.GetAttribute("undertime"));
                        newSegment.overTime     = Convert.ToInt64(reader.GetAttribute("overtime"));
                        break;

                    case "cad":
                        newSegment.cadTarget   = Convert.ToInt32(reader.GetAttribute("target"));
                        newSegment.ptsCadPlus  = Convert.ToInt32(reader.GetAttribute("plus"));
                        newSegment.ptsCadMinus = Convert.ToInt32(reader.GetAttribute("minus"));
                        newWorkout.segments.Add(newSegment);
                        newSegment = new segmentDef();
                        break;

                    default:
                        break;
                    }
                }
                newWorkout.length = totalLength;
                workOutList.Add(newWorkout);
                newWorkout          = new workoutDef();
                newWorkout.segments = new List <segmentDef>();
                reader.Close();
                workOutContents.Close();
            }
        }
示例#4
0
        public Point[] getWorkoutPoints(workoutDef activeWorkout)
        {
            Point[] tempWorkoutPoints = new Point[500];
            // not sure if I have to ...set all points?

            tempWorkoutPoints[0] = new Point(0.0, 1.0);

            // Can't do this here overUnders break this
            // tempWorkoutPoints[1 + 2 * activeWorkout.segments.Count] = new Point(1.0, 1.0);

            double currentX     = 0.0;
            int    currentPoint = 1;

            // would like to mod this to show
            // .2 FTP -> 1.8 FTP ... should make peeks better?
            // so, would like .2 =
            foreach (segmentDef seg in activeWorkout.segments)
            {
                tempWorkoutPoints[currentPoint] = new Point(currentX, (1 - ((seg.effort - 1) / chartZoom + .5)));
                currentPoint++;
                switch (seg.type)
                {
                case "steady":
                    currentX = currentX + (double)seg.length / activeWorkout.length;
                    tempWorkoutPoints[currentPoint] = new Point(currentX, (1 - ((seg.effort - 1) / chartZoom + .5)));
                    currentPoint++;
                    break;

                case "ramp":
                    currentX = currentX + (double)seg.length / activeWorkout.length;
                    tempWorkoutPoints[currentPoint] = new Point(currentX, (1 - ((seg.effortFinish - 1) / chartZoom + .5)));
                    currentPoint++;
                    break;

                case "overunder":
                    double endTime   = currentX + (double)seg.length / activeWorkout.length;
                    double underTime = (double)seg.underTime / activeWorkout.length;
                    double overTime  = (double)seg.overTime / activeWorkout.length;
                    bool   isOver    = false;
                    while (currentX < endTime)
                    {
                        if (!isOver && currentX + underTime <= endTime)
                        {
                            currentX = currentX + underTime;
                            tempWorkoutPoints[currentPoint] = new Point(currentX, (1 - ((seg.effort - 1) / chartZoom + .5)));
                            currentPoint++;
                            tempWorkoutPoints[currentPoint] = new Point(currentX, (1 - ((seg.effortFinish - 1) / chartZoom + .5)));
                            currentPoint++;
                            isOver = true;
                        }
                        else if (currentX + overTime <= endTime)
                        {
                            currentX = currentX + overTime;
                            tempWorkoutPoints[currentPoint] = new Point(currentX, (1 - ((seg.effortFinish - 1) / chartZoom + .5)));
                            currentPoint++;
                            tempWorkoutPoints[currentPoint] = new Point(currentX, (1 - ((seg.effort - 1) / chartZoom + .5)));
                            currentPoint++;
                            isOver = false;
                        }
                        else
                        {
                            currentX = endTime;
                            tempWorkoutPoints[currentPoint] = new Point(currentX, (1 - ((seg.effort - 1) / chartZoom + .5)));
                        }
                    }
                    break;
                }
            }
            tempWorkoutPoints[currentPoint] = new Point(1.0, 1.0);

            Point[] currentWorkoutPoints = new Point[currentPoint + 1];
            for (int i = 0; i <= currentPoint; i++)
            {
                currentWorkoutPoints[i] = tempWorkoutPoints[i];
            }

            return(currentWorkoutPoints);
        }