Exemplo n.º 1
0
        private void deletesCoordinates(GPSTrackerEntry res)
        {
            var coordinates = res.Coordinates;

            res.Coordinates = null;
            if (coordinates != null)
            {
                Session.Delete(coordinates);
            }
        }
Exemplo n.º 2
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;
            }
        }