Example #1
0
        protected void RemoveDuplicates()
        {
            OrderByTime();

            TcxTrackpoint        prev     = null;
            List <TcxTrackpoint> newTrack = new List <TcxTrackpoint>();

            foreach (TcxTrackpoint tp in TrackPoints)
            {
                if (prev == null)
                {
                    prev = tp;
                }
                else
                {
                    if (tp.Time == prev.Time)
                    {
                        prev = tp.CombineTrackpoint(prev);
                        newTrack.Add(prev);
                        prev = null;
                    }
                    else
                    {
                        newTrack.Add(prev);
                        prev = tp;
                    }
                }
            }
            if (TrackPoints.Count > 0)
            {
                newTrack.Add(TrackPoints.Last());
            }

            TrackPoints = newTrack;
        }
Example #2
0
        protected void Normalize()
        {
            TcxTrackpoint        prev     = null;
            TcxTrackpoint        current  = null;
            List <TcxTrackpoint> next     = null;
            List <TcxTrackpoint> newTrack = new List <TcxTrackpoint>();

            for (int i = 1; i < TrackPoints.Count - 1; i++)
            {
                prev    = TrackPoints[i - 1];
                current = TrackPoints[i];
                next    = TrackPoints.GetRange(i + 1, TrackPoints.Count - i - 1);

                current.CombineTrackpoint(prev, next);
            }
        }
Example #3
0
        public TcxActivity ConvertToTcxActivity()
        {
            TcxActivity tcxActivity = new TcxActivity();

            tcxActivity.Id   = StartTime;
            tcxActivity.Laps = new List <TcxLap>();

            foreach (GpxTrackSegment segment in Track)
            {
                TcxLap lap = new TcxLap();
                lap.Track             = new TcxTrack();
                lap.Track.TrackPoints = new List <TcxTrackpoint>();
                foreach (GpxTrackpoint trackpoint in segment.Track)
                {
                    TcxTrackpoint tcxTrackpoint = new TcxTrackpoint(trackpoint);
                    lap.Track.TrackPoints.Add(tcxTrackpoint);
                }

                tcxActivity.Laps.Add(lap);
            }

            return(tcxActivity);
        }
Example #4
0
        public TcxTrackpoint CombineTrackpoint(TcxTrackpoint second)
        {
            TcxTrackpoint newTrackpoint = new TcxTrackpoint();

            newTrackpoint.Time          = Time;
            newTrackpoint.IsTimeDefined = true;

            if (IsPositionDefined && second.IsPositionDefined)
            {
                newTrackpoint.Position          = Position;
                newTrackpoint.IsPositionDefined = true;
            }
            else
            {
                if (IsPositionDefined)
                {
                    newTrackpoint.Position          = Position;
                    newTrackpoint.IsPositionDefined = true;
                }
                else if (second.IsPositionDefined)
                {
                    newTrackpoint.Position          = second.Position;
                    newTrackpoint.IsPositionDefined = true;
                }
                else
                {
                    newTrackpoint.IsPositionDefined = false;
                }
            }

            if (IsAltitudeMetersDefined && second.IsAltitudeMetersDefined)
            {
                newTrackpoint.AltitudeMeters          = AltitudeMeters;
                newTrackpoint.IsAltitudeMetersDefined = true;
            }
            else
            {
                if (IsAltitudeMetersDefined)
                {
                    newTrackpoint.AltitudeMeters          = AltitudeMeters;
                    newTrackpoint.IsAltitudeMetersDefined = true;
                }
                else if (second.IsAltitudeMetersDefined)
                {
                    newTrackpoint.AltitudeMeters          = second.AltitudeMeters;
                    newTrackpoint.IsAltitudeMetersDefined = true;
                }
                else
                {
                    newTrackpoint.IsAltitudeMetersDefined = false;
                }
            }

            if (IsDistanceMetersDefined && second.IsDistanceMetersDefined)
            {
                newTrackpoint.DistanceMeters          = DistanceMeters;
                newTrackpoint.IsDistanceMetersDefined = true;
            }
            else
            {
                if (IsDistanceMetersDefined)
                {
                    newTrackpoint.DistanceMeters          = DistanceMeters;
                    newTrackpoint.IsDistanceMetersDefined = true;
                }
                else if (second.IsDistanceMetersDefined)
                {
                    newTrackpoint.DistanceMeters          = second.DistanceMeters;
                    newTrackpoint.IsDistanceMetersDefined = true;
                }
                else
                {
                    newTrackpoint.IsDistanceMetersDefined = false;
                }
            }

            if (IsSensorStateDefined && second.IsSensorStateDefined)
            {
                newTrackpoint.SensorState          = SensorState;
                newTrackpoint.IsSensorStateDefined = true;
            }
            else
            {
                if (IsSensorStateDefined)
                {
                    newTrackpoint.SensorState          = SensorState;
                    newTrackpoint.IsSensorStateDefined = true;
                }
                else if (second.IsSensorStateDefined)
                {
                    newTrackpoint.SensorState          = second.SensorState;
                    newTrackpoint.IsSensorStateDefined = true;
                }
                else
                {
                    newTrackpoint.IsSensorStateDefined = false;
                }
            }

            if (IsHeartRateBpmDefined && second.IsHeartRateBpmDefined)
            {
                newTrackpoint.HeartRateBpm          = HeartRateBpm;
                newTrackpoint.IsHeartRateBpmDefined = true;
            }
            else
            {
                if (IsHeartRateBpmDefined)
                {
                    newTrackpoint.HeartRateBpm          = HeartRateBpm;
                    newTrackpoint.IsHeartRateBpmDefined = true;
                }
                else if (second.IsHeartRateBpmDefined)
                {
                    newTrackpoint.HeartRateBpm          = second.HeartRateBpm;
                    newTrackpoint.IsHeartRateBpmDefined = true;
                }
                else
                {
                    newTrackpoint.IsHeartRateBpmDefined = false;
                }
            }

            if (IsCadenceDefined && second.IsCadenceDefined)
            {
                newTrackpoint.Cadence          = Cadence;
                newTrackpoint.IsCadenceDefined = true;
            }
            else
            {
                if (IsCadenceDefined)
                {
                    newTrackpoint.Cadence          = Cadence;
                    newTrackpoint.IsCadenceDefined = true;
                }
                else if (second.IsCadenceDefined)
                {
                    newTrackpoint.Cadence          = second.Cadence;
                    newTrackpoint.IsCadenceDefined = true;
                }
                else
                {
                    newTrackpoint.IsCadenceDefined = false;
                }
            }

            return(newTrackpoint);
        }
