Пример #1
0
        public IEnumerable <LapDto> GetLapStream(long activityId, PeakStreamType streamType)
        {
            // string units = DisplayLabel.PeakStreamTypeUnits(streamType);

            var result = _context.ActivityPeakDetail
                         .Where(p => p.ActivityId == activityId && p.StreamType == streamType &&
                                _context.PeakStreamTypeDuration
                                .Where(d => d.PeakStreamType == p.StreamType)
                                .Select(d => d.Duration)
                                .ToList()
                                .Contains(p.Duration)
                                )
                         .OrderBy(p => p.Duration)
                         .Select(p => new LapDto
            {
                Id                = p.Id,
                Type              = streamType,
                Selected          = false,
                Name              = p.Duration.ToString(),
                Value             = p.Value.ToString(),
                StartIndex        = p.StartIndex.Value,
                EndIndex          = p.EndIndex.Value,
                StreamStep        = p.Activity.StreamStep,
                SteppedStartIndex = p.StartIndex.Value / p.Activity.StreamStep,
                SteppedEndIndex   = p.EndIndex.Value / p.Activity.StreamStep,
            }).ToList();

            foreach (LapDto l in result)
            {
                l.Name = DisplayLabel.StreamDurationForDisplay(Convert.ToInt32(l.Name));
            }
            return(result);
        }
Пример #2
0
        public PeaksDto ExtractPeaksByDays(PeakStreamType type, /*IQueryable<ActivityPeaks> peaks,*/ int days)
        {
            // days=int.maxvalue is used for earlist date
            DateTime earliestDate = days == int.MaxValue ? DateTime.MinValue.Date : DateTime.Now.AddDays(days * -1).Date;

            return(ExtractPeaks(type, /*peaks,*/ earliestDate, DateTime.Now.Date));
        }
Пример #3
0
 public ActivityPeakDetail(long activityId, PeakStreamType type, int duration)
 {
     this.ActivityId = activityId;
     this.Duration   = duration;
     this.Value      = null;
     this.StartIndex = null;
     this.StreamType = type;
 }
Пример #4
0
        /// <summary>
        /// Return Peak information for common time duration
        /// </summary>
        /// <param name="userId">Indentity</param>
        /// <param name="type">Stream Type to analyse</param>
        /// <returns></returns>
        public IEnumerable <PeaksDto> GetPeaks(string userId, PeakStreamType type)
        {
            UserId = userId;

            return(new[] { ExtractPeaksByDays(type /*, peaks*/, 7),
                           ExtractPeaksByDays(type /*, peaks*/, 30),
                           ExtractPeaksByDays(type /*, peaks*/, 90),
                           ExtractPeaksByDays(type /*, peaks*/, 365),
                           ExtractPeaksByDays(type /*, peaks*/, int.MaxValue) });
        }
Пример #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));
        }
Пример #6
0
        private PeakDuration(PeakStreamType streamType, int?streamSize)
        {
            _streamType = streamType;

            if (streamSize == null)
            {
                _standardDurations = SetupDurations();
            }
            else
            {
                _standardDurations = SetupPowerCurveDurations(streamSize.Value);
            }
        }
Пример #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="stream">Stream to be analysed for peaks.</param>
        /// <param name="type">Type of stream (power, HR, cadence)</param>
        /// <param name="activityId">Activity Id.</param>
        private PeakSeeker(List <int> stream, PeakStreamType type, long activityId, bool usePowerCurveDurations)
        {
            _streamType = type;
            _activityId = activityId;

            // for cadence peaks we ignore 0 values to exclude times when stationary so strip out now.
            _data = stream.Where(d => _streamType == PeakStreamType.Cadence ? d > 0 : true).ToArray();

            if (usePowerCurveDurations)
            {
                _durations = PeakDuration.CreatePowerCurveDurations(_data.Count()).Durations;
            }
            else
            {
                _durations = PeakDuration.Create(_streamType).Durations;
            }
        }
Пример #8
0
        public static string PeakStreamTypeUnits(PeakStreamType type)
        {
            switch (type)
            {
            case PeakStreamType.Cadence: return("rpm");

            case PeakStreamType.HeartRate: return("bpm");

            case PeakStreamType.Lap: return("");

            case PeakStreamType.Power: return("w");

            case PeakStreamType.Speed: return("mph");

            case PeakStreamType.Elevation: return("ft");

            default: return("");
            }
        }
Пример #9
0
 public ActivityPeakDetail(long activityId, PeakStreamType type)
 {
     this.ActivityId = activityId;
     this.StreamType = type;
 }
Пример #10
0
 public ActivityPeakDetailCalculator(long activityId, PeakStreamType type, int duration) : base(activityId, type, duration)
 {
 }
