Skip to content

Commit

Permalink
Improve something
Browse files Browse the repository at this point in the history
  • Loading branch information
larsevj committed Jan 2, 2025
1 parent 5526786 commit e6b01d1
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 37 deletions.
8 changes: 3 additions & 5 deletions src/ert/gui/simulation/run_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@
from ert.run_models.event import RunModelDataEvent, RunModelErrorEvent
from ert.shared.status.utils import (
byte_with_unit,
disk_space_status,
file_has_content,
format_running_time,
get_mount_directory,
)

from ..find_ert_info import find_ert_info
Expand Down Expand Up @@ -196,7 +196,7 @@ def __init__(
self._ticker = QTimer(self)
self._ticker.timeout.connect(self._on_ticker)

self.run_path_mp = run_model.run_paths._runpath_format
self.run_path_mp = get_mount_directory(run_model.run_paths._runpath_format)

self._total_progress_label = QLabel(
_TOTAL_PROGRESS_TEMPLATE.format(
Expand Down Expand Up @@ -430,10 +430,8 @@ def _on_ticker(self) -> None:
self.running_time.setText(format_running_time(runtime))

maximum_memory_usage = self._snapshot_model.root.max_memory_usage
disk_usage = disk_space_status(self.run_path_mp)

if disk_usage:
self.disk_space.update_status(self.run_path_mp)
self.disk_space.update_status(self.run_path_mp)

Check failure on line 434 in src/ert/gui/simulation/run_dialog.py

View workflow job for this annotation

GitHub Actions / type-checking (3.12)

Call to untyped function "update_status" in typed context

if maximum_memory_usage:
self.memory_usage.setText(
Expand Down
60 changes: 34 additions & 26 deletions src/ert/gui/simulation/view/disk_space_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ def __init__(self, parent=None):
layout.setSpacing(10)

# Text label
self.label = QLabel(self)
self.usage_label = QLabel(self)
self.space_left_label = QLabel(self)

# Progress bar
self.progress_bar = QProgressBar(self)
Expand All @@ -22,34 +23,41 @@ def __init__(self, parent=None):
self.progress_bar.setFixedWidth(100)
self.progress_bar.setAlignment(Qt.AlignCenter)

Check failure on line 24 in src/ert/gui/simulation/view/disk_space_widget.py

View workflow job for this annotation

GitHub Actions / type-checking (3.12)

"type[Qt]" has no attribute "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.usage_label)
layout.addWidget(self.progress_bar)
layout.addWidget(self.space_left_label)

def update_status(self, run_path_mp):
def update_status(self, mount_dir):

Check failure on line 30 in src/ert/gui/simulation/view/disk_space_widget.py

View workflow job for this annotation

GitHub Actions / type-checking (3.12)

Function is missing a type annotation
"""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}%")
disk_usage_percentage, free_disk_space = disk_space_status(mount_dir)

Check failure on line 32 in src/ert/gui/simulation/view/disk_space_widget.py

View workflow job for this annotation

GitHub Actions / type-checking (3.12)

"None" object is not iterable
if disk_usage_percentage is not None:
usage = int(disk_usage_percentage)
self.usage_label.setText("Disk space runpath:")
self.progress_bar.setValue(usage)
self.progress_bar.setFormat(f"{disk_usage_percentage:.1f}%")

# Set color based on usage threshold
if usage >= 90:
color = "#e74c3c" # Red for critical usage
elif usage >= 70:
color = "#f1c40f" # Yellow for warning
else:
color = "#2ecc71" # Green for normal usage

self.progress_bar.setStyleSheet(f"""
QProgressBar {{
border: 1px solid #ccc;
border-radius: 2px;
text-align: center;
}}
QProgressBar::chunk {{
background-color: {color};
}}
""")

self.space_left_label.setText(f"{free_disk_space} free")

self.setVisible(True)
else:
self.setVisible(False)
12 changes: 6 additions & 6 deletions src/ert/shared/status/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@ def get_ert_memory_usage() -> int:
return usage.ru_maxrss // rss_scale


def disk_space_status(runpath: str) -> float | None:
def disk_space_status(mount_dir: str) -> tuple[float, str] | None:
with contextlib.suppress(Exception):
mount_dir = _get_mount_directory(runpath)
total_space, used_space, _free_space = shutil.disk_usage(mount_dir)
percentage_used = used_space / total_space
return percentage_used
disk_info = shutil.disk_usage(mount_dir)
percentage_used = (disk_info.used / disk_info.total) * 100
return percentage_used, byte_with_unit(disk_info.free)
return None


def _get_mount_directory(runpath: str) -> Path:
def get_mount_directory(runpath: str) -> Path:
path = Path(runpath).absolute()

while not path.is_mount():
Expand Down

0 comments on commit e6b01d1

Please sign in to comment.