/// <summary>
        /// Create and return a new SAMPLE based on the index in the mTempList
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        private SAMPLE BuildNewSample(int index)
        {
            SAMPLE newSample = new SAMPLE();
            // Build new sample
            GeoLoc     point1        = new GeoLoc(mTempList[index - 1].LAT, mTempList[index - 1].LON);
            GeoLoc     point2        = new GeoLoc(mTempList[index].LAT, mTempList[index].LON);
            double     newPointSlope = (mTempList[index - 1].SLOPE + mTempList[index].SLOPE) / 2;
            double     newPointSpeed = (mTempList[index - 1].KPH + mTempList[index].KPH) / 2;
            GeoLocMath geoLocM1      = new GeoLocMath(point1, point2);
            GeoLoc     newPoint      = geoLocM1.CalcMidPoint();

            geoLocM1.point1 = newPoint;
            geoLocM1.point2 = point1;
            double newdistanceTravelled = geoLocM1.CalcDistanceBetweenGeoLocations() + mTempList[index - 1].KM;

            // Create new sample and add data from above
            newSample = new SAMPLE()
            {
                SECS  = 999999, //insertPosition,
                KM    = newdistanceTravelled,
                KPH   = newPointSpeed,
                ALT   = (mTempList[index].ALT + mTempList[index - 1].ALT) / 2,
                LAT   = newPoint.Latitude,
                LON   = newPoint.Longitude,
                SLOPE = newPointSlope
            };
            return(newSample);
        }
Пример #2
0
        /// <summary>
        /// Add a new point between 2 adjacent ones
        /// </summary>
        private void  AddNewPoint(
            ref int thisOldRideCnt,
            ref int thisNewRideCnt,
            ref int pointsAdded,
            ref GoldenCheetahRide thisOldRide,
            ref GoldenCheetahRide thisNewRide,
            ref string fullPath)
        {
            // Add new sample
            GeoLoc point1        = new GeoLoc(thisOldRide.RIDE.SAMPLES[thisOldRideCnt - 1].LAT, thisOldRide.RIDE.SAMPLES[thisOldRideCnt - 1].LON);
            GeoLoc point2        = new GeoLoc(thisOldRide.RIDE.SAMPLES[thisOldRideCnt].LAT, thisOldRide.RIDE.SAMPLES[thisOldRideCnt].LON);
            double newPointSlope = (thisOldRide.RIDE.SAMPLES[thisOldRideCnt - 1].SLOPE + thisOldRide.RIDE.SAMPLES[thisOldRideCnt].SLOPE) / 2;
            double newPointSpeed = (thisOldRide.RIDE.SAMPLES[thisOldRideCnt - 1].KPH + thisOldRide.RIDE.SAMPLES[thisOldRideCnt].KPH) / 2;

            GeoLocMath geoLocM1 = new GeoLocMath(point1, point2);
            GeoLoc     newPoint = geoLocM1.CalcMidPoint();

            geoLocM1.point1 = newPoint;
            geoLocM1.point2 = point1;
            double newdistanceTravelled = geoLocM1.CalcDistanceBetweenGeoLocations() + thisOldRide.RIDE.SAMPLES[thisOldRideCnt - 1].KM;
            // Create new sample and add data from above
            SAMPLE newSample = new SAMPLE()
            {
                SECS  = 999, //insertPosition,
                KM    = newdistanceTravelled,
                KPH   = newPointSpeed,
                ALT   = (thisOldRide.RIDE.SAMPLES[thisOldRideCnt].ALT + thisOldRide.RIDE.SAMPLES[thisOldRideCnt - 1].ALT) / 2,
                LAT   = newPoint.Latitude,
                LON   = newPoint.Longitude,
                SLOPE = newPointSlope
            };

            // Insert new point in ride
            thisNewRide.RIDE.SAMPLES.Add(newSample);
            testSegment.Add(newSample);
            SaveLineToTxt(newSample, fullPath, -1, thisNewRideCnt);
            thisNewRideCnt += 1;

            pointsAdded++;
        }
