예제 #1
0
        /// <summary>
        /// Create Activity Analytics based on the activity type.
        /// </summary>
        /// <returns>Analytics</returns>
        public ActivityAnalytics GetAnalytics()
        {
            if (!IsValid())
            {
                return(ActivityAnalytics.EmptyStream());
            }

            if (Activity.ActivityType.IsRide)
            {
                ZoneValueOnDay value = new ZoneValueOnDay();
                var            ftp   = value.GetUserZoneValueOnGivenDate(_activity.Athlete.UserId, enums.ZoneType.BikePower, _activity.Start);

                if (ftp == null)
                {
                    return(null);
                }

                return(ActivityAnalytics.RideCreateFromPowerStream(Stream, ftp.Value));
            }
            else if (Activity.ActivityType.IsRun)
            {
                return(ActivityAnalytics.RunCreateFromPaceOrHeartRateStream(Stream.Select(w => w.Velocity).ToList(), Stream.Select(w => w.HeartRate).ToList()));
            }
            else if (Activity.ActivityType.IsSwim)
            {
                return(ActivityAnalytics.SwimCreateFromPaceStream(Stream.Select(w => w.Velocity).ToList()));
            }
            else
            {
                return(ActivityAnalytics.OtherUnknown());
            }
        }
예제 #2
0
        private void UpdateActivityDetails()
        {
            // update details missing from summary activity.
            _fvActivity.Calories    = Convert.ToDecimal(_stravaActivity.Calories);
            _fvActivity.Description = _stravaActivity.Description;
            // gear??
            _fvActivity.EmbedToken  = _stravaActivity.EmbedToken;
            _fvActivity.DeviceName  = _stravaActivity.DeviceName;
            _fvActivity.MapPolyline = _stravaActivity.Map.Polyline;
            // splits_metric
            // splits_standard

            if ((_fvActivity.HasPowerMeter) && (_convertedStream.HasIndividualStream(StreamType.Watts)))
            {
                ZoneValueOnDay value = new ZoneValueOnDay();
                var            ftp   = value.GetUserZoneValueOnGivenDate(_userId, enums.ZoneType.BikePower, _fvActivity.Start);

                if (ftp != null)
                {
                    BikePower calc = new BikePower(_convertedStream.GetIndividualStream <int?>(enums.StreamType.Watts), ftp.Value);

                    _fvActivity.TSS             = calc.TSS();
                    _fvActivity.IntensityFactor = calc.IntensityFactor();
                }
            }

            if (_streamSize != null)
            {
                _fvActivity.StreamSize = _streamSize;
            }

            _fvActivity.DetailsDownloaded = true;

            _unitOfWork.Complete();
        }
예제 #3
0
        public void Zone_GetValueOnGivenDayUser2()
        {
            Mock <ISettingsRepository> mock = MockZones();

            ZoneValueOnDay value = new ZoneValueOnDay(mock.Object);

            Assert.IsNull(value.GetUserZoneValueOnGivenDate("USER2", Infrastructure.enums.ZoneType.BikePower, new DateTime(2009, 12, 31)), "Before Initial Date");
            Assert.IsNull(value.GetUserZoneValueOnGivenDate("USER2", Infrastructure.enums.ZoneType.BikeHeartRate, new DateTime(2015, 12, 31)), "No Heart Rates set-up");

            Assert.IsNull(value.GetUserZoneValueOnGivenDate("USER2", Infrastructure.enums.ZoneType.BikePower, new DateTime(2015, 12, 31)), "day before initial date");
            Assert.AreEqual(255, value.GetUserZoneValueOnGivenDate("USER2", Infrastructure.enums.ZoneType.BikePower, new DateTime(2016, 11, 1)), "Start of month");
            Assert.AreEqual(255, value.GetUserZoneValueOnGivenDate("USER2", Infrastructure.enums.ZoneType.BikePower, new DateTime(2016, 11, 2)), "Within  month");
            Assert.AreEqual(255, value.GetUserZoneValueOnGivenDate("USER2", Infrastructure.enums.ZoneType.BikePower, new DateTime(2016, 11, 30)), "End of Month");
            Assert.AreEqual(260, value.GetUserZoneValueOnGivenDate("USER2", Infrastructure.enums.ZoneType.BikePower, new DateTime(2016, 12, 1)), "Begin of month ");
            Assert.AreEqual(260, value.GetUserZoneValueOnGivenDate("USER2", Infrastructure.enums.ZoneType.BikePower, new DateTime(2017, 1, 1)), "After Last date");
        }
예제 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="zone">Zone Type (Bike, Run, Swim - HeartRate/Pace/etc)</param>
        /// <param name="date">Activity date for which to return zones</param>
        /// <returns>Zones for a given user/type on a given date</returns>
        public List <ZoneValueDto> GetUserZoneValues(ZoneType zone, DateTime date)
        {
            // remove the time.
            date = date.Date;

            ZoneValueOnDay zoneValueDate = new ZoneValueOnDay();
            int?           ValueOnDate   = zoneValueDate.GetUserZoneValueOnGivenDate(_userId, zone, date);

            // if no value value found for the given user/zone/date then return a single zone.
            if (ValueOnDate == null)
            {
                return new List <ZoneValueDto>()
                       {
                           ZoneValueDto.CreateDefault(zone)
                       }
            }
            ;

            // populate zones with the start value.
            var zoneValues = _userZones.Where(z => z.ZoneType == zone)
                             .Select(r => new ZoneValueDto
            {
                ZoneType   = zone,
                ZoneName   = r.ZoneName,
                StartValue = r.ZoneStart * ValueOnDate.Value / 100
            })
                             .OrderBy(z => z.StartValue)
                             .ToList();


            if (zoneValues.Count > 1)
            {
                // calculate the EndValue for the zone based on the start value of the next zone up.
                for (int z = 0; z <= zoneValues.Count - 2; z++)
                {
                    zoneValues[z].EndValue = zoneValues[z + 1].StartValue - 1;
                }
            }

            else if (zoneValues.Count == 1)
            {
                // for the last zone the max value will have no upper limit.
                zoneValues[zoneValues.Count - 1].EndValue = int.MaxValue;
            }

            return(zoneValues);
        }
    }