public void TestSimpleNotFullStaticAverage()
 {
     var sma = new SimpleMovingAverage(5);
     sma.Add(3);
     sma.Add(4);
     sma.Add(2);
     sma.Add(3);
     var average = sma.Average();
     Assert.Equal(3, average);
 }
        public void TestSimpleNotFullStaticAverage()
        {
            var sma = new SimpleMovingAverage(5);

            sma.Add(3);
            sma.Add(4);
            sma.Add(2);
            sma.Add(3);
            var average = sma.Average();

            Assert.Equal(3, average);
        }
 public void TestSimpleMovingAverage()
 {
     var sma = new SimpleMovingAverage(5);
     sma.Add(10);
     sma.Add(55);
     sma.Add(33);
     sma.Add(56);
     sma.Add (88);
     sma.Add(23);
     var average = sma.Average();
     Assert.Equal(51, average);
 }
        public void TestSimpleMovingAverage()
        {
            var sma = new SimpleMovingAverage(5);

            sma.Add(10);
            sma.Add(55);
            sma.Add(33);
            sma.Add(56);
            sma.Add(88);
            sma.Add(23);
            var average = sma.Average();

            Assert.Equal(51, average);
        }
        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);
        }