[ui] using coherent format for elapsed time

This commit is contained in:
Loïc Vital 2022-10-03 16:26:57 +02:00
parent c2f8c0f97a
commit 5b973cb349
3 changed files with 34 additions and 33 deletions

View file

@ -216,7 +216,7 @@ Item {
horizontalAlignment: Text.AlignRight horizontalAlignment: Text.AlignRight
color: "#CCCCCC" color: "#CCCCCC"
enabled: duration > 0 enabled: duration > 0
ToolTip.text: "elapsed time: " + String(duration) + "s" ToolTip.text: "Elapsed time: " + Format.getTimeStr(duration)
ToolTip.visible: mouseArea.containsMouse ToolTip.visible: mouseArea.containsMouse
MouseArea { MouseArea {
id: mouseArea id: mouseArea

View file

@ -4,6 +4,7 @@ import QtQuick.Controls 1.4 as Controls1 // SplitView
import QtQuick.Layouts 1.3 import QtQuick.Layouts 1.3
import MaterialIcons 2.2 import MaterialIcons 2.2
import Controls 1.0 import Controls 1.0
import Utils 1.0
/** /**
@ -29,7 +30,7 @@ Panel {
if (node !== null && node.isSubmittedOrRunning()) { if (node !== null && node.isSubmittedOrRunning()) {
// Some chunks might be submitted but they'll all run eventually // Some chunks might be submitted but they'll all run eventually
if (node.elapsedTime > 0) { // At least a chunk is done running if (node.elapsedTime > 0) { // At least a chunk is done running
return "Running for: " + getTimeStr(node.elapsedTime) return "Running for: " + Format.getTimeStr(node.elapsedTime)
} else { } else {
return (node.chunks.count > 1) ? "First chunk running" : "Node running" return (node.chunks.count > 1) ? "First chunk running" : "Node running"
} }
@ -37,7 +38,7 @@ Panel {
/* Either all chunks finished running or the last one is running /* Either all chunks finished running or the last one is running
* Placed inside an "else if" instead of "else" to avoid entering the functions * Placed inside an "else if" instead of "else" to avoid entering the functions
* when there is no real use */ * when there is no real use */
return getTimeStr(node.elapsedTime) return Format.getTimeStr(node.elapsedTime)
} else { } else {
return "" return ""
} }
@ -57,7 +58,7 @@ Panel {
if (node !== null && (node.isFinishedOrRunning() || (node.isSubmittedOrRunning() && node.elapsedTime > 0))) { if (node !== null && (node.isFinishedOrRunning() || (node.isSubmittedOrRunning() && node.elapsedTime > 0))) {
var longestChunkTime = getLongestChunkTime(node.chunks) var longestChunkTime = getLongestChunkTime(node.chunks)
if (longestChunkTime > 0) if (longestChunkTime > 0)
return "Longest chunk: " + getTimeStr(longestChunkTime) + " (" + node.chunks.count + " chunks)" return "Longest chunk: " + Format.getTimeStr(longestChunkTime) + " (" + node.chunks.count + " chunks)"
else else
return "" return ""
} else { } else {
@ -71,35 +72,6 @@ Panel {
hoverEnabled: true hoverEnabled: true
} }
function getTimeStr(elapsed)
{
if (elapsed <= 0)
return ""
var hours = 0
var min = 0
var finalTime = ""
if (elapsed > 3600) {
hours = Math.floor(elapsed / 3600)
elapsed = elapsed - (hours * 3600)
finalTime += hours + "h"
}
if (elapsed > 60) {
min = Math.floor(elapsed / 60)
elapsed = elapsed - (min * 60)
finalTime += min + "m"
}
if (hours == 0 && min == 0) {
// Millisecond precision for execution times below 1 min
finalTime += Number(elapsed.toLocaleString(Qt.locale('en-US'))) + "s"
} else {
finalTime += Math.round(elapsed) + "s"
}
return finalTime
}
function getLongestChunkTime(chunks) function getLongestChunkTime(chunks)
{ {
if (chunks.count <= 1) if (chunks.count <= 1)

View file

@ -22,3 +22,32 @@ function sec2time(time) {
return pad(hours, 2) + ':' + pad(minutes, 2) + ':' + pad(seconds, 2) return pad(hours, 2) + ':' + pad(minutes, 2) + ':' + pad(seconds, 2)
} }
function getTimeStr(elapsed)
{
if (elapsed <= 0)
return ""
var hours = 0
var min = 0
var finalTime = ""
if (elapsed > 3600) {
hours = Math.floor(elapsed / 3600)
elapsed = elapsed - (hours * 3600)
finalTime += hours + "h"
}
if (elapsed > 60) {
min = Math.floor(elapsed / 60)
elapsed = elapsed - (min * 60)
finalTime += min + "m"
}
if (hours == 0 && min == 0) {
// Millisecond precision for execution times below 1 min
finalTime += Number(elapsed.toLocaleString(Qt.locale('en-US'))) + "s"
} else {
finalTime += Math.round(elapsed) + "s"
}
return finalTime
}