better parsing
This commit is contained in:
@ -778,24 +778,20 @@ class SystemHealthMonitor:
|
||||
|
||||
def _parse_size(self, size_str: str) -> float:
|
||||
"""
|
||||
Parse size string with units to bytes.
|
||||
Examples: '1.5G', '500M', '2.3T', etc.
|
||||
Parse size string with units to float value
|
||||
Examples: '44.9G', '1.9G', '192.2M', '5.3T'
|
||||
"""
|
||||
if not size_str or not isinstance(size_str, str):
|
||||
return 0.0
|
||||
|
||||
# Remove any spaces and convert to uppercase for consistency
|
||||
# Remove any spaces and normalize format
|
||||
size_str = size_str.strip().upper()
|
||||
|
||||
# Handle special case for MB notation
|
||||
if 'MB' in size_str:
|
||||
size_str = size_str.replace('MB', 'M')
|
||||
|
||||
# Define unit multipliers
|
||||
units = {
|
||||
'B': 1,
|
||||
'K': 1024,
|
||||
'M': 1024**2,
|
||||
'M': 1024**2,
|
||||
'G': 1024**3,
|
||||
'T': 1024**4,
|
||||
'P': 1024**5
|
||||
@ -803,13 +799,13 @@ class SystemHealthMonitor:
|
||||
|
||||
try:
|
||||
# Extract numeric value and unit
|
||||
if size_str[-1] in units:
|
||||
number = float(size_str[:-1])
|
||||
unit = size_str[-1]
|
||||
return number * units[unit]
|
||||
# Handle case where the input is just a number
|
||||
match = re.match(r'^([\d.]+)([BKMGTP])$', size_str)
|
||||
if match:
|
||||
value = float(match.group(1))
|
||||
unit = match.group(2)
|
||||
return value * units[unit]
|
||||
return float(size_str)
|
||||
except (ValueError, IndexError):
|
||||
except (ValueError, AttributeError):
|
||||
logger.debug(f"Could not parse size: {size_str}")
|
||||
return 0.0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user