예제 #1
0
        private void NonConsecutivePointsRemoveProcess(ref int startCnt,
                                                       ref int endCnt,
                                                       ref int pointsInterval,
                                                       //ref int lastSample,
                                                       ref int pointsLeftToRemove,
                                                       ref int thisOldRideCnt,
                                                       //ref int pointsSkipped,
                                                       ref int thisNewRideCnt,
                                                       ref int pointsMoved,
                                                       ref GoldenCheetahRide thisOldRide,
                                                       ref GoldenCheetahRide thisNewRide,
                                                       ref string fullPath)
        {
            if (pointsInterval <= 1)
            {
                throw new Exception("ConsecutivePointsRemoveProcess -- Cannot remove all points");
            }

            //Loop and remove points
            int cnt = 1;

            while (startCnt < endCnt)
            {
                if (cnt == pointsInterval) // || startCnt == lastSample) // Skip sample to simulate removing sample in new ride
                {                          // Don't remove more than pointsToRemove
                    if (pointsLeftToRemove > 0)
                    {
                        cnt = 1;
                        thisOldRideCnt++;
                        pointsLeftToRemove--;
                        //pointsSkipped++;
                        startCnt++;
                    }
                }
                if (startCnt < endCnt)
                {
                    if (thisOldRideCnt <= thisOldRide.RIDE.SAMPLES.Count - 2) // Guard aginst EOF
                    {
                        CopySampleToNewlist(thisOldRide.RIDE.SAMPLES[thisOldRideCnt], ref thisNewRide);
                        CopySampleToTestlist(thisOldRide.RIDE.SAMPLES[thisOldRideCnt], ref testSegment);
                        SaveLineToTxt(thisOldRide.RIDE.SAMPLES[thisOldRideCnt], fullPath, thisOldRideCnt, thisNewRideCnt);
                        thisNewRideCnt++;
                        thisOldRideCnt++;
                        cnt++;
                        pointsMoved++;
                        startCnt++;
                    }
                    else
                    {
                        startCnt = endCnt;
                        thisNewRideCnt++;
                        thisOldRideCnt++;
                    }
                }
            } // END of removing for loop
        }
예제 #2
0
        // Too many points to drop. Rather than removing points just move some points to the new ride
        private void ConsecutivePointsRemoveProcess(ref int startCnt,
                                                    ref int endCnt,
                                                    ref int pointsInterval,
                                                    //ref int lastSample,
                                                    ref int pointsLeftToRemove,
                                                    ref int thisOldRideCnt,
                                                    //ref int pointsSkipped,
                                                    ref int thisNewRideCnt,
                                                    ref int pointsMoved,
                                                    ref GoldenCheetahRide thisOldRide,
                                                    ref GoldenCheetahRide thisNewRide,
                                                    ref int videoTime,
                                                    ref string fullPath)
        {
            int dropCount = (endCnt - startCnt) / (videoTime - 1);

            if (dropCount * (videoTime - 1) > endCnt - startCnt)
            {
                dropCount--;
            }
            if (dropCount <= 1)
            {
                throw new Exception("ConsecutivePointsRemoveProcess -- Cannot remove all points");
            }

            int  addedCntr = 1;
            bool done      = false;

            while (startCnt < endCnt && !done)
            {
                thisOldRideCnt += dropCount;
                //pointsSkipped += dropCount;
                if (thisOldRideCnt < thisOldRide.RIDE.SAMPLES.Count - 2) // Guard aginst EOF
                {
                    if (addedCntr < videoTime - 1)                       // Don't add more points than needed
                    {
                        CopySampleToNewlist(thisOldRide.RIDE.SAMPLES[thisOldRideCnt], ref thisNewRide);
                        CopySampleToTestlist(thisOldRide.RIDE.SAMPLES[thisOldRideCnt], ref testSegment);
                        SaveLineToTxt(thisOldRide.RIDE.SAMPLES[thisOldRideCnt], fullPath, thisOldRideCnt, thisNewRideCnt);
                        thisNewRideCnt++;
                        //thisOldRideCnt++;
                        pointsMoved++;
                        addedCntr++;
                    }
                    else
                    {
                        done           = true;
                        thisOldRideCnt = endCnt;
                    }
                }
                startCnt += dropCount;
            }
        }
