Sha256: 774e1a02fa01df305a569c33fb820922f69305a87ab06e3bc76f8e3606d95f12

Contents?: true

Size: 1.93 KB

Versions: 21

Compression:

Stored size: 1.93 KB

Contents

// ETA calculation
class ETA{

    constructor(length, initTime, initValue){
        // size of eta buffer
        this.etaBufferLength = length || 100;

        // eta buffer with initial values
        this.valueBuffer = [initValue];
        this.timeBuffer = [initTime];

        // eta time value
        this.eta = '0';
    }

    // add new values to calculation buffer
    update(time, value, total){
        this.valueBuffer.push(value);
        this.timeBuffer.push(time);

        // trigger recalculation
        this.calculate(total-value);
    }

    // fetch estimated time
    getTime(){
        return this.eta;
    }

    // eta calculation - request number of remaining events
    calculate(remaining){
        // get number of samples in eta buffer
        const currentBufferSize = this.valueBuffer.length;
        const buffer = Math.min(this.etaBufferLength, currentBufferSize);

        const v_diff = this.valueBuffer[currentBufferSize - 1] - this.valueBuffer[currentBufferSize - buffer];
        const t_diff = this.timeBuffer[currentBufferSize - 1] - this.timeBuffer[currentBufferSize - buffer];

        // get progress per ms
        const vt_rate = v_diff/t_diff;

        // strip past elements
        this.valueBuffer = this.valueBuffer.slice(-this.etaBufferLength);
        this.timeBuffer  = this.timeBuffer.slice(-this.etaBufferLength);

        // eq: vt_rate *x = total
        const eta = Math.ceil(remaining/vt_rate/1000);

        // check values
        if (isNaN(eta)){
            this.eta = 'NULL';

        // +/- Infinity --- NaN already handled
        }else if (!isFinite(eta)){
            this.eta = 'INF';

        // > 10M s ? - set upper display limit ~115days (1e7/60/60/24)
        }else if (eta > 1e7){
            this.eta = 'INF';

        // negative ?
        }else if (eta < 0){
            this.eta = 0;

        }else{
            // assign
            this.eta = eta;
        }
    }
}

module.exports = ETA;

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
appmap-0.72.2 ./node_modules/cli-progress/lib/eta.js
appmap-0.72.1 ./node_modules/cli-progress/lib/eta.js
appmap-0.72.0 ./node_modules/cli-progress/lib/eta.js
appmap-0.71.0 ./node_modules/cli-progress/lib/eta.js
appmap-0.70.2 ./node_modules/cli-progress/lib/eta.js
appmap-0.70.1 ./node_modules/cli-progress/lib/eta.js
appmap-0.70.0 ./node_modules/cli-progress/lib/eta.js
appmap-0.69.0 ./node_modules/cli-progress/lib/eta.js
appmap-0.68.2 ./node_modules/cli-progress/lib/eta.js
appmap-0.68.1 ./node_modules/cli-progress/lib/eta.js
appmap-0.68.0 ./node_modules/cli-progress/lib/eta.js
appmap-0.67.1 ./node_modules/cli-progress/lib/eta.js
appmap-0.67.0 ./node_modules/cli-progress/lib/eta.js
appmap-0.66.2 ./node_modules/cli-progress/lib/eta.js
appmap-0.66.1 ./node_modules/cli-progress/lib/eta.js
appmap-0.66.0 ./node_modules/cli-progress/lib/eta.js
appmap-0.65.1 ./node_modules/cli-progress/lib/eta.js
appmap-0.65.0 ./node_modules/cli-progress/lib/eta.js
appmap-0.64.0 ./node_modules/cli-progress/lib/eta.js
appmap-0.63.0 ./node_modules/cli-progress/lib/eta.js