-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.js
63 lines (54 loc) · 1.85 KB
/
helper.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
export const usersCapacityCalPhases = (scenario) => {
let totalDuration = 0;
let phases = [];
let totalPhasesDuration = 0;
for (let i = 0; i < scenario.length; i++) {
totalDuration += parseDuration(scenario[i].duration);
if (scenario[i].usersCapacityCalcRef) {
let phaseStart = totalDuration - parseDuration(scenario[i].duration);
let phaseEnd = totalDuration;
let phaseTarget = scenario[i].target;
phases.push({ phaseStart, phaseEnd, phaseTarget });
totalPhasesDuration += parseDuration(scenario[i].duration);
}
}
let isConfigured = phases.length > 0;
let totalPhasesDurationInMinutes = totalPhasesDuration / 60;
return { phases, isConfigured, totalPhasesDurationInMinutes };
};
export const logUsersCapacityPhases = (usersCapacityPhases) => {
console.log("USERs CAPACITY CALCs CONFIGs:");
if (usersCapacityPhases.isConfigured) {
usersCapacityPhases.phases.forEach((phase, index) => {
console.log(`Phase ${index + 1} starts at ${phase.phaseStart} seconds and ends at ${phase.phaseEnd} seconds with a target of ${phase.phaseTarget} VUs`);
});
console.log(`Total duration of users capacity phases is: ${usersCapacityPhases.totalPhasesDurationInMinutes} minutes`);
} else {
console.log("This scenario is not configured for user capacity calculation.");
}
};
const parseDuration = (duration) => {
let time = parseInt(duration.slice(0, -1));
let unit = duration.slice(-1);
switch (unit) {
case "s":
return time;
case "m":
return time * 60;
case "h":
return time * 3600;
default:
return 0;
}
};
function arraysEqual(arr1, arr2) {
if (arr1.length !== arr2.length) {
return false;
}
for (let i = 0; i < arr1.length; i++) {
if (arr1[i] !== arr2[i]) {
return false;
}
}
return true;
}