예제 #3
0
        private void CopySampleToNewlist(SAMPLE srcSample, ref GoldenCheetahRide destination)
        {
            SAMPLE newSample = new SAMPLE()
            {
                SECS  = srcSample.SECS, //insertPosition,
                KM    = srcSample.KM,
                KPH   = srcSample.KPH,
                ALT   = srcSample.ALT,
                LAT   = srcSample.LAT,
                LON   = srcSample.LON,
                SLOPE = srcSample.SLOPE
            };

            // Insert new point in ride
            destination.RIDE.SAMPLES.Add(newSample);
        }
예제 #4
0
        public void UpdateTableFromRideListSamples(DataTable thisDataTable, GoldenCheetahRide thisGCRide)
        {
            thisDataTable.Clear();
            for (int i = 0; i < thisGCRide.RIDE.SAMPLES.Count() - 1; i++)
            {
                DataRow dr = thisDataTable.NewRow();

                dr["secs"]  = thisGCRide.RIDE.SAMPLES[i].SECS;
                dr["km"]    = thisGCRide.RIDE.SAMPLES[i].KM;
                dr["cad"]   = thisGCRide.RIDE.SAMPLES[i].CAD;
                dr["kph"]   = thisGCRide.RIDE.SAMPLES[i].KPH;
                dr["hr"]    = thisGCRide.RIDE.SAMPLES[i].HR;
                dr["alt"]   = thisGCRide.RIDE.SAMPLES[i].ALT;
                dr["lat"]   = thisGCRide.RIDE.SAMPLES[i].LAT;
                dr["lon"]   = thisGCRide.RIDE.SAMPLES[i].LON;
                dr["slope"] = thisGCRide.RIDE.SAMPLES[i].SLOPE;
                thisDataTable.Rows.Add(dr); //add other rows
            }
        }
예제 #5
0
        //Only needed if we allow the user to edit the table manually
        public void UpdateRideListSamplesFromTable(DataTable thisDataTable, GoldenCheetahRide thisGCRide)
        {
            thisGCRide.RIDE.SAMPLES = null;
            thisGCRide.RIDE.SAMPLES = new List <SAMPLE>();
            foreach (DataRow dr in thisDataTable.Rows)
            {
                SAMPLE newSample = new SAMPLE();
                newSample.SECS  = (int)dr["secs"];
                newSample.KM    = (double)dr["km"];
                newSample.CAD   = (int)dr["cad"];
                newSample.KPH   = (double)dr["kph"];
                newSample.HR    = (double)dr["hr"];
                newSample.ALT   = (double)dr["alt"];
                newSample.LAT   = (double)dr["lat"];
                newSample.LON   = (double)dr["lon"];
                newSample.SLOPE = (double)dr["slope"];

                thisGCRide.RIDE.SAMPLES.Add(newSample);
            }
        }
예제 #6
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++;
        }
예제 #7
0
        public int FindTimeForDistance(double s, ref GoldenCheetahRide thisOldRide)
        {
            int pos = 0;

            while (thisOldRide.RIDE.SAMPLES[pos].KM < s && pos <= thisOldRide.RIDE.SAMPLES.Count - 1)
            {
                pos += 1;
            }
            if (pos > 0)
            {
                if (Math.Abs(thisOldRide.RIDE.SAMPLES[pos].KM - s) > Math.Abs(thisOldRide.RIDE.SAMPLES[pos - 1].KM - s))
                {
                    //Previous position is better match
                    pos--;
                }
            }
            if (pos > thisOldRide.RIDE.SAMPLES.Count || pos < 0)
            {
                pos = -1;
            }
            return(pos);
        }
