コード例 #1
0
        public void GetDistance()
        {
            IList <GPSPoint> pkt = new List <GPSPoint>();

            pkt.Add(new GPSPoint(50.9313049f, 17.2975941f, 3, 4, 1));
            pkt.Add(new GPSPoint(50.9311333f, 17.29805f, 31, 41, 2));
            pkt.Add(new GPSPoint(50.9310341f, 17.2986717f, 32, 42, 3));
            pkt.Add(new GPSPoint(50.9312172f, 17.2992649f, 34, 44, 5));
            pkt.Add(new GPSPoint(50.9329834f, 17.3020668f, 35, 45, 6));
            pkt.Add(new GPSPoint(50.933815f, 17.3040714f, 35, 45, 7));

            var distance = GPSTrackerHelper.GetDistance(pkt);

            Assert.AreEqual(574.84724282491675, distance);
        }
コード例 #2
0
        public void GetDistance_WithPausePoint()
        {
            IList <GPSPoint> pkt = new List <GPSPoint>();

            pkt.Add(new GPSPoint(50.9313049f, 17.2975941f, 3, 4, 1));
            pkt.Add(new GPSPoint(50.9311333f, 17.29805f, 31, 41, 2));
            pkt.Add(new GPSPoint(50.9310341f, 17.2986717f, 32, 42, 3));
            pkt.Add(new GPSPoint(50.9312172f, 17.2992649f, 34, 44, 5));
            pkt.Add(GPSPoint.CreatePause(5.1f));
            pkt.Add(new GPSPoint(50.9329834f, 17.3020668f, 35, 45, 6));
            pkt.Add(new GPSPoint(50.933815f, 17.3040714f, 35, 45, 7));

            var distance = GPSTrackerHelper.GetDistance(pkt);

            Assert.AreEqual(296.89223243105414, distance);
        }
コード例 #3
0
        private static void performGpsPointsCalculations(GPSTrackerEntry res, List <GPSPoint> points, Profile dbProfile)
        {
            if (res.Status == EntryObjectStatus.Planned)
            {
                res.Status = EntryObjectStatus.Done;
            }
            //perform calculation based on gps coordinates
            res.Distance = (decimal?)GPSTrackerHelper.GetDistance(points);
            var pointsWithSpeed = points.Where(x => !float.IsNaN(x.Speed) && x.Speed > -1).ToList();

            if (pointsWithSpeed.Count > 0)
            {
                res.MaxSpeed = (decimal?)pointsWithSpeed.Max(x => x.Speed);
            }
            //res.AvgSpeed = (decimal?) points.Average(x => x.Speed);
            var pointsWithAltitude = points.Where(x => !float.IsNaN(x.Altitude) && x.Altitude > -1).ToList();

            if (pointsWithAltitude.Count > 0)
            {
                res.MaxAltitude  = (decimal?)pointsWithAltitude.Max(x => x.Altitude);
                res.MinAltitude  = (decimal?)pointsWithAltitude.Min(x => x.Altitude);
                res.TotalAscent  = (decimal?)GPSTrackerHelper.GetTotalAscents(pointsWithAltitude);
                res.TotalDescent = (decimal?)GPSTrackerHelper.GetTotalDescends(pointsWithAltitude);
            }

            if (res.Duration == null || res.Duration == 0)
            {
                res.Duration = (decimal?)points.Last().Duration;
            }
            if (res.Calories == null || res.Calories == 0)
            {
                TrainingDayService.CalculateCaloriesBurned(res,
                                                           res.TrainingDay.Customer != null
                                                               ? (IPerson)res.TrainingDay.Customer
                                                               : dbProfile);
            }
            if (res.Duration.Value > 0)
            {
                res.AvgSpeed = res.Distance.Value / res.Duration.Value;
            }
        }