Exemplo n.º 1
0
        public void AddRun(RunStatistics run)
        {
            HeartRateHistogram.Record(run.HeartRateHistogram);
            PaceHistogram.Record(run.PaceHistogram);
            TotalDistance   += run.TotalDistance;
            TotalTime       += run.TotalTime;
            TotalHeartbeats += run.TotalHeartbeats;
            MaxHeartRate     = Math.Max(MaxHeartRate, run.MaxHeartRate);
            TotalSteps      += run.TotalSteps;
            TotalClimb      += run.TotalClimb;
            Runs++;
            DateTime lastPointTime = DateTime.MinValue;
            var      sampledRoute  = new SortedDictionary <DateTime, GpxTrackPoint>();

            foreach (var time in run.Route.Keys)
            {
                if (time >= lastPointTime + Settings.AggregateSamplingPeriod)
                {
                    sampledRoute[time] = run.Route[time];
                    lastPointTime      = time;
                }
            }
            var lastPoint = run.Route.Last();

            if (!sampledRoute.ContainsKey(lastPoint.Key))
            {
                sampledRoute[lastPoint.Key] = lastPoint.Value;
            }
            foreach (var point in run.Pauses)
            {
                if (!sampledRoute.ContainsKey(point.PauseStart.Time))
                {
                    sampledRoute[point.PauseStart.Time] = point.PauseStart;
                }
                if (!sampledRoute.ContainsKey(point.PauseEnd.Time))
                {
                    sampledRoute[point.PauseEnd.Time] = point.PauseEnd;
                }
            }
            Routes[run.StartTime] = sampledRoute.Values.ToList();
            foreach (var point in sampledRoute.Values)
            {
                if (point.Latitude < MinLatitude)
                {
                    MinLatitude = point.Latitude;
                }
                if (point.Latitude > MaxLatitude)
                {
                    MaxLatitude = point.Latitude;
                }
                if (point.Longitude < MinLongitude)
                {
                    MinLongitude = point.Longitude;
                }
                if (point.Longitude > MaxLongitude)
                {
                    MaxLongitude = point.Longitude;
                }
            }
        }
Exemplo n.º 2
0
        public void RecordInterval(GpxTrackPoint point)
        {
            // Sequence (AveragingPeriod=4):
            // ___, ___, ___, ___ (latest = -1, earliest = -1)
            // Δ01, ___, ___, ___ (latest = 0, earliest = 0)
            // Δ01, Δ12, ___, ___ (latest = 1, earliest = 0)
            // Δ01, Δ12, Δ23, ___ (latest = 2, earliest = 0)
            // Δ01, Δ12, Δ23, Δ34 (latest = 3, earliest = 0)
            // Δ45, Δ12, Δ23, Δ34 (latest = 0, earliest = 1)
            // Δ45, Δ56, Δ23, Δ34 (latest = 1, earliest = 2)
            // Δ45, Δ56, Δ67, Δ34 (latest = 2, earliest = 3)
            // Δ45, Δ56, Δ67, Δ78 (latest = 3, earliest = 0)
            // Δ89, Δ56, Δ67, Δ78 (latest = 0, earliest = 1)
            _latestPointOffset++;
            if (_bufferCount < Settings.AveragingPeriod)
            {
                _bufferCount++;
            }
            if (_latestPointOffset >= Settings.AveragingPeriod)
            {
                _latestPointOffset = 0;
            }
            if (_earliestPointOffset < 0)
            {
                _earliestPointOffset = 0;
            }
            else if (_latestPointOffset == _earliestPointOffset)
            {
                _earliestPointOffset++;
                if (_earliestPointOffset >= Settings.AveragingPeriod)
                {
                    _earliestPointOffset = 0;
                }
            }

            _lastIntervals[_latestPointOffset].Distance = _lastPoint.DistanceTo(point);
            _lastIntervals[_latestPointOffset].Climb    = point.Elevation - _lastPoint.Elevation;
            _lastIntervals[_latestPointOffset].Interval = _lastPoint.TimeDifference(point);

            var dist   = _lastPoint.DistanceTo(point);
            var deltaT = _lastPoint.TimeDifference(point);

            var averagedDistance = 0.0;
            var averagedClimb    = 0.0;
            var averageTime      = new TimeSpan(0);

            for (var i = 0; i < _bufferCount; i++)
            {
                averagedDistance += _lastIntervals[i].Distance;
                averagedClimb    += _lastIntervals[i].Climb;
                averageTime      += _lastIntervals[i].Interval;
            }

            HeartRateHistogram.Record(point.HeartRate, deltaT);
            TotalHeartbeats += point.HeartRate * deltaT.TotalMinutes;

            var averagedPace = new TimeSpan((long)(1000.0D * averageTime.Ticks / averagedDistance));

            // ReSharper disable once PossibleLossOfFraction
            PaceHistogram.Record(TimeSpan.FromSeconds(averagedPace.Ticks / TimeSpan.TicksPerSecond), deltaT);
            if (averagedDistance > 0.0 /* && averagedPace < Settings.SlowestDisplayedPace*/)
            {
                point.Pace = averagedPace;
                if (averagedPace < FastestPace)
                {
                    FastestPace = averagedPace;
                }
                if (averagedPace > SlowestPace)
                {
                    SlowestPace = (averagedPace > Settings.SlowestDisplayedPace ? Settings.SlowestDisplayedPace : averagedPace);
                }
            }
            else
            {
                point.Pace = Settings.SlowestDisplayedPace;
            }
            point.Speed = 3600.0 / averagedPace.TotalSeconds;
            if (point.Speed > MaxSpeed)
            {
                MaxSpeed = point.Speed;
            }

            // Cadence is number of full cycles per minute by the pair of feet, thus there are two steps per cadence per minute
            TotalSteps += 2.0D * point.Cadence * deltaT.TotalMinutes;

            point.Slope = 100.0D * Math.Tan(averagedClimb / averagedDistance);

            TotalDistance += dist;
            TotalTime     += deltaT;

            var intervalClimb = point.Elevation - _lastPoint.Elevation;

            if (intervalClimb > 0.0D)
            {
                TotalClimb += intervalClimb;
            }

            EndTime = point.Time > EndTime ? point.Time : EndTime;

            RecordRoutePoint(point);

            _lastPoint = point;
            _lastPace  = averagedDistance > 0.0 ? averagedPace : Settings.SlowestDisplayedPace;
        }