Esempio n. 1
0
 public RunInfo(string fileName, RunStatistics stats)
 {
     FileName = fileName;
     StartTime = stats.StartTime;
     Duration = stats.TotalTime;
     DistanceInKm = stats.TotalDistanceInKm;
 }
Esempio n. 2
0
 public RunInfo(string fileName, RunStatistics stats)
 {
     FileName     = fileName;
     StartTime    = stats.StartTime;
     Duration     = stats.TotalTime;
     DistanceInKm = stats.TotalDistanceInKm;
 }
Esempio n. 3
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;
                }
            }
        }
Esempio n. 4
0
 public void Store(string fileName, RunStatistics stats)
 {
     var fileInfo = new FileInfo(fileName);
     _cache[fileName] = new CacheRecord {
         LastModified = fileInfo.LastWriteTimeUtc,
         Statistics = stats
     };
 }
Esempio n. 5
0
        public void Store(string fileName, RunStatistics stats)
        {
            var fileInfo = new FileInfo(fileName);

            _cache[fileName] = new CacheRecord {
                LastModified = fileInfo.LastWriteTimeUtc,
                Statistics   = stats
            };
        }
 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;
         }
     }
 }
Esempio n. 7
0
        public bool Analyze(string fileName, out RunStatistics runStats)
        {
            runStats = _cache.Fetch(fileName);
            var analysisRun = false;

            if (runStats == null)
            {
                analysisRun = true;
                var gpxNamespace = XNamespace.Get("http://www.topografix.com/GPX/1/1");
                var gpxDoc       = XDocument.Load(fileName);

                runStats = new RunStatistics();
                var firstPoint = true;

                foreach (var track in gpxDoc.Descendants(gpxNamespace + "trk"))
                {
                    foreach (var segment in track.Descendants(gpxNamespace + "trkseg"))
                    {
                        var points = from point in segment.Descendants(gpxNamespace + "trkpt")
                                     select new GpxTrackPoint(point);
                        var iterator = points.GetEnumerator();
                        if (iterator.MoveNext())
                        {
                            var pt = iterator.Current;
                            if (firstPoint)
                            {
                                runStats.StartTime = pt.Time;
                                firstPoint         = false;
                            }
                            runStats.SetStartPoint(pt);
                            while (iterator.MoveNext())
                            {
                                pt = iterator.Current;
                                runStats.RecordInterval(pt);
                            }
                            runStats.EndSegment();
                        }
                    }
                }

                _cache.Store(fileName, runStats);
            }

            AggregateStatistics monthlyStats;
            AggregateStatistics weeklyStats;

            var month = new DateTime(runStats.StartTime.Year, runStats.StartTime.Month, 1);

            if (MonthlyStats.ContainsKey(month))
            {
                monthlyStats = MonthlyStats[month];
            }
            else
            {
                MonthlyStats[month]    = monthlyStats = new AggregateStatistics();
                monthlyStats.StartTime = month;
            }
            monthlyStats.AddRun(runStats);
            var deltaDays = DayOfWeek.Monday - runStats.StartTime.DayOfWeek;

            if (deltaDays > 0)
            {
                deltaDays -= 7;
            }
            var week = runStats.StartTime.Date.AddDays(deltaDays);

            if (WeeklyStats.ContainsKey(week))
            {
                weeklyStats = WeeklyStats[week];
            }
            else
            {
                WeeklyStats[week]     = weeklyStats = new AggregateStatistics();
                weeklyStats.StartTime = week;
            }
            weeklyStats.AddRun(runStats);

            return(analysisRun);
        }