Exemple #1
0
 private static void PostProcessPointIndex(TrackLap lap, ref int firstIndex)
 {
     foreach (TrackPoint point in lap.Points)
     {
         point.Index = firstIndex++;
     }
 }
Exemple #2
0
 private static void PostProcessPointTimeDelta(TrackLap lap, DateTime startTime)
 {
     foreach (TrackPoint point in lap.Points)
     {
         point.TimeDelta = point.Time - startTime;
     }
 }
Exemple #3
0
        private static TrackActivity ConvertTrack(GpxTrack gpxTrack)
        {
            TrackActivity track = new TrackActivity();

            track.Laps      = new List <TrackLap>();
            track.Waypoints = new List <TrackWaypoint>();

            track.Name        = gpxTrack.Name;
            track.Description = gpxTrack.Description;

            foreach (GpxTrackSegment segment in gpxTrack.TrackSegments)
            {
                TrackLap lap = new TrackLap();
                lap.Points = new List <TrackPoint>();

                foreach (GpxTrackPoint gpxPt in segment.TrackPoints)
                {
                    TrackPoint pt = new TrackPoint();

                    pt.Latitude  = (float)gpxPt.Lat;
                    pt.Longitude = (float)gpxPt.Lon;
                    pt.Altitude  = (float)gpxPt.Elevation;
                    pt.Time      = gpxPt.Time;

                    lap.Points.Add(pt);
                }

                track.Laps.Add(lap);
            }

            return(track);
        }
        private static TrackActivity ConvertCourse(TcxCourse tcxCourse)
        {
            TrackActivity track = new TrackActivity();

            track.Laps      = new List <TrackLap>();
            track.Waypoints = new List <TrackWaypoint>();

            track.Name = tcxCourse.Name;

            TrackLap lap = new TrackLap();

            lap.Points = new List <TrackPoint>();

            if (tcxCourse.CoursePoints != null)
            {
                foreach (TcxCoursePoint tcxCoursePoint in tcxCourse.CoursePoints)
                {
                    track.Waypoints.Add(ConvertWaypoint(tcxCoursePoint));
                }
            }

            if (tcxCourse.TrackpointList != null && tcxCourse.TrackpointList.Trackpoints != null)
            {
                foreach (TcxTrackPoint tcxPt in tcxCourse.TrackpointList.Trackpoints)
                {
                    TrackPoint pt = ConvertTrackPoint(tcxPt);

                    lap.Points.Add(pt);
                }
            }

            track.Laps.Add(lap);

            return(track);
        }
Exemple #5
0
        private static void PostProcessPointDistance(TrackLap lap)
        {
            TrackPoint prevPoint = lap.Points[0];
            double     accDist   = 0;

            foreach (TrackPoint point in lap.Points)
            {
                accDist       += ComputeDistance(point, prevPoint);
                point.Distance = (float)accDist;

                prevPoint = point;
            }
        }
Exemple #6
0
        private static void ComputeSpeed(TrackLap lap, TrackPoint pt)
        {
            const int range = 2;

            int lapIndex = pt.Index - lap.FirstPointIndex;

            // compute speed from [-range..range] around index
            int lowBound  = Math.Max(lapIndex - range, 0);
            int highBound = Math.Min(lapIndex + range, lap.Points.Count - 1);

            float    deltaDistance = lap.Points[highBound].Distance - lap.Points[lowBound].Distance;
            TimeSpan deltaTime     = lap.Points[highBound].Time - lap.Points[lowBound].Time;

            if (deltaTime != TimeSpan.Zero)
            {
                pt.Speed = 0.001f * deltaDistance / (float)deltaTime.TotalHours;
            }
        }
Exemple #7
0
        private static void PostProcessLapData(TrackLap lap)
        {
            if (lap.Points.Count < 2)
            {
                return;
            }

            if (lap.Points[lap.Points.Count - 1].Distance == 0.0)
            {
                PostProcessPointDistance(lap);
            }

            lap.StartTime     = lap.Points[0].Time;
            lap.TotalDistance = lap.Points[lap.Points.Count - 1].Distance - lap.Points[0].Distance;
            lap.TotalTime     = lap.Points[lap.Points.Count - 1].Time - lap.Points[0].Time;

            float accumAsc  = 0;
            float accumDesc = 0;
            float prevAlti  = lap.Points[0].Altitude;

            foreach (TrackPoint pt in lap.Points)
            {
                // compute accumulated ascent/descent
                float diff = pt.Altitude - prevAlti;
                prevAlti = pt.Altitude;

                if (diff > 0)
                {
                    accumAsc += diff;
                }
                else
                {
                    accumDesc -= diff;                                          // diff is negative so (-diff) is positive.
                }
                pt.AccAsc  = accumAsc;
                pt.AccDesc = accumDesc;

                ComputeSpeed(lap, pt);
            }
        }
        private static TrackActivity ConvertActivity(TcxActivity tcxActivity)
        {
            TrackActivity track = new TrackActivity();

            track.Laps      = new List <TrackLap>();
            track.Waypoints = new List <TrackWaypoint>();

            foreach (TcxActivityLap tcxLap in tcxActivity.Laps)
            {
                TrackLap lap = new TrackLap();
                lap.Points = new List <TrackPoint>();

                if (tcxLap.Tracks != null)
                {
                    foreach (TcxTrackPointList tcxTrack in tcxLap.Tracks)
                    {
                        if (tcxTrack.Trackpoints != null)
                        {
                            foreach (TcxTrackPoint tcxPoint in tcxTrack.Trackpoints)
                            {
                                TrackPoint pt = ConvertTrackPoint(tcxPoint);

                                if (pt != null)
                                {
                                    lap.Points.Add(pt);
                                }
                            }
                        }
                    }
                }

                track.Laps.Add(lap);
            }

            return(track);
        }