MCPcopy Create free account
hub / github.com/npkgz/cli-progress / calculate

Method calculate

lib/eta.js:32–70  ·  view source on GitHub ↗
(remaining)

Source from the content-addressed store, hash-verified

30
31 // eta calculation - request number of remaining events
32 calculate(remaining){
33 // get number of samples in eta buffer
34 const currentBufferSize = this.valueBuffer.length;
35 const buffer = Math.min(this.etaBufferLength, currentBufferSize);
36
37 const v_diff = this.valueBuffer[currentBufferSize - 1] - this.valueBuffer[currentBufferSize - buffer];
38 const t_diff = this.timeBuffer[currentBufferSize - 1] - this.timeBuffer[currentBufferSize - buffer];
39
40 // get progress per ms
41 const vt_rate = v_diff/t_diff;
42
43 // strip past elements
44 this.valueBuffer = this.valueBuffer.slice(-this.etaBufferLength);
45 this.timeBuffer = this.timeBuffer.slice(-this.etaBufferLength);
46
47 // eq: vt_rate *x = total
48 const eta = Math.ceil(remaining/vt_rate/1000);
49
50 // check values
51 if (isNaN(eta)){
52 this.eta = 'NULL';
53
54 // +/- Infinity --- NaN already handled
55 }else if (!isFinite(eta)){
56 this.eta = 'INF';
57
58 // > 10M s ? - set upper display limit ~115days (1e7/60/60/24)
59 }else if (eta > 1e7){
60 this.eta = 'INF';
61
62 // negative ?
63 }else if (eta < 0){
64 this.eta = 0;
65
66 }else{
67 // assign
68 this.eta = eta;
69 }
70 }
71}
72
73module.exports = ETA;

Callers 1

updateMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected