Esempio n. 1
0
        private void CalculateActivity(Activity fvActivity)
        {
            ActivityStreams stream = ActivityStreams.CreateFromExistingActivityStream(fvActivity.Id);

            // stream must have watts to calculate TSS/IF!
            if (!stream.HasIndividualStream(enums.StreamType.Watts))
            {
                return;
            }

            ZoneValueOnDay value = new ZoneValueOnDay();
            var            ftp   = value.GetUserZoneValueOnGivenDate(fvActivity.Athlete.UserId, enums.ZoneType.BikePower, fvActivity.Start);

            if (ftp == null)
            {
                return;
            }

            BikePower calc = new BikePower(stream.GetIndividualStream <int?>(enums.StreamType.Watts), ftp.Value);

            fvActivity.TSS             = calc.TSS();
            fvActivity.IntensityFactor = calc.IntensityFactor();

            _uow.Complete();
        }
Esempio n. 2
0
        /// <summary>
        /// Convert Strava stream information and write to database.
        /// </summary>
        /// <param name="stream">Detailed information for activity in strava format</param>
        private void ConvertStream(List <StravaDotNetStreams.ActivityStream> stream)
        {
            _convertedStream = ActivityStreams.CreateForNewActivity(this._activityId);

            // convert each strava item
            for (int row = 0; row <= stream[0].OriginalSize - 1; row++)
            {
                Stream s = ExtractStreamRow(stream, row);

                // occasinally we get duplicate rows for the same time back from Strava so need to ignore them!
                if (_convertedStream.Stream.Where(c => c.Time == s.Time).Any())
                {
                    System.Diagnostics.Debug.WriteLine(string.Format("Skipping row {0} for activity {1}", s.Time, _activityId));
                    continue;
                }

                _convertedStream.Stream.Add(s);
            }

            _convertedStream.FixGaps();

            _convertedStream.StoreStreams();
            _convertedStream.CalculatePeaksAndSave();

            // we can only calculate a power curve for activities which have a power meter!
            if (_stravaActivity.HasPowerMeter)
            {
                _convertedStream.AddPowerCurveCalculationJobs();
            }
        }
Esempio n. 3
0
        public static PeakSeeker CreatePowerCurve(ActivityStreams stream)
        {
            var individualStream = stream.GetIndividualStream <int?>(StreamType.Watts)
                                   .Select(s => s.Value)
                                   .ToList();

            return(new PeakSeeker(individualStream, PeakStreamType.Power, stream.ActivityId, true));
        }
        private void CalculateStats()
        {
            ActivityStreams.CreateFromExistingActivityStream(_jobDetails.ActivityId.Value)
            .CalculatePeak(StreamType.Watts, _jobDetails.Duration)
            .Save(false);

            _jobDetails.MarkJobComplete();
            _uow.Complete();
        }
Esempio n. 5
0
        public static PeakSeeker Create(ActivityStreams stream, StreamType type)
        {
            var individualStream = stream.GetIndividualStream <int?>(type)
                                   .Select(s => s.Value)
                                   .ToList();

            PeakStreamType peakStream = type == StreamType.Watts ? PeakStreamType.Power :
                                        type == StreamType.Cadence ? PeakStreamType.Cadence : PeakStreamType.HeartRate;

            return(new PeakSeeker(individualStream, peakStream, stream.ActivityId, false));
        }
Esempio n. 6
0
        public ActionResult Recalculate(long?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            ActivityStreams.CreateFromExistingActivityStream(id.Value)
            .CalculatePeaksAndSave();

            return(RedirectToAction("ViewActivity", new { id = id }));
        }
