mirror of
https://github.com/esphome/esphome.git
synced 2025-10-21 19:23:45 +01:00
tidy
This commit is contained in:
@@ -18,27 +18,23 @@ COMMENT_MARKER = "<!-- esphome-memory-impact-analysis -->"
|
|||||||
|
|
||||||
|
|
||||||
def format_bytes(bytes_value: int) -> str:
|
def format_bytes(bytes_value: int) -> str:
|
||||||
"""Format bytes value with appropriate unit.
|
"""Format bytes value with comma separators.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
bytes_value: Number of bytes
|
bytes_value: Number of bytes
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Formatted string (e.g., "1.5 KB", "256 bytes")
|
Formatted string with comma separators (e.g., "1,234 bytes")
|
||||||
"""
|
"""
|
||||||
if bytes_value < 1024:
|
return f"{bytes_value:,} bytes"
|
||||||
return f"{bytes_value} bytes"
|
|
||||||
if bytes_value < 1024 * 1024:
|
|
||||||
return f"{bytes_value / 1024:.2f} KB"
|
|
||||||
return f"{bytes_value / (1024 * 1024):.2f} MB"
|
|
||||||
|
|
||||||
|
|
||||||
def format_change(before: int, after: int) -> str:
|
def format_change(before: int, after: int) -> str:
|
||||||
"""Format memory change with delta and percentage.
|
"""Format memory change with delta and percentage.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
before: Memory usage before change
|
before: Memory usage before change (in bytes)
|
||||||
after: Memory usage after change
|
after: Memory usage after change (in bytes)
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Formatted string with delta and percentage
|
Formatted string with delta and percentage
|
||||||
@@ -46,8 +42,16 @@ def format_change(before: int, after: int) -> str:
|
|||||||
delta = after - before
|
delta = after - before
|
||||||
percentage = 0.0 if before == 0 else (delta / before) * 100
|
percentage = 0.0 if before == 0 else (delta / before) * 100
|
||||||
|
|
||||||
# Format delta with sign
|
# Format delta with sign and always show in bytes for precision
|
||||||
delta_str = f"+{format_bytes(delta)}" if delta >= 0 else format_bytes(delta)
|
if delta > 0:
|
||||||
|
delta_str = f"+{delta:,} bytes"
|
||||||
|
emoji = "📈"
|
||||||
|
elif delta < 0:
|
||||||
|
delta_str = f"{delta:,} bytes"
|
||||||
|
emoji = "📉"
|
||||||
|
else:
|
||||||
|
delta_str = "+0 bytes"
|
||||||
|
emoji = "➡️"
|
||||||
|
|
||||||
# Format percentage with sign
|
# Format percentage with sign
|
||||||
if percentage > 0:
|
if percentage > 0:
|
||||||
@@ -57,14 +61,6 @@ def format_change(before: int, after: int) -> str:
|
|||||||
else:
|
else:
|
||||||
pct_str = "0.00%"
|
pct_str = "0.00%"
|
||||||
|
|
||||||
# Add emoji indicator
|
|
||||||
if delta > 0:
|
|
||||||
emoji = "📈"
|
|
||||||
elif delta < 0:
|
|
||||||
emoji = "📉"
|
|
||||||
else:
|
|
||||||
emoji = "➡️"
|
|
||||||
|
|
||||||
return f"{emoji} {delta_str} ({pct_str})"
|
return f"{emoji} {delta_str} ({pct_str})"
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user