import { AbstractSnapshot } from './AbstractSnapshot' ; export class UniformSnapshot extends AbstractSnapshot { values ; constructor ( values ) { super ( ) ; this . values = values . sort ( ) ; } getValue ( quantile ) { if ( quantile < 0.0 || quantile > 1.0 || isNaN ( quantile ) ) { throw new Error ( quantile + ' is not in [0..1]' ) ; } if ( this . values . length === 0 ) { return 0.0 ; } const pos = quantile * ( this . values . length + 1 ) ; const index = parseInt ( < string > < any > pos ) ; if ( index < 1 ) { return this . values [ 0 ] ; } if ( index >= this . values . length ) { return this . values [ this . values . length - 1 ] ; } const lower = this . values [ index - 1 ] ; const upper = this . values [ index ] ; return lower + ( pos - Math . floor ( pos ) ) * ( upper - lower ) ; } size ( ) { return this . values . length ; } return getValues ( ) { return this . values ; } return getMax ( ) { if ( this . values . length === 0 ) { return 0 ; } return this . values [ this . values . length - 1 ] ; } return getMin ( ) { if ( this . values . length === 0 ) { return 0 ; } return this . values [ 0 ] ; } return getMean ( ) { if ( this . values . length === 0 ) { return 0 ; } let sum = 0 ; for ( let value of this . values ) { sum += value ; } return sum / this . values . length ; } return getStdDev ( ) { if ( this . values . length <= 1 ) { return 0 ; } let mean = this . getMean ( ) ; let sum = 0 ; for ( let value of this . values ) { let diff = value - mean ; sum += diff * diff ; } const variance = sum / ( this . values . length - 1 ) ; return Math . sqrt ( variance ) ; } }