/// <summary>
        /// Create a sublist of the source list based on starting point and items to copy
        /// </summary>
        private void CreateSubListOfSamples()
        {
            mSegmentTime = mEndTimeMarket - mStartTimeMarker + 1;

            if (mSegmentTime <= 1)
            {
                throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().ToString() + $"File time: { mStartTimeMarker }. Items to copy in the list is less than 1.");
            }

            if (mStartTimeMarker > 0)
            {
                mStartTimeMarker++;
            }

            for (int i = mStartTimeMarker; i <= mEndTimeMarket; i++) // Skip point already there
            {
                SAMPLE newSample = new SAMPLE()
                {
                    SECS  = mSourceList[i].SECS, //insertPosition,
                    KM    = mSourceList[i].KM,
                    KPH   = mSourceList[i].KPH,
                    ALT   = mSourceList[i].ALT,
                    LAT   = mSourceList[i].LAT,
                    LON   = mSourceList[i].LON,
                    SLOPE = mSourceList[i].SLOPE
                };
                mTempList.Add(newSample);
            }
            if (mTempList == null)
            {
                throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().ToString() + $"Created list is empty.");
            }
        }
Exemplo n.º 2
0
        public List <SAMPLE> LoadListFromTable(DataTable dt)
        {
            List <SAMPLE> myList = new List <SAMPLE>();

            foreach (DataRow dr in dt.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"];

                myList.Add(newSample);
            }

            if (dt.Rows.Count > 0)
            {
                return(myList);
            }
            else
            {
                return(null);
            }
        }
        /// <summary>
        /// Adding less that half of the segment length. Need to calculate the insert inteval
        /// </summary>
        private void AddLessThanHalfPoints()
        {
            pointsInterval = CalculateAddPointsInterval();

            //startCnt = 1;
            int pointsAdded = 0;
            int endCnt      = mSegmentTime - 1; // Last point is already there
            int cnt         = 1;

            while (startCnt <= endCnt)
            {
                if (pointsAdded < pointsToAdd && cnt == pointsInterval)
                {
                    SAMPLE newSample = BuildNewSample(startCnt);
                    // Insert new point in ride
                    mTempList.Add(newSample);
                    pointsAdded++;
                    cnt = 1;
                    //if (pointsAdded == pointsToAdd) done = true;
                }
                startCnt++;
                cnt++;
            }
            SortMyList();
        }
        /// <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);
        }
Exemplo n.º 5
0
 public static void SaveLineToTxt(SAMPLE item, string path, int origTime, int newTime)
 {
     using (TextWriter tw = new StreamWriter(path, true)) //Append mode
     {
         tw.Write("From sec:" + origTime.ToString());
         tw.Write(" to sec:" + newTime.ToString());
         tw.Write(" -- SECS:" + item.SECS.ToString());
         tw.Write(", KM:" + item.KM.ToString());
         tw.Write(", KPH:" + item.KPH.ToString());
         tw.Write(", LAT:" + item.LAT.ToString());
         tw.Write(", LON:" + item.LON.ToString());
         tw.WriteLine(", SLOPE:" + item.SLOPE.ToString());
         tw.Flush();
     }
 }
Exemplo n.º 6
0
        private void CopySampleToTestlist(SAMPLE srcSample, ref List <SAMPLE> 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.Add(newSample);
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
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);
            }
        }
Exemplo n.º 9
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++;
        }
Exemplo n.º 10
0
        /// <summary>
        /// Adding more than half of the points we have may need multiple passes
        /// </summary>
        private void AddMoreThanHalfPoints()
        {
            int startingPoint = (mSegmentTime - pointsToAdd) / 2;

            if (startingPoint < 1)
            {
                startingPoint = 1;
            }
            //startCnt = 0;
            int pointsAdded = 0;
            int endCnt      = mSegmentTime - 1; // Last point is already there

            while (startCnt <= endCnt)
            {
                if (pointsAdded < pointsToAdd && startCnt >= startingPoint)
                {
                    SAMPLE newSample = BuildNewSample(startCnt);
                    // Insert new point in ride


                    // *** Should not add at the end of the list  ***
                    if (startCnt != endCnt)
                    {
                        mTempList.Add(newSample);
                        pointsAdded++;
                    }
                }
                startCnt++;
                // We got to the end of the list but if we didn't add all the points we needed, start again.
                if (pointsAdded < pointsToAdd && startCnt >= startingPoint && startCnt > endCnt)
                {
                    startCnt = 1;
                    SortMyList();
                }
            }
            SortMyList();
        }
Exemplo n.º 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} ");
            //}
        }
Exemplo n.º 12
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
        }