Пример #11
0
 public static PeakSeeker Create(List <int> stream, PeakStreamType type, long activityId)
 {
     return(new PeakSeeker(stream, type, activityId, false));
 }
        public void AddPeaks(List <ActivityPeakDetail> peaks)
        {
            if ((peaks == null) || (peaks.Count == 0))
            {
                return;
            }

            long           activityId = peaks[0].ActivityId;
            PeakStreamType type       = peaks[0].StreamType;


            var existingPeaks = _unitOfWork.CRUDRepository.GetByActivityId <ActivityPeaks>(activityId).Where(a => a.StreamType == type).ToList();

            if (existingPeaks.Count > 0)
            {
                _unitOfWork.CRUDRepository.DeleteRange <ActivityPeaks>(existingPeaks);
            }

            var existingPeakDetail = _unitOfWork.CRUDRepository.GetByActivityId <ActivityPeakDetail>(activityId)
                                     .Where(a => a.StreamType == type).ToList();

            if (existingPeakDetail.Count > 0)
            {
                _unitOfWork.CRUDRepository.DeleteRange <ActivityPeakDetail>(existingPeakDetail);
            }

            ActivityPeaks stravaPeak = new ActivityPeaks()
            {
                ActivityId = activityId, StreamType = type
            };

            foreach (ActivityPeakDetail d in peaks)
            {
                switch (d.Duration)
                {
                case 5: { stravaPeak.Peak5 = d.Value; break; }

                case 10: { stravaPeak.Peak10 = d.Value; break; }

                case 30: { stravaPeak.Peak30 = d.Value; break; }

                case 60: { stravaPeak.Peak60 = d.Value; break; }

                case 120: { stravaPeak.Peak120 = d.Value; break; }

                case 300: { stravaPeak.Peak300 = d.Value; break; }

                case 360: { stravaPeak.Peak360 = d.Value; break; }

                case 600: { stravaPeak.Peak600 = d.Value; break; }

                case 720: { stravaPeak.Peak720 = d.Value; break; }

                case 1200: { stravaPeak.Peak1200 = d.Value; break; }

                case 1800: { stravaPeak.Peak1800 = d.Value; break; }

                case 3600: { stravaPeak.Peak3600 = d.Value; break; }

                case int.MaxValue: { stravaPeak.PeakDuration = d.Value; break; }
                }

                _unitOfWork.CRUDRepository.Add <ActivityPeakDetail>(d);
            }

            _unitOfWork.CRUDRepository.Add <ActivityPeaks>(stravaPeak);
        }
Пример #13
0
 public static PeakDuration Create(PeakStreamType type)
 {
     return(new PeakDuration(type, null));
 }
Пример #14
0
        public PeaksDto ExtractPeaks(PeakStreamType type, /*IQueryable<ActivityPeaks> peaks,*/ DateTime start, DateTime end)
        {
            if (string.IsNullOrEmpty(UserId))
            {
                throw new ArgumentException("UserId invalid");
            }

            var peaks = _context.ActivityPeak
                        .Where(p => p.Activity.Athlete.UserId == UserId && p.StreamType == type)
                        .Include(p => p.Activity);


            PeaksDto ap = new PeaksDto();

            ap.PeakType = type;

            // DateTime.MinValue = all activities so need to set days to int.maxValue so that the client can identify it as all days/activities.
            if (start == DateTime.MinValue)
            {
                ap.Days = int.MaxValue;
            }
            else
            {
                ap.Days = Convert.ToInt32(end.Subtract(start).TotalDays);
            }

            ap.DurationPeaks.Add(peaks.Where(p => p.Activity.Start >= start && p.Activity.Start <= end)
                                 .OrderByDescending(p => p.Peak5)
                                 .Select(p => new PeaksDetailDto()
            {
                Duration = 5, Peak = p.Peak5, ActivityId = p.ActivityId, Description = p.Activity.Name
            })
                                 .FirstOrDefault());

            ap.DurationPeaks.Add(peaks.Where(p => p.Activity.Start >= start && p.Activity.Start <= end)
                                 .OrderByDescending(p => p.Peak60)
                                 .Select(p => new PeaksDetailDto()
            {
                Duration = 60, Peak = p.Peak60, ActivityId = p.ActivityId, Description = p.Activity.Name
            })
                                 .FirstOrDefault());

            ap.DurationPeaks.Add(peaks.Where(p => p.Activity.Start >= start && p.Activity.Start <= end)
                                 .OrderByDescending(p => p.Peak300)
                                 .Select(p => new PeaksDetailDto()
            {
                Duration = 300, Peak = p.Peak300, ActivityId = p.ActivityId, Description = p.Activity.Name
            })
                                 .FirstOrDefault());

            ap.DurationPeaks.Add(peaks.Where(p => p.Activity.Start >= start && p.Activity.Start <= end)
                                 .OrderByDescending(p => p.Peak1200)
                                 .Select(p => new PeaksDetailDto()
            {
                Duration = 1200, Peak = p.Peak1200, ActivityId = p.ActivityId, Description = p.Activity.Name
            })
                                 .FirstOrDefault());

            ap.DurationPeaks.Add(peaks.Where(p => p.Activity.Start >= start && p.Activity.Start <= end)
                                 .OrderByDescending(p => p.Peak3600)
                                 .Select(p => new PeaksDetailDto()
            {
                Duration = 3600, Peak = p.Peak3600, ActivityId = p.ActivityId, Description = p.Activity.Name
            })
                                 .FirstOrDefault());

            return(ap);
        }