Example #5
0
        public TcxTrackpoint CombineTrackpoint(TcxTrackpoint prev, List <TcxTrackpoint> next)
        {
            Console.WriteLine("Combine Trackpoint");
            TcxTrackpoint newTrackpoint = new TcxTrackpoint();

            newTrackpoint.Time          = Time;
            newTrackpoint.IsTimeDefined = true;

            if (!IsPositionDefined)
            {
                if (!prev.IsPositionDefined)
                {
                    Console.WriteLine("Previous element has not defined position!");
                }
                else
                {
                    TcxTrackpoint nextM = null;
                    int           count = 0;
                    foreach (TcxTrackpoint t in next)
                    {
                        count++;
                        if (t.IsPositionDefined)
                        {
                            nextM = t;
                            break;
                        }
                    }
                    if (nextM == null)
                    {
                        Console.WriteLine("Not found next element with position specified!");
                    }
                    else
                    {
                        double fullDiff = (nextM.Time - prev.Time).TotalSeconds;
                        double diff     = (Time - prev.Time).TotalSeconds;

                        double latDiff = nextM.Position.Latitude - prev.Position.Latitude;
                        double lonDiff = nextM.Position.Longitude - prev.Position.Longitude;

                        double newLat = prev.Position.Latitude + ((diff / fullDiff) * latDiff);
                        double newLon = prev.Position.Longitude + ((diff / fullDiff) * lonDiff);

                        newTrackpoint.Position          = new TcxPosition(newLat, newLon);
                        newTrackpoint.IsPositionDefined = true;
                        Console.WriteLine(string.Format("Diff: {0}, FullDiff: {1}, LatDiff: {2}, LonDiff: {3}, newLat: {4}, newLon: {5}",
                                                        diff, fullDiff, latDiff, lonDiff, newLat, newLon));
                    }
                }
            }
            else
            {
                newTrackpoint.Position = Position;
            }

            if (!IsAltitudeMetersDefined)
            {
                if (!prev.IsAltitudeMetersDefined)
                {
                    Console.WriteLine("Previous element has not defined elevation!");
                }
                else
                {
                    TcxTrackpoint nextM = null;
                    int           count = 0;
                    foreach (TcxTrackpoint t in next)
                    {
                        count++;
                        if (t.IsAltitudeMetersDefined)
                        {
                            nextM = t;
                            break;
                        }
                    }
                    if (nextM == null)
                    {
                        Console.WriteLine("Not found next element with elevation specified!");
                    }
                    else
                    {
                        double fullDiff = (nextM.Time - prev.Time).TotalSeconds;
                        double diff     = (Time - prev.Time).TotalSeconds;

                        double eleDiff = nextM.AltitudeMeters - prev.AltitudeMeters;

                        double newEle = (int)(prev.AltitudeMeters + ((diff / fullDiff) * eleDiff));

                        newTrackpoint.AltitudeMeters          = newEle;
                        newTrackpoint.IsAltitudeMetersDefined = true;
                    }
                }
            }
            else
            {
                newTrackpoint.AltitudeMeters = AltitudeMeters;
            }

            if (!IsCadenceDefined)
            {
                if (!prev.IsCadenceDefined)
                {
                    Console.WriteLine("Previous element has not defined cadence!");
                }
                else
                {
                    TcxTrackpoint nextM = null;
                    int           count = 0;
                    foreach (TcxTrackpoint t in next)
                    {
                        count++;
                        if (t.IsCadenceDefined)
                        {
                            nextM = t;
                            break;
                        }
                    }
                    if (nextM == null)
                    {
                        Console.WriteLine("Not found next element with cadence specified!");
                    }
                    else
                    {
                        double fullDiff = (nextM.Time - prev.Time).TotalSeconds;
                        double diff     = (Time - prev.Time).TotalSeconds;

                        double cadDiff = nextM.Cadence - prev.Cadence;

                        double newCad = (int)(prev.Cadence + ((diff / fullDiff) * cadDiff));

                        newTrackpoint.Cadence          = newCad;
                        newTrackpoint.IsCadenceDefined = true;
                    }
                }
            }
            else
            {
                newTrackpoint.Cadence = Cadence;
            }

            if (!IsDistanceMetersDefined)
            {
                if (!prev.IsDistanceMetersDefined)
                {
                    Console.WriteLine("Previous element has not defined distance meters!");
                }
                else
                {
                    TcxTrackpoint nextM = null;
                    int           count = 0;
                    foreach (TcxTrackpoint t in next)
                    {
                        count++;
                        if (t.IsDistanceMetersDefined)
                        {
                            nextM = t;
                            break;
                        }
                    }
                    if (nextM == null)
                    {
                        Console.WriteLine("Not found next element with distance meters specified!");
                    }
                    else
                    {
                        double fullDiff = (nextM.Time - prev.Time).TotalSeconds;
                        double diff     = (Time - prev.Time).TotalSeconds;

                        double distDiff = nextM.DistanceMeters - prev.DistanceMeters;

                        double newDist = (int)(prev.DistanceMeters + ((diff / fullDiff) * distDiff));

                        newTrackpoint.DistanceMeters          = newDist;
                        newTrackpoint.IsDistanceMetersDefined = true;
                    }
                }
            }
            else
            {
                newTrackpoint.DistanceMeters = DistanceMeters;
            }

            if (!IsHeartRateBpmDefined)
            {
                if (!prev.IsHeartRateBpmDefined)
                {
                    Console.WriteLine("Previous element has not defined heart rate!");
                }
                else
                {
                    TcxTrackpoint nextM = null;
                    int           count = 0;
                    foreach (TcxTrackpoint t in next)
                    {
                        count++;
                        if (t.IsHeartRateBpmDefined)
                        {
                            nextM = t;
                            break;
                        }
                    }
                    if (nextM == null)
                    {
                        Console.WriteLine("Not found next element with heart rate specified!");
                    }
                    else
                    {
                        double fullDiff = (nextM.Time - prev.Time).TotalSeconds;
                        double diff     = (Time - prev.Time).TotalSeconds;

                        double heartDiff = nextM.HeartRateBpm - prev.HeartRateBpm;

                        double newHeart = (int)(prev.HeartRateBpm + ((diff / fullDiff) * heartDiff));

                        newTrackpoint.HeartRateBpm          = newHeart;
                        newTrackpoint.IsHeartRateBpmDefined = true;
                    }
                }
            }
            else
            {
                newTrackpoint.HeartRateBpm = HeartRateBpm;
            }



            // todo rest of attributes
            return(newTrackpoint);
        }