Пример #3
0
        }        // ***** addPointsToNewRide ENDS

        /// <summary>
        /// Process to generate more points that currently available in the segment.
        /// </summary>
        /// <param name="startCnt"></param>
        /// <param name="endCnt"></param>
        /// <param name="pointsToAdd"></param>
        /// <param name="pointsAdded"></param>
        /// <param name="thisOldRideCnt"></param>
        /// <param name="thisNewRideCnt"></param>
        /// <param name="pointsMoved"></param>
        /// <param name="segmentTime"></param>
        /// <param name="thisOldRide"></param>
        /// <param name="thisNewRide"></param>
        /// <param name="fullPath"></param>
        private void MorePointsThanWeHaveAddProcess(ref int startCnt,
                                                    ref int endCnt,
                                                    //ref int pointsInterval,
                                                    //ref int lastSample,
                                                    ref int pointsToAdd,
                                                    ref int pointsAdded,
                                                    ref int thisOldRideCnt,
                                                    ref int thisNewRideCnt,
                                                    //ref int pointsMoved,
                                                    ref int segmentTime,
                                                    ref GoldenCheetahRide thisOldRide,
                                                    ref GoldenCheetahRide thisNewRide,
                                                    ref string fullPath)
        {
            //Save state
            int  savedStartCnt        = startCnt;
            int  savedthisOldRideCnt  = thisOldRideCnt;
            bool finishedMovingPoints = false;

            // Always start with the second point
            int startingPoint = 2;

            while (startCnt <= endCnt)
            {
                if (pointsAdded < pointsToAdd && startCnt >= startingPoint)
                {
                    // Add new sample
                    GeoLoc point1        = new GeoLoc(thisOldRide.RIDE.SAMPLES[thisOldRideCnt - 1].LAT, thisOldRide.RIDE.SAMPLES[thisOldRideCnt - 1].LON);
                    GeoLoc point2        = new GeoLoc(thisOldRide.RIDE.SAMPLES[thisOldRideCnt].LAT, thisOldRide.RIDE.SAMPLES[thisOldRideCnt].LON);
                    double newPointSlope = (thisOldRide.RIDE.SAMPLES[thisOldRideCnt - 1].SLOPE + thisOldRide.RIDE.SAMPLES[thisOldRideCnt].SLOPE) / 2;
                    double newPointSpeed = (thisOldRide.RIDE.SAMPLES[thisOldRideCnt - 1].KPH + thisOldRide.RIDE.SAMPLES[thisOldRideCnt].KPH) / 2;

                    GeoLocMath geoLocM1 = new GeoLocMath(point1, point2);
                    GeoLoc     newPoint = geoLocM1.CalcMidPoint();
                    geoLocM1.point1 = newPoint;
                    geoLocM1.point2 = point1;
                    double newdistanceTravelled = geoLocM1.CalcDistanceBetweenGeoLocations() + thisOldRide.RIDE.SAMPLES[thisOldRideCnt - 1].KM;
                    // Create new sample and add data from above
                    SAMPLE newSample = new SAMPLE()
                    {
                        SECS  = 999, //insertPosition,
                        KM    = newdistanceTravelled,
                        KPH   = newPointSpeed,
                        ALT   = (thisOldRide.RIDE.SAMPLES[thisOldRideCnt].ALT + thisOldRide.RIDE.SAMPLES[thisOldRideCnt - 1].ALT) / 2,
                        LAT   = newPoint.Latitude,
                        LON   = newPoint.Longitude,
                        SLOPE = newPointSlope
                    };
                    // Insert new point in ride
                    thisNewRide.RIDE.SAMPLES.Add(newSample);
                    testSegment.Add(newSample);
                    SaveLineToTxt(newSample, fullPath, -1, thisNewRideCnt);
                    thisNewRideCnt += 1;
                    //cnt = 1;
                    pointsAdded++;
                }

                if (!finishedMovingPoints)
                {
                    // Move sample to new ride
                    CopySampleToNewlist(thisOldRide.RIDE.SAMPLES[thisOldRideCnt], ref thisNewRide);
                    CopySampleToTestlist(thisOldRide.RIDE.SAMPLES[thisOldRideCnt], ref testSegment);
                    SaveLineToTxt(thisOldRide.RIDE.SAMPLES[thisOldRideCnt], fullPath, thisOldRideCnt, thisNewRideCnt);
                    thisNewRideCnt += 1;
                    thisOldRideCnt++;
                    //cnt++;
                }

                startCnt++;

                if (pointsAdded < pointsToAdd && startCnt >= startingPoint && startCnt > endCnt)
                {
                    startCnt             = savedStartCnt;
                    thisOldRideCnt       = savedthisOldRideCnt;
                    finishedMovingPoints = true;
                }
            } // END of adding for loop

            // Need to check if all points needed were added.
            // If not, loop and add them

            //while (pointsAdded < pointsToAdd)
            //{

            //    AddNewPoint(
            //        ref thisOldRideCnt,
            //        ref thisNewRideCnt,
            //        ref pointsAdded,
            //        ref thisOldRide,
            //        ref thisNewRide,
            //        ref fullPath);

            //}

            //if (pointsAdded < pointsToAdd)
            //{
            //    throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().ToString() +
            //        $" -- Only added {pointsAdded} out of {pointsToAdd} ");
            //}
        }