예제 #8
0
        public DataTable LoadTableFromGCRideList(GoldenCheetahRide thisRide)
        {
            if (thisRide.RIDE.SAMPLES.Count() == 0)
            {
                return(null);
            }

            DataTable dt = new DataTable();

            dt.Columns.Add("secs", typeof(int));
            dt.Columns.Add("km", typeof(double));
            dt.Columns.Add("cad", typeof(int));
            dt.Columns.Add("kph", typeof(double));
            dt.Columns.Add("hr", typeof(double));
            dt.Columns.Add("alt", typeof(double));
            dt.Columns.Add("lat", typeof(double));
            dt.Columns.Add("lon", typeof(double));
            dt.Columns.Add("slope", typeof(double));

            for (int i = 0; i < thisRide.RIDE.SAMPLES.Count(); i++)
            {
                DataRow dr = dt.NewRow();

                dr["secs"]  = thisRide.RIDE.SAMPLES[i].SECS;
                dr["km"]    = thisRide.RIDE.SAMPLES[i].KM;
                dr["cad"]   = thisRide.RIDE.SAMPLES[i].CAD;
                dr["kph"]   = thisRide.RIDE.SAMPLES[i].KPH;
                dr["hr"]    = thisRide.RIDE.SAMPLES[i].HR;
                dr["alt"]   = thisRide.RIDE.SAMPLES[i].ALT;
                dr["lat"]   = thisRide.RIDE.SAMPLES[i].LAT;
                dr["lon"]   = thisRide.RIDE.SAMPLES[i].LON;
                dr["slope"] = thisRide.RIDE.SAMPLES[i].SLOPE;
                dt.Rows.Add(dr);
            }
            return(dt);
        }
예제 #9
0
        public List <SAMPLE> RemovePointsFromNewRide(int videoTime, int startTime, int endTime, ref int thisOldRideCnt, ref int thisNewRideCnt, GoldenCheetahRide thisOldRide, ref GoldenCheetahRide thisNewRide)
        {
            TextConnector tc       = new TextConnector();
            string        fullPath = tc.FullFilePath("debug" + startTime.ToString() + "-" + endTime.ToString() + ".csv", "debug");

            if (File.Exists(fullPath))
            {
                File.Delete(fullPath);
            }

            testSegment.Clear();
            int pointsMoved = 0;
            //int pointsSkipped = 0;
            int pointsToRemove = -1;
            int startCnt       = startTime;
            int endCnt         = endTime;
            int segmentTime    = endTime - startTime + 1;

            videoTime++;  // Add 1 second to the video that is lost during subtraction.
            // If we only need to remove 1 point the above increment will make pointsToRemove == 0.
            pointsToRemove = Math.Abs(videoTime - segmentTime);
            if (pointsToRemove == 0)
            {
                pointsToRemove = 1;
            }

            int pointsInterval = CalculateRomovePointsInterval(pointsToRemove, segmentTime);

            if (thisNewRide.RIDE.SAMPLES.Count() == 0) // This is the first record so we can't subtract 1 from the counters
            {
                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++;
                startCnt++;
            }
            else
            {   //Check if point exists in new route before adding it
                if (Math.Abs(thisNewRide.RIDE.SAMPLES[thisNewRideCnt - 1].KM - thisOldRide.RIDE.SAMPLES[thisOldRideCnt - 1].KM) > 0.01)
                {
                    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++;
                    pointsMoved++;
                }
                else // Based on distance point already exists
                {
                    startCnt++;
                    //pointsSkipped++;
                }
            }

            // THIS NEEDS A METHOD ---Do we need an extra  drop?
            //int lastSample = -1;
            //if ((pointsInterval * pointsToRemove) == segmentTime) lastSample = segmentTime - 1;



            if ((pointsInterval * pointsToRemove) >= segmentTime - 1)
            {
                pointsInterval--;
            }
            int pointsLeftToRemove = pointsToRemove;


            // if the videoTimeSegment is > than (routeSegmentTime/2) we need to remove more points than we keep.
            //
            if (videoTime > (segmentTime / 2))
            {
                NonConsecutivePointsRemoveProcess(ref startCnt,
                                                  ref endCnt,
                                                  ref pointsInterval,
                                                  //ref lastSample,
                                                  ref pointsLeftToRemove,
                                                  ref thisOldRideCnt,
                                                  //ref pointsSkipped,
                                                  ref thisNewRideCnt,
                                                  ref pointsMoved,
                                                  ref thisOldRide,
                                                  ref thisNewRide,
                                                  ref fullPath);
            }
            else
            {
                ConsecutivePointsRemoveProcess(ref startCnt,
                                               ref endCnt,
                                               ref pointsInterval,
                                               //ref lastSample,
                                               ref pointsLeftToRemove,
                                               ref thisOldRideCnt,
                                               //ref pointsSkipped,
                                               ref thisNewRideCnt,
                                               ref pointsMoved,
                                               ref thisOldRide,
                                               ref thisNewRide,
                                               ref videoTime,
                                               ref fullPath);
            }

            // Get last point from old route
            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++;


            //// Save temp list
            //TextConnector tc = new TextConnector();
            //string fullPath = tc.FullFilePath("debug" + startTime.ToString() + "-"  + endTime.ToString() + ".csv", "debug");
            //SaveToTxt(testSegment, fullPath);
            return(testSegment);
        }
