lib/progress.ts: get an external reviewer for the default estimation algorithm #76
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
i think it is implemented in a buggy way. i gave it some tests in an isolated place, but not too much on real world cases.
/*** Exponential Moving Average.* this is the algorithm used for the default progress estimator.* https://en.wikipedia.org/wiki/Exponential_smoothing*/export class Ema implements EstimationAlgorithm {start: number | null = null;estimate: number | null = null;/** smoothing factor (0-1) */alpha: number = 0.25;constructor(alpha: number = 0.1) {this.alpha = alpha;}/*** given a timestamp `time` and a progress value `progress`, return the* timestamp that the action will be finished on.*/sample(time: number, progress: number): number | null {ASSERT(progress >= 0 && progress < 1,`progress must be a number between 0 and 1, got ${progress}`,);if (this.start == null) {this.start = time;return null;}const value = (time - this.start) / progress;this.estimate = this.estimate != null? ((1 - this.alpha) * this.estimate +this.alpha * value): value;return time + (1 - progress) * this.estimate;}reset(): void {this.start = null;this.estimate = null;}}my suspicion is that the api interface should be
sample(time: number, current: number, total: number)where both numbers must be >= 0 and current < total