shrunk parsing

This commit is contained in:
2025-03-09 20:30:33 -04:00
parent 34f9327afd
commit ba48e366c1

View File

@ -777,38 +777,30 @@ class SystemHealthMonitor:
return False return False
def _parse_size(self, size_str: str) -> float: def _parse_size(self, size_str: str) -> float:
""" """Parse size string with units to float value"""
Parse size string with units to float value if not size_str:
Examples: '44.9G', '1.9G', '192.2M', '5.3T'
"""
if not size_str or not isinstance(size_str, str):
return 0.0 return 0.0
# Remove any spaces and normalize format # Handle M/G/T sizes with potential decimal points
size_str = size_str.strip().upper() match = re.match(r'([\d.]+)([KMGT])', size_str.strip())
# Define unit multipliers
units = {
'B': 1,
'K': 1024,
'M': 1024**2,
'G': 1024**3,
'T': 1024**4,
'P': 1024**5
}
try:
# Extract numeric value and unit
match = re.match(r'^([\d.]+)([BKMGTP])$', size_str)
if match: if match:
value = float(match.group(1)) value = float(match.group(1))
unit = match.group(2) unit = match.group(2)
return value * units[unit] multipliers = {
'K': 1024,
'M': 1024**2,
'G': 1024**3,
'T': 1024**4
}
return value * multipliers[unit]
# Try parsing as plain number
try:
return float(size_str) return float(size_str)
except (ValueError, AttributeError): except ValueError:
logger.debug(f"Could not parse size: {size_str}")
return 0.0 return 0.0
def _is_physical_disk(self, device_path): def _is_physical_disk(self, device_path):
""" """
Check if the device is a physical disk, excluding logical volumes and special devices. Check if the device is a physical disk, excluding logical volumes and special devices.