-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogress.js
69 lines (59 loc) · 1.58 KB
/
progress.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"use strict";
/**
* Class keeps track of Loader progress for a run
*/
class Progress {
constructor(profiles) {
this.profiles = {};
for (var i in profiles) {
var profile = profiles[i];
this.addProfile(profile.name, profile.iterations);
}
}
addProfile(name, total){
if(total > 0)
this.profiles[name] = {
total: total,
started: 0,
complete: 0,
error: 0,
time: 0
};
}
startProfile(name){
this.profiles[name].started++;
}
profileComplete(name, time){
this.profiles[name].complete++;
this.profiles[name].time += time;
}
profileError(name, time){
this.profiles[name].error++;
this.profiles[name].time += time;
}
get totals(){
var totals = {
complete: 0,
error: 0,
total: 0,
time: 0
};
for(var i in this.profiles){
totals.total += this.profiles[i].total;
totals.error += this.profiles[i].error;
totals.complete += this.profiles[i].complete;
totals.time += this.profiles[i].time;
}
return totals;
}
totalProgress(){
var total = 0;
var totalComplete = 0
for(var i in this.profiles){
total += this.profiles[i].total;
totalComplete += this.profiles[i].complete + this.profiles[i].error
}
return parseFloat(totalComplete) / total;
};
}
module.exports = Progress;