예제 #10
0
        //Video segment and ride segment are equal. Move all points from the old ride to the new one.
        public List <SAMPLE> MoveAllPointsToNewRide(int videoTime, int startTime, int endTime, ref int thisOldRideCnt,
                                                    ref int thisNewRideCnt, GoldenCheetahRide thisOldRide, ref GoldenCheetahRide thisNewRide)
        {
#if (DEBUG)
            TextConnector tc       = new TextConnector();
            string        fullPath = tc.FullFilePath("debug" + startTime.ToString() + "-" + endTime.ToString() + ".csv", "debug");

            if (File.Exists(fullPath))
            {
                File.Delete(fullPath);
            }
#endif
            testSegment.Clear();
            int startCnt = startTime;
            int endCnt   = endTime;

            if (thisNewRide.RIDE.SAMPLES.Count() == 0) // This is the first record so we can't subtract 1 from the counters
            {
                CopySampleToNewlist(thisOldRide.RIDE.SAMPLES[thisOldRideCnt], ref thisNewRide);
                CopySampleToTestlist(thisOldRide.RIDE.SAMPLES[thisOldRideCnt], ref testSegment);
#if (DEBUG)
                SaveLineToTxt(thisOldRide.RIDE.SAMPLES[thisOldRideCnt], fullPath, thisOldRideCnt, thisNewRideCnt);
#endif
                thisNewRideCnt += 1;
                thisOldRideCnt++;
                startCnt++;
            }
            else
            {   //Check if point exists in new route before adding it
                if (Math.Abs(thisNewRide.RIDE.SAMPLES[thisNewRideCnt - 1].KM - thisOldRide.RIDE.SAMPLES[thisOldRideCnt - 1].KM) > 0.01)
                {
                    CopySampleToNewlist(thisOldRide.RIDE.SAMPLES[thisOldRideCnt], ref thisNewRide);
                    CopySampleToTestlist(thisOldRide.RIDE.SAMPLES[thisOldRideCnt], ref testSegment);
#if (DEBUG)
                    SaveLineToTxt(thisOldRide.RIDE.SAMPLES[thisOldRideCnt], fullPath, thisOldRideCnt, thisNewRideCnt);
#endif
                    thisNewRideCnt += 1;
                    thisOldRideCnt++;
                    //pointsMoved++;
                }
                else // Based on distance point already exists
                {
                    startCnt++;
                    //pointsSkipped++;
                }
            }

            while (startCnt <= endCnt)
            {
                if (thisOldRideCnt < thisOldRide.RIDE.SAMPLES.Count - 2) // Guard aginst EOF
                {
                    CopySampleToNewlist(thisOldRide.RIDE.SAMPLES[thisOldRideCnt], ref thisNewRide);
                    CopySampleToTestlist(thisOldRide.RIDE.SAMPLES[thisOldRideCnt], ref testSegment);
#if (DEBUG)
                    SaveLineToTxt(thisOldRide.RIDE.SAMPLES[thisOldRideCnt], fullPath, thisOldRideCnt, thisNewRideCnt);
#endif
                    thisNewRideCnt++;
                }
                startCnt++;
                thisOldRideCnt++;
            }
            return(testSegment);
        }
