コード例 #1
0
        public void CalculateNonZero_Average_With_No_Data_Returns_Zero()
        {
            var      samples           = new WorkoutSamples(0);
            var      vector            = new WorkoutSampleVector(3, WorkoutSampleDataType.Power);
            IAthlete athlete           = new Athlete();
            var      workoutCalculator = new WorkoutSamplesCalculator(samples, athlete);
            var      average           = workoutCalculator.CalculateNonZeroVectorAverage(vector);

            Assert.Equal(0, average);
        }
コード例 #2
0
        public void CalculatCadenceClassificatoion_Under_2_Samples_returns_()
        {
            var samples = new WorkoutSamples(0);
            var vector  = new WorkoutSampleVector(1, WorkoutSampleDataType.Cadence);

            vector.AddPoint(1, 2);
            samples.CadenceVector = vector;
            IAthlete athlete           = new Athlete();
            var      workoutCalculator = new WorkoutSamplesCalculator(samples, athlete);
            var      classification    = workoutCalculator.ClassifyWorkoutCadenceRanges();

            Assert.IsType <List <ICadenceRange> >(classification);
        }
コード例 #3
0
        public void CalculateNonZero_Average_Returns_Average()
        {
            var samples = new WorkoutSamples(0);
            var vector  = new WorkoutSampleVector(3, WorkoutSampleDataType.Power);

            vector.AddPoint(1, 2);
            vector.AddPoint(2, 4);
            vector.AddPoint(3, 0);
            IAthlete athlete           = new Athlete();
            var      workoutCalculator = new WorkoutSamplesCalculator(samples, athlete);
            var      average           = workoutCalculator.CalculateNonZeroVectorAverage(vector);

            Assert.Equal(3, average);
        }
コード例 #4
0
        public void CalculateNormalizedPower_With_Under_30_Samples_Returns_Average()
        {
            //Initialise();
            var samples = new WorkoutSamples(0);
            var vector  = new WorkoutSampleVector(2, WorkoutSampleDataType.Power);

            vector.AddPoint(1, 2);
            vector.AddPoint(2, 4);
            IAthlete athlete           = new Athlete();
            var      workoutCalculator = new WorkoutSamplesCalculator(samples, athlete);
            var      average           = workoutCalculator.CalculateVectorNormalizedAverage(vector);

            Assert.Equal(3, average);
        }
コード例 #5
0
        public double CalculateVectorNormalizedAverage(WorkoutSampleVector vector)
        {
            if (!vector.HasData)
            {
                return(0);
            }
            if (vector.NumberOfSamples < 30)
            {
                return(CalculateVectorAverage(vector));
            }

            var    movingAverageBuffer  = new SimpleMovingAverage(30);
            double movingAverage        = 0;
            var    movingAverageSamples = 1;

            movingAverageBuffer.Add(vector.Vector[0].dataPoint);

            for (var i = 1; i < vector.NumberOfSamples; i++)
            {
                if (vector.Vector[i].dataPoint < 0)
                {
                    continue;
                }
                var timeDiff = vector.Vector[i].timeOffsetSeconds - vector.Vector[i - 1].timeOffsetSeconds;
                for (var j = 0; j < timeDiff; j++)
                //Cannot multiply value across time in the sample as we need a 30s moving avg.
                {
                    movingAverageBuffer.Add(vector.Vector[i].dataPoint);
                    if (movingAverageBuffer.NumberOfSamples >= 30)
                    {
                        movingAverage += Math.Pow(Math.Round(movingAverageBuffer.Average()), 4);
                        movingAverageSamples++;
                    }
                }
            }
            var average = movingAverage / movingAverageSamples;

            average = Math.Round(Math.Pow(average, 0.25));
            return(average);
        }
コード例 #6
0
        internal double CalculateVectorAverage(WorkoutSampleVector vector)
        {
            if (!vector.HasData)
            {
                return(0);
            }
            var weightedCumulative = vector.Vector[0].dataPoint;

            for (var i = 1; i < vector.NumberOfSamples; i++)
            {
                if (vector.Vector[i].dataPoint <= 0)
                {
                    continue;
                }
                var timeDiff = vector.Vector[i].timeOffsetSeconds - vector.Vector[i - 1].timeOffsetSeconds;
                weightedCumulative = weightedCumulative + timeDiff * vector.Vector[i].dataPoint;
            }
            var divisor = vector.Vector[vector.NumberOfSamples - 1].timeOffsetSeconds;

            var average = weightedCumulative / divisor;

            return(Math.Round(average));
        }
コード例 #7
0
        internal IEnumerable <IRange> ClassifyWorkoutCadenceType(IEnumerable <IRange> ranges, WorkoutSampleVector vector, double referenceValue)
        {
            if (vector.NumberOfSamples < 2)
            {
                return(ranges);
            }
            var rangeList = ranges as IList <IRange> ?? ranges.ToList();

            ClassifyCadenceDataPoint(vector.Vector[0].dataPoint, rangeList, referenceValue);
            for (var i = 1; i < vector.NumberOfSamples; i++)
            {
                if (!(vector.Vector[i].dataPoint >= 0))
                {
                    continue;
                }
                var timeDiff = vector.Vector[i].timeOffsetSeconds -
                               vector.Vector[i - 1].timeOffsetSeconds;
                for (var j = 0; j < timeDiff; j++)
                {
                    ClassifyCadenceDataPoint(vector.Vector[i].dataPoint, rangeList, referenceValue);
                }
            }
            var totalSamples = rangeList.Sum(range => range.QuanityOfSamples);

            foreach (var range in rangeList)
            {
                var percent = range.QuanityOfSamples / (double)totalSamples * 100;
                range.PercentOfTotal = Math.Round(percent);
            }
            return(rangeList);
        }