@vbarbarosh/node-helpers 3.18.0 → 3.18.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/make_progress.js +9 -12
package/package.json
CHANGED
package/src/make_progress.js
CHANGED
|
@@ -21,10 +21,9 @@ function make_progress(total)
|
|
|
21
21
|
progress: null,
|
|
22
22
|
percents: null,
|
|
23
23
|
add: function (delta = 0) {
|
|
24
|
-
const
|
|
24
|
+
const now_minus_10sec = Date.now() - 10000;
|
|
25
|
+
history.splice(0, history.findLastIndex(v => v.time < now_minus_10sec));
|
|
25
26
|
history.push({time: Date.now(), delta});
|
|
26
|
-
// Keep last 5 seconds
|
|
27
|
-
history.splice(0, history.findLastIndex(v => v.time < now_minus_5sec));
|
|
28
27
|
out.done += delta;
|
|
29
28
|
out.refresh();
|
|
30
29
|
},
|
|
@@ -32,19 +31,17 @@ function make_progress(total)
|
|
|
32
31
|
out.add(done - out.done);
|
|
33
32
|
},
|
|
34
33
|
refresh: function () {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
|
|
34
|
+
out.duration = (Date.now() - time0)/1000;
|
|
35
|
+
out.percents = !out.total ? null : out.done/out.total;
|
|
36
|
+
out.eta = !out.total ? null : (out.total - out.done)/out.rate;
|
|
37
|
+
if (history.length) {
|
|
38
|
+
const delta = history.reduce((a,v) => a + v.delta, 0);
|
|
39
|
+
const time_sec = (Date.now() - history[0].time)/1000;
|
|
40
|
+
out.rate = delta/time_sec;
|
|
41
41
|
}
|
|
42
42
|
else {
|
|
43
43
|
out.rate = out.done/out.duration;
|
|
44
44
|
}
|
|
45
|
-
out.duration = (Date.now() - time0)/1000;
|
|
46
|
-
out.percents = !out.total ? null : out.done/out.total;
|
|
47
|
-
out.eta = !out.total ? null : (out.total - out.done)/out.rate;
|
|
48
45
|
},
|
|
49
46
|
};
|
|
50
47
|
return out;
|