Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎨 Image pulling downloaded sizes when available #5712

Merged
merged 6 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1330,10 +1330,10 @@ qx.Class.define("osparc.data.model.Node", {
});
},

setNodeProgressSequence: function(progressType, progress) {
setNodeProgressSequence: function(progressType, progressReport) {
const nodeStatus = this.getStatus();
if (nodeStatus.getProgressSequence()) {
nodeStatus.getProgressSequence().addProgressMessage(progressType, progress);
nodeStatus.getProgressSequence().addProgressMessage(progressType, progressReport);
}
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,43 +47,61 @@ qx.Class.define("osparc.data.model.NodeProgressSequence", {
},

clusterUpScaling: {
check: "Number",
init: 0,
check: "Object",
init: {
progressLabel: qx.locale.Manager.tr("Waiting..."),
value: 0
},
nullable: false,
apply: "__applyClusterUpScaling"
},

sidecarPulling: {
check: "Number",
init: 0,
check: "Object",
init: {
progressLabel: qx.locale.Manager.tr("Waiting..."),
value: 0
},
nullable: false,
apply: "__applySidecarPulling"
},

outputsPulling: {
check: "Number",
init: 0,
check: "Object",
init: {
progressLabel: qx.locale.Manager.tr("Waiting..."),
value: 0
},
nullable: false,
apply: "__applyOutputsPulling"
},

statePulling: {
check: "Number",
init: 0,
check: "Object",
init: {
progressLabel: qx.locale.Manager.tr("Waiting..."),
value: 0
},
nullable: false,
apply: "__applyStatePulling"
},

imagesPulling: {
check: "Number",
init: 0,
check: "Object",
init: {
progressLabel: qx.locale.Manager.tr("Waiting..."),
value: 0
},
nullable: false,
apply: "__applyImagesPulling"
},

inputsPulling: {
check: "Number",
init: 0,
check: "Object",
init: {
progressLabel: qx.locale.Manager.tr("Waiting..."),
value: 0
},
nullable: false,
apply: "__applyInputsPulling"
}
Expand All @@ -92,7 +110,8 @@ qx.Class.define("osparc.data.model.NodeProgressSequence", {
statics: {
NODE_INDEX: {
LABEL: 0,
HALO: 1,
CALC: 1,
HALO: 2,
},

createTaskLayout: function(label) {
Expand Down Expand Up @@ -130,6 +149,15 @@ qx.Class.define("osparc.data.model.NodeProgressSequence", {
osparc.service.StatusUI.getStatusHalo(iconContainer, progressColor, 0);
layout.addAt(iconContainer, this.NODE_INDEX.HALO);

const progressState = new qx.ui.basic.Label();
progressState.set({
value: qx.locale.Manager.tr("Waiting..."),
textColor: "text",
allowGrowX: true,
allowShrinkX: true
});
layout.addAt(progressState, this.NODE_INDEX.CALC);

return layout;
},

Expand All @@ -144,7 +172,7 @@ qx.Class.define("osparc.data.model.NodeProgressSequence", {
return progressBar;
},

updateProgressLabel: function(atom, value) {
updateProgressLabel: function(atom, {value, progressLabel}) {
if ([null, undefined].includes(value)) {
return;
}
Expand All @@ -155,6 +183,9 @@ qx.Class.define("osparc.data.model.NodeProgressSequence", {
icon.setVisibility(value === 1 ? "visible" : "excluded");
const progressColor = qx.theme.manager.Color.getInstance().resolve("progressbar")
osparc.service.StatusUI.getStatusHalo(halo, progressColor, value * 100);

const label = atom.getChildren()[this.NODE_INDEX.CALC];
label.setValue(progressLabel);
}
},

Expand Down Expand Up @@ -183,21 +214,54 @@ qx.Class.define("osparc.data.model.NodeProgressSequence", {
__pullingInputsLayout: null,
__disclaimerText: null,

getDefaultStartValues: function() {
return {
progressLabel: qx.locale.Manager.tr("Waiting..."),
value: 0
}
},

getDefaultEndValues: function() {
return {
progressLabel: "100%",
value: 1
}
},

getWidgetForLoadingPage: function() {
return this.__mainLoadingPage;
},

resetSequence: function() {
const defaultVals = this.getDefaultStartValues();
this.setOverallProgress(0);
this.setClusterUpScaling(0);
this.setSidecarPulling(0);
this.setOutputsPulling(0);
this.setStatePulling(0);
this.setImagesPulling(0);
this.setInputsPulling(0);
this.setClusterUpScaling(defaultVals);
this.setSidecarPulling(defaultVals);
this.setOutputsPulling(defaultVals);
this.setStatePulling(defaultVals);
this.setImagesPulling(defaultVals);
this.setInputsPulling(defaultVals);
},

getProgress: function(report) {
const isDownloading = report["actual_value"] > 0 && report["actual_value"] < report["total"];
if (report.unit) {
return {
progressLabel: isDownloading ?
`${osparc.utils.Utils.bytesToSize(report["actual_value"], 1, false)} / ${osparc.utils.Utils.bytesToSize(report["total"], 1)}` :
`${osparc.utils.Utils.bytesToSize(report["total"], 1)}`,
value: report["actual_value"] / report["total"]
}
}
const percentage = parseFloat((report["actual_value"] / report["total"] * 100).toFixed(2))
return {
progressLabel: `${percentage}%`,
value: report["actual_value"] / report["total"]
}
},

addProgressMessage: function(progressType, progress) {
addProgressMessage: function(progressType, progressReport) {
const progress = this.getProgress(progressReport);
switch (progressType) {
case "CLUSTER_UP_SCALING":
this.setClusterUpScaling(progress);
Expand Down Expand Up @@ -283,12 +347,12 @@ qx.Class.define("osparc.data.model.NodeProgressSequence", {
},

__computeOverallProgress: function() {
const overallProgress = this.getClusterUpScaling() +
this.getSidecarPulling() +
this.getOutputsPulling() +
this.getStatePulling() +
this.getImagesPulling() +
this.getInputsPulling();
const overallProgress = this.getClusterUpScaling().value +
this.getSidecarPulling().value +
this.getOutputsPulling().value +
this.getStatePulling().value +
this.getImagesPulling().value +
this.getInputsPulling().value;
this.setOverallProgress(overallProgress)
},

Expand All @@ -311,44 +375,54 @@ qx.Class.define("osparc.data.model.NodeProgressSequence", {
},

__applySidecarPulling: function(value) {
if (value > 0) {
this.setClusterUpScaling(1);
if (value.value > 0) {
const defaultEndVals = this.getDefaultEndValues();
this.setClusterUpScaling(defaultEndVals);
this.self().updateProgressLabel(this.__clusterUpScalingLayout, defaultEndVals);
odeimaiz marked this conversation as resolved.
Show resolved Hide resolved
}
this.self().updateProgressLabel(this.__pullingSidecarLayout, value);

this.__computeOverallProgress();
},

__applyOutputsPulling: function(value) {
if (value > 0) {
this.setSidecarPulling(1);
if (value.value > 0) {
const defaultEndVals = this.getDefaultEndValues();
this.setSidecarPulling(defaultEndVals);
this.self().updateProgressLabel(this.__pullingSidecarLayout, defaultEndVals);
}
this.self().updateProgressLabel(this.__pullingOutputsLayout, value);

this.__computeOverallProgress();
},

__applyStatePulling: function(value) {
if (value > 0) {
this.setSidecarPulling(1);
if (value.value > 0) {
const defaultEndVals = this.getDefaultEndValues();
this.setSidecarPulling(defaultEndVals);
this.self().updateProgressLabel(this.__pullingSidecarLayout, defaultEndVals);
}
this.self().updateProgressLabel(this.__pullingStateLayout, value);

this.__computeOverallProgress();
},

__applyImagesPulling: function(value) {
if (value > 0) {
this.setSidecarPulling(1);
if (value.value > 0) {
const defaultEndVals = this.getDefaultEndValues();
this.setSidecarPulling(defaultEndVals);
this.self().updateProgressLabel(this.__pullingSidecarLayout, defaultEndVals);
}
this.self().updateProgressLabel(this.__pullingImagesLayout, value);

this.__computeOverallProgress();
},

__applyInputsPulling: function(value) {
if (value > 0) {
this.setSidecarPulling(1);
if (value.value > 0) {
const defaultEndVals = this.getDefaultEndValues();
this.setSidecarPulling(defaultEndVals);
this.self().updateProgressLabel(this.__pullingSidecarLayout, defaultEndVals);
}
this.self().updateProgressLabel(this.__pullingInputsLayout, value);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,8 @@ qx.Class.define("osparc.data.model.Study", {
const node = workbench.getNode(nodeId);
if (node) {
const progressType = nodeProgressData["progress_type"];
const progress = nodeProgressData["progress_report"]["actual_value"] / nodeProgressData["progress_report"]["total"];
node.setNodeProgressSequence(progressType, progress);
const progressReport = nodeProgressData["progress_report"];
node.setNodeProgressSequence(progressType, progressReport);
}
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ qx.Class.define("osparc.utils.Utils", {
return L > 0.35 ? "#FFF" : "#000";
},

bytesToSize: function(bytes, decimals = 2) {
bytesToSize: function(bytes, decimals = 2, isPrefixVisible = true) {
if (!+bytes) {
return "0 Bytes";
}
Expand All @@ -561,7 +561,7 @@ qx.Class.define("osparc.utils.Utils", {
const dm = decimals < 0 ? 0 : decimals;

const i = Math.floor(Math.log(bytes) / Math.log(k))
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${isPrefixVisible ? sizes[i] : ""}`
},

bytesToGB: function(bytes) {
Expand Down
Loading