Skip to content

Commit

Permalink
try add colour bar
Browse files Browse the repository at this point in the history
  • Loading branch information
larsevj committed Jan 2, 2025
1 parent 33ffdb9 commit 5526786
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/ert/gui/simulation/run_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@

from ..find_ert_info import find_ert_info
from .queue_emitter import QueueEmitter
from .view import ProgressWidget, RealizationWidget, UpdateWidget
from .view import DiskSpaceWidget, ProgressWidget, RealizationWidget, UpdateWidget

_TOTAL_PROGRESS_TEMPLATE = "Total progress {total_progress}% — {iteration_label}"

Expand Down Expand Up @@ -223,7 +223,7 @@ def __init__(

self.running_time = QLabel("")
self.memory_usage = QLabel("")
self.disk_space = QLabel("")
self.disk_space = DiskSpaceWidget()

self.kill_button = QPushButton("Terminate experiment")
self.restart_button = QPushButton("Rerun failed")
Expand Down Expand Up @@ -433,7 +433,7 @@ def _on_ticker(self) -> None:
disk_usage = disk_space_status(self.run_path_mp)

if disk_usage:
self.disk_space.setText(f"Disk space used runpath: {disk_usage:.2f}%")
self.disk_space.update_status(self.run_path_mp)

if maximum_memory_usage:
self.memory_usage.setText(
Expand Down
3 changes: 2 additions & 1 deletion src/ert/gui/simulation/view/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .disk_space_widget import DiskSpaceWidget
from .progress_widget import ProgressWidget
from .realization import RealizationWidget
from .update import UpdateWidget

__all__ = ["ProgressWidget", "RealizationWidget", "UpdateWidget"]
__all__ = ["DiskSpaceWidget", "ProgressWidget", "RealizationWidget", "UpdateWidget"]
55 changes: 55 additions & 0 deletions src/ert/gui/simulation/view/disk_space_widget.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from qtpy.QtCore import Qt
from qtpy.QtWidgets import QHBoxLayout, QLabel, QProgressBar, QWidget

from ert.shared.status.utils import disk_space_status


class DiskSpaceWidget(QWidget):
def __init__(self, parent=None):
super().__init__(parent)

layout = QHBoxLayout(self)
layout.setContentsMargins(0, 0, 0, 0)
layout.setSpacing(10)

# Text label
self.label = QLabel(self)

# Progress bar
self.progress_bar = QProgressBar(self)
self.progress_bar.setRange(0, 100)
self.progress_bar.setTextVisible(True)
self.progress_bar.setFixedWidth(100)
self.progress_bar.setAlignment(Qt.AlignCenter)

# Add color styling based on usage
self.progress_bar.setStyleSheet("""
QProgressBar {
border: 1px solid #ccc;
border-radius: 2px;
text-align: center;
}
QProgressBar::chunk {
background-color: qlineargradient(
x1: 0, y1: 0.5, x2: 1, y2: 0.5,
stop: 0 #2ecc71,
stop: 0.7 #f1c40f,
stop: 0.9 #e74c3c
);
}
""")

layout.addWidget(self.label)
layout.addWidget(self.progress_bar)

def update_status(self, run_path_mp):
"""Update both the label and progress bar with current disk usage"""
disk_usage = disk_space_status(run_path_mp)
if disk_usage is not None:
self.label.setText("Disk space used runpath:")
self.progress_bar.setValue(int(disk_usage))
self.progress_bar.setFormat(f"{disk_usage:.1f}%")
self.setVisible(True)
else:
self.setVisible(False)
1 change: 0 additions & 1 deletion src/ert/shared/status/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ def get_ert_memory_usage() -> int:
def disk_space_status(runpath: str) -> float | None:
with contextlib.suppress(Exception):
mount_dir = _get_mount_directory(runpath)
print(mount_dir)
total_space, used_space, _free_space = shutil.disk_usage(mount_dir)
percentage_used = used_space / total_space
return percentage_used
Expand Down

0 comments on commit 5526786

Please sign in to comment.