mirror of
https://github.com/gchq/CyberChef.git
synced 2024-11-16 00:48:31 +01:00
Only show bake stats when theres more than 1 input
Better handle canceling a bake when inputs are loading Don't create chefworkers if we don't need them Fix capitalisation of bake stats
This commit is contained in:
parent
b3cb800f35
commit
89c4f54ce8
1 changed files with 57 additions and 26 deletions
|
@ -324,6 +324,7 @@ class WorkerWaiter {
|
||||||
this.inputs = [];
|
this.inputs = [];
|
||||||
this.inputNums = [];
|
this.inputNums = [];
|
||||||
this.totalOutputs = 0;
|
this.totalOutputs = 0;
|
||||||
|
this.loadingOutputs = 0;
|
||||||
if (!silent) this.manager.output.set(this.manager.output.getActiveTab());
|
if (!silent) this.manager.output.set(this.manager.output.getActiveTab());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -359,18 +360,37 @@ class WorkerWaiter {
|
||||||
duration = duration.toLocaleString() + "ms";
|
duration = duration.toLocaleString() + "ms";
|
||||||
const progress = this.getBakeProgress();
|
const progress = this.getBakeProgress();
|
||||||
|
|
||||||
let width = progress.total.toString().length;
|
if (progress.total > 1) {
|
||||||
if (duration.length > width) {
|
let width = progress.total.toLocaleString().length;
|
||||||
width = duration.length;
|
if (duration.length > width) {
|
||||||
|
width = duration.length;
|
||||||
|
}
|
||||||
|
width = width < 2 ? 2 : width;
|
||||||
|
|
||||||
|
const totalStr = progress.total.toLocaleString().padStart(width, " ").replace(/ /g, " ");
|
||||||
|
const durationStr = duration.padStart(width, " ").replace(/ /g, " ");
|
||||||
|
|
||||||
|
const inputNums = Object.keys(this.manager.output.outputs);
|
||||||
|
let avgTime = 0,
|
||||||
|
numOutputs = 0;
|
||||||
|
for (let i = 0; i < inputNums.length; i++) {
|
||||||
|
const output = this.manager.output.outputs[inputNums[i]];
|
||||||
|
if (output.status === "baked") {
|
||||||
|
numOutputs++;
|
||||||
|
avgTime += output.data.duration;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
avgTime = Math.round(avgTime / numOutputs).toLocaleString() + "ms";
|
||||||
|
avgTime = avgTime.padStart(width, " ").replace(/ /g, " ");
|
||||||
|
|
||||||
|
const msg = `total: ${totalStr}<br>time: ${durationStr}<br>average: ${avgTime}`;
|
||||||
|
|
||||||
|
const bakeInfo = document.getElementById("bake-info");
|
||||||
|
bakeInfo.innerHTML = msg;
|
||||||
|
bakeInfo.style.display = "";
|
||||||
|
} else {
|
||||||
|
document.getElementById("bake-info").style.display = "none";
|
||||||
}
|
}
|
||||||
width = width < 2 ? 2 : width;
|
|
||||||
|
|
||||||
const totalStr = progress.total.toLocaleString().padStart(width, " ").replace(/ /g, " ");
|
|
||||||
const durationStr = duration.padStart(width, " ").replace(/ /g, " ");
|
|
||||||
|
|
||||||
const msg = `Total: ${totalStr}<br>Time: ${durationStr}`;
|
|
||||||
|
|
||||||
document.getElementById("bake-info").innerHTML = msg;
|
|
||||||
document.getElementById("bake").style.background = "";
|
document.getElementById("bake").style.background = "";
|
||||||
this.totalOutputs = 0; // Reset for next time
|
this.totalOutputs = 0; // Reset for next time
|
||||||
log.debug("--- Bake complete ---");
|
log.debug("--- Bake complete ---");
|
||||||
|
@ -518,7 +538,14 @@ class WorkerWaiter {
|
||||||
this.inputNums = inputNums;
|
this.inputNums = inputNums;
|
||||||
this.totalOutputs = inputNums.length;
|
this.totalOutputs = inputNums.length;
|
||||||
|
|
||||||
for (let i = 0; i < inputNums.length; i++) {
|
let inactiveWorkers = 0;
|
||||||
|
for (let i = 0; i < this.chefWorkers.length; i++) {
|
||||||
|
if (!this.chefWorkers[i].active) {
|
||||||
|
inactiveWorkers++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = 0; i < inputNums.length - inactiveWorkers; i++) {
|
||||||
if (this.addChefWorker() === -1) break;
|
if (this.addChefWorker() === -1) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -626,25 +653,29 @@ class WorkerWaiter {
|
||||||
}
|
}
|
||||||
|
|
||||||
const bakeInfo = document.getElementById("bake-info");
|
const bakeInfo = document.getElementById("bake-info");
|
||||||
let width = progress.total.toLocaleString().length;
|
if (progress.total > 1) {
|
||||||
width = width < 2 ? 2 : width;
|
let width = progress.total.toLocaleString().length;
|
||||||
|
width = width < 2 ? 2 : width;
|
||||||
|
|
||||||
const totalStr = progress.total.toLocaleString().padStart(width, " ").replace(/ /g, " ");
|
const totalStr = progress.total.toLocaleString().padStart(width, " ").replace(/ /g, " ");
|
||||||
const bakedStr = progress.baked.toLocaleString().padStart(width, " ").replace(/ /g, " ");
|
const bakedStr = progress.baked.toLocaleString().padStart(width, " ").replace(/ /g, " ");
|
||||||
const pendingStr = progress.pending.toLocaleString().padStart(width, " ").replace(/ /g, " ");
|
const pendingStr = progress.pending.toLocaleString().padStart(width, " ").replace(/ /g, " ");
|
||||||
const bakingStr = progress.baking.toLocaleString().padStart(width, " ").replace(/ /g, " ");
|
const bakingStr = progress.baking.toLocaleString().padStart(width, " ").replace(/ /g, " ");
|
||||||
|
|
||||||
let msg = "Total: " + totalStr;
|
let msg = "total: " + totalStr;
|
||||||
msg += "<br>Baked: " + bakedStr;
|
msg += "<br>baked: " + bakedStr;
|
||||||
|
|
||||||
if (progress.pending > 0) {
|
if (progress.pending > 0) {
|
||||||
msg += "<br>Pending: " + pendingStr;
|
msg += "<br>pending: " + pendingStr;
|
||||||
} else if (progress.baking > 0) {
|
} else if (progress.baking > 0) {
|
||||||
msg += "<br>Baking: " + bakingStr;
|
msg += "<br>baking: " + bakingStr;
|
||||||
|
}
|
||||||
|
bakeInfo.innerHTML = msg;
|
||||||
|
bakeInfo.style.display = "";
|
||||||
|
} else {
|
||||||
|
bakeInfo.style.display = "none";
|
||||||
}
|
}
|
||||||
|
|
||||||
bakeInfo.innerHTML = msg;
|
|
||||||
|
|
||||||
if (progress.total !== progress.baked) {
|
if (progress.total !== progress.baked) {
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
this.displayProgress();
|
this.displayProgress();
|
||||||
|
|
Loading…
Reference in a new issue