Пример #4
0
        // This method will add points to a  route segment if
        // the # of points to be added < half of the size of the segment
        private void LessThanHalfPointsAddProcess(ref int startCnt,
                                                  ref int endCnt,
                                                  ref int pointsInterval,
                                                  //ref int lastSample,
                                                  ref int pointsToAdd,
                                                  ref int pointsAdded,
                                                  ref int thisOldRideCnt,
                                                  ref int thisNewRideCnt,
                                                  ref int pointsMoved,
                                                  //ref double videoSpeed,
                                                  ref GoldenCheetahRide thisOldRide,
                                                  ref GoldenCheetahRide thisNewRide,
                                                  ref string fullPath)
        {
            //Loop and add points
            int cnt     = 1;
            int loopCnt = 0;

            while (startCnt <= endCnt)             // THIS
            {
                if (cnt == pointsInterval)         // || startCnt == lastSample)  // We only add points at pointsInterval
                {
                    if (pointsAdded < pointsToAdd) // Stop adding points because pointsInterval is converted to integer and not accurate
                    {
                        // Add new sample
                        GeoLoc point1        = new GeoLoc(thisOldRide.RIDE.SAMPLES[thisOldRideCnt - 1].LAT, thisOldRide.RIDE.SAMPLES[thisOldRideCnt - 1].LON);
                        GeoLoc point2        = new GeoLoc(thisOldRide.RIDE.SAMPLES[thisOldRideCnt].LAT, thisOldRide.RIDE.SAMPLES[thisOldRideCnt].LON);
                        double newPointSlope = (thisOldRide.RIDE.SAMPLES[thisOldRideCnt - 1].SLOPE + thisOldRide.RIDE.SAMPLES[thisOldRideCnt].SLOPE) / 2;
                        double newPointSpeed = (thisOldRide.RIDE.SAMPLES[thisOldRideCnt - 1].KPH + thisOldRide.RIDE.SAMPLES[thisOldRideCnt].KPH) / 2;

                        GeoLocMath geoLocM1 = new GeoLocMath(point1, point2);
                        GeoLoc     newPoint = geoLocM1.CalcMidPoint();
                        geoLocM1.point1 = newPoint;
                        geoLocM1.point2 = point1;
                        double newdistanceTravelled = geoLocM1.CalcDistanceBetweenGeoLocations() + thisOldRide.RIDE.SAMPLES[thisOldRideCnt - 1].KM;

                        // Create new sample and add data from above
                        SAMPLE newSample = new SAMPLE()
                        {
                            SECS  = 999, //insertPosition,
                            KM    = newdistanceTravelled,
                            KPH   = newPointSpeed,
                            ALT   = (thisOldRide.RIDE.SAMPLES[thisOldRideCnt].ALT + thisOldRide.RIDE.SAMPLES[thisOldRideCnt - 1].ALT) / 2,
                            LAT   = newPoint.Latitude,
                            LON   = newPoint.Longitude,
                            SLOPE = newPointSlope
                        };
                        // Insert new point in ride
                        thisNewRide.RIDE.SAMPLES.Add(newSample);
                        testSegment.Add(newSample);
                        SaveLineToTxt(newSample, fullPath, -1, thisNewRideCnt);
                        thisNewRideCnt += 1;
                        cnt             = 1;
                        pointsAdded++;
                    }
                }
                // Move sample to new ride
                CopySampleToNewlist(thisOldRide.RIDE.SAMPLES[thisOldRideCnt], ref thisNewRide);
                CopySampleToTestlist(thisOldRide.RIDE.SAMPLES[thisOldRideCnt], ref testSegment);
                SaveLineToTxt(thisOldRide.RIDE.SAMPLES[thisOldRideCnt], fullPath, thisOldRideCnt, thisNewRideCnt);
                thisNewRideCnt += 1;
                thisOldRideCnt++;
                cnt++;
                pointsMoved++;
                loopCnt++;
                startCnt++;
            } // END of addong for loop
        }