예제 #11
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} ");
            //}
        }
예제 #12
0
        public void PointsToAdd(int videoTime, int startTime, int endTime, ref int thisOldRideCnt, ref int thisNewRideCnt, GoldenCheetahRide thisOldRide, ref GoldenCheetahRide thisNewRide)
        {
            int pointsMoved = 0;

            for (int i = startTime; i <= endTime; i++)
            {
                if (thisNewRide.RIDE.SAMPLES.Count() == 0) // New ride is empty
                {
                    // This is the first record. Move initial point from old route to new route
                    CopySampleToNewlist(thisOldRide.RIDE.SAMPLES[thisOldRideCnt], ref thisNewRide);
                    thisNewRideCnt++;
                    thisOldRideCnt++;
                    pointsMoved++;
                }
                else // New ride is not empty
                {   //Check if point exists in new route before adding it
                    if (Math.Abs(thisNewRide.RIDE.SAMPLES[thisNewRideCnt - 1].KM - thisOldRide.RIDE.SAMPLES[thisOldRideCnt - 1].KM) > 0.01)
                    {
                        CopySampleToNewlist(thisOldRide.RIDE.SAMPLES[thisOldRideCnt], ref thisNewRide);
                        thisNewRideCnt++;
                        thisOldRideCnt++;
                    }
                }
            }
        }
