30 lines
No EOL
640 B
TypeScript
30 lines
No EOL
640 B
TypeScript
import * as math from 'mathjs';
|
|
import * as _ from 'lodash';
|
|
|
|
export class RollingWindow {
|
|
private windows: number[][];
|
|
|
|
constructor(windows: number[][]) {
|
|
this.windows = windows;
|
|
}
|
|
|
|
mean(): number[] {
|
|
return this.windows.map(window => Number(math.mean(window)));
|
|
}
|
|
|
|
sum(): number[] {
|
|
return this.windows.map(window => _.sum(window));
|
|
}
|
|
|
|
min(): number[] {
|
|
return this.windows.map(window => Math.min(...window));
|
|
}
|
|
|
|
max(): number[] {
|
|
return this.windows.map(window => Math.max(...window));
|
|
}
|
|
|
|
toArray(): number[][] {
|
|
return this.windows;
|
|
}
|
|
} |