Esempio n. 7
0
        public void ActivityStreams_TestAllTimeRecordsExistWithGap()
        {
            long activityId = 1234L;

            ActivityStreams stream = ActivityStreams.CreateForNewActivity(activityId);

            // check activityId correctly assigned.
            Assert.AreEqual(stream.ActivityId, activityId);

            int itemsAdded = 0;

            // add a block of 100.
            for (int x = 0; x < 100; x++)
            {
                stream.Stream.Add(new Stream()
                {
                    Time = x
                });
                itemsAdded++;
            }

            // and another block but leaving a gap of missing time records.
            for (int x = 105; x < 200; x++)
            {
                stream.Stream.Add(new Stream()
                {
                    Time = x
                });
                itemsAdded++;
            }

            Assert.AreEqual(stream.Stream.Count(), itemsAdded);

            // check we are picking up that there is a gap in the stream.
            Assert.AreEqual(true, stream.GapsInStream());

            // fix the gap.
            stream.FixGaps();

            // and check it's now reporting no gaps.
            Assert.AreEqual(false, stream.GapsInStream());


            // pull out one of the added stream items and check it exists and time/activityId are correct.
            Stream added = stream.Stream.Where(s => s.Time == 101).FirstOrDefault();

            Assert.IsNotNull(added);

            Assert.AreEqual(101, added.Time);
            Assert.AreEqual(activityId, added.ActivityId);
        }
Esempio n. 8
0
        public ActionResult GetActivitySummaryInformation([System.Web.Http.FromUri] SummaryInformationRequest detail)
        {
            ActivityStreams details = ActivityStreams.CreateFromExistingActivityStream(detail.activityId, detail.startIndex, detail.endIndex);

            if (details.UserId != User.Identity.GetUserId())
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            ActivityMinMaxDto mma = new ActivityMinMaxDto(details);

            mma.Populate();
            mma.Label = detail.selection;

            return(PartialView("_ActivitySummaryInformation", mma));
        }
        public static new ActivityDetailDto CreateFromActivity(Activity fvActivity)
        {
            LapDtoRepository  repo = new LapDtoRepository();
            ActivityDetailDto m    = Mapper.Map <ActivityDetailDto>(ActivityDto.CreateFromActivity(fvActivity));

            m.ActivityStream = ActivityStreams.CreateFromExistingActivityStream(fvActivity.Id);// uow.Activity.GetActivityStream(fvActivity.Id);

            m.Laps      = repo.GetLaps(fvActivity.Id);
            m.HeartRate = repo.GetLapStream(fvActivity.Id, PeakStreamType.HeartRate);
            m.Cadence   = repo.GetLapStream(fvActivity.Id, PeakStreamType.Cadence);

            ActivityMinMaxDto mma = new ActivityMinMaxDto(m.ActivityStream);

            mma.Populate();
            m.SummaryInfo = mma;

            m.Analytics = m.SummaryInfo.Analytics;

            ActivityZones zones = new ActivityZones(m);

            if (m.IsRun)
            {
                m.HeartRateZones = zones.GetZoneValues(ZoneType.RunHeartRate);
                m.RunPaceZones   = zones.GetZoneValues(ZoneType.RunPace);
                m.PaceByDistance = repo.GetBestEffort(fvActivity.Id);
            }
            else if (m.IsRide)
            {
                m.HeartRateZones = zones.GetZoneValues(ZoneType.BikeHeartRate);

                if (m.HasPowerMeter)
                {
                    m.Power      = repo.GetLapStream(fvActivity.Id, PeakStreamType.Power);
                    m.PowerZones = zones.GetZoneValues(ZoneType.BikePower);  // uow.Settings.GetZoneValues(m, ZoneType.BikePower);
                }
            }
            else if (m.IsSwim)
            {
            }


            return(m);
        }
Esempio n. 10
0
        public void ActivityStreams_TestAllTimeRecordsExistNoGap()
        {
            long activityId = 1234L;

            ActivityStreams s = ActivityStreams.CreateForNewActivity(activityId);

            // check activityId correctly assigned.
            Assert.AreEqual(s.ActivityId, activityId);

            int itemsAdded = 0;

            for (int x = 0; x < 100; x++)
            {
                s.Stream.Add(new Stream()
                {
                    Time = x
                });
                itemsAdded++;
            }

            Assert.AreEqual(s.Stream.Count(), itemsAdded);
            Assert.AreEqual(false, s.GapsInStream());
        }
Esempio n. 11
0
 public HeartRateTss(ActivityStreams activity)
 {
     _activity = activity;
 }
 public ActivityMinMaxDto(ActivityStreams activityStreams)
 {
     _activityStreams = activityStreams;
     StreamSummary    = new List <MinMaxAve>();
 }