예제 #13
0
        /// <summary>
        /// Add points to the ride for video sync.
        /// videoTime = The number of seconds the video needs to travel the segment
        /// rideTime = The # of SECS at the end of the segment
        /// startTime = The # of SECS at the start of the segment
        /// endTime = the # of SECS at the end of the segment
        /// </summary>
        /// <returns></returns>
        public List <SAMPLE> AddPointsToNewRide(int videoTime, int startTime, int endTime, ref int thisOldRideCnt, ref int thisNewRideCnt, GoldenCheetahRide thisOldRide, ref GoldenCheetahRide thisNewRide)
        {
            testSegment.Clear();

#if (DEBUG)
            TextConnector tc       = new TextConnector();
            string        fullPath = tc.FullFilePath("debug" + startTime.ToString() + "-" + endTime.ToString() + ".csv", "debug");

            if (File.Exists(fullPath))
            {
                File.Delete(fullPath);
            }
#endif

            int pointsAdded = 0;
            int pointsMoved = 0;
            // Init vars
            int pointsToAdd = -1;
            int startCnt    = 0;
            int endCnt      = 0;
            int segmentTime = 0;
            // If this is not the first record we need to add a second to the video time
            videoTime++;
            segmentTime = endTime - startTime + 1;
            endCnt      = segmentTime - 1; // Last point is added manually
            pointsToAdd = videoTime - segmentTime;

            //Calculate distance and avg speed for the full segment
            GeoLoc     startpoint        = new GeoLoc(thisOldRide.RIDE.SAMPLES[startTime].LAT, thisOldRide.RIDE.SAMPLES[startTime].LON);
            GeoLoc     endpoint          = new GeoLoc(thisOldRide.RIDE.SAMPLES[endTime].LAT, thisOldRide.RIDE.SAMPLES[endTime].LON);
            GeoLocMath geoLocMath        = new GeoLocMath(startpoint, endpoint);
            double     distanceTravelled = geoLocMath.CalcDistanceBetweenGeoLocations();

            if (thisNewRide.RIDE.SAMPLES.Count() == 0)
            {
                // This is the first record.
                // Move initial point from old route to new route
                CopySampleToNewlist(thisOldRide.RIDE.SAMPLES[thisOldRideCnt], ref thisNewRide);
                CopySampleToTestlist(thisOldRide.RIDE.SAMPLES[thisOldRideCnt], ref testSegment);
#if (DEBUG)
                SaveLineToTxt(thisOldRide.RIDE.SAMPLES[thisOldRideCnt], fullPath, thisOldRideCnt, thisNewRideCnt);
#endif
                thisNewRideCnt += 1;
                thisOldRideCnt++;
                startCnt++;
                pointsMoved++;
                endCnt--; // THIS
            }
            else
            {   //Check if point exists in new route before adding it
                if (Math.Abs(thisNewRide.RIDE.SAMPLES[thisNewRideCnt - 1].KM - thisOldRide.RIDE.SAMPLES[thisOldRideCnt - 1].KM) > 0.01)
                {
                    // Move initial point from old route to new route
                    CopySampleToNewlist(thisOldRide.RIDE.SAMPLES[thisOldRideCnt], ref thisNewRide);
                    CopySampleToTestlist(thisOldRide.RIDE.SAMPLES[thisOldRideCnt], ref testSegment);
#if (DEBUG)
                    SaveLineToTxt(thisOldRide.RIDE.SAMPLES[thisOldRideCnt], fullPath, thisOldRideCnt, thisNewRideCnt);
#endif
                    thisNewRideCnt += 1;
                    thisOldRideCnt++;
                    pointsMoved++;
                }
                else
                {
                    // First point is there already, move to the next one and decriment the number of points to move
                    startCnt++;
                    endCnt--;
                }
            }

            // If the last sample to add equals the segment length, add it right before the end
            //int lastSample = -1;
            //if ((pointsInterval * pointsToAdd) == endCnt) lastSample = endCnt - 1;

            if (pointsToAdd > (segmentTime / 2) && pointsToAdd < segmentTime)
            {
                //ADD every other point starting with (_segmentTime - _pointsToAdd) / 2
                MoreThanHalfPointsAddProcess(ref startCnt,
                                             ref endCnt,
                                             //ref pointsInterval,
                                             //ref lastSample,
                                             ref pointsToAdd,
                                             ref pointsAdded,
                                             ref thisOldRideCnt,
                                             ref thisNewRideCnt,
                                             ref pointsMoved,
                                             ref segmentTime,
                                             ref thisOldRide,
                                             ref thisNewRide,
                                             ref fullPath);
            }
            else if (pointsToAdd > (segmentTime / 2) && pointsToAdd > segmentTime)
            {
                Debug.WriteLine(" New Method here ");
                MorePointsThanWeHaveAddProcess(ref startCnt,
                                               ref endCnt,
                                               //ref pointsInterval,
                                               //ref lastSample,
                                               ref pointsToAdd,
                                               ref pointsAdded,
                                               ref thisOldRideCnt,
                                               ref thisNewRideCnt,
                                               ref segmentTime,
                                               ref thisOldRide,
                                               ref thisNewRide,
                                               ref fullPath);
            }
            else
            {
                //Calculate the number of points to add and the interval for adding them
                int pointsInterval = CalculateAddPointsInterval(pointsToAdd, segmentTime, endCnt, videoTime);
                LessThanHalfPointsAddProcess(ref startCnt,
                                             ref endCnt,
                                             ref pointsInterval,
                                             //ref lastSample,
                                             ref pointsToAdd,
                                             ref pointsAdded,
                                             ref thisOldRideCnt,
                                             ref thisNewRideCnt,
                                             ref pointsMoved,
                                             ref thisOldRide,
                                             ref thisNewRide,
                                             ref fullPath);
            }

            // Move last point from old route to new route
            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++;

            return(testSegment);
        }        // ***** addPointsToNewRide ENDS
예제 #14
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
        }