import { CircularBuffer } from './providers/circular-buffer' ; export class StandardDeviation { private values : CircularBuffer ; constructor ( private period ) { this . values = new CircularBuffer ( period ) ; } nextValue ( value , mean ? ) { this . values . push ( value ) ; return Math . sqrt ( this . values . toArray ( ) . reduce ( ( acc , item ) => acc + ( item - mean ) ** 2 , 0 ) / this . period ) ; } momentValue ( value , mean ? ) { const rm = this . values . push ( value ) ; const result = Math . sqrt ( this . values . toArray ( ) . reduce ( ( acc , item ) => acc + ( item - mean ) ** 2 , 0 ) / this . period ) ; this . values . pushback ( rm ) ; return result ; } calculate ( values , value , mean ? ) { } }