1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-22 03:33:52 +01:00
This commit is contained in:
J. Nick Koston
2025-10-17 17:10:28 -10:00
parent 8fd43f1d96
commit d98b00f56d

View File

@@ -61,16 +61,15 @@ def format_bytes(bytes_value: int) -> str:
return f"{bytes_value:,} bytes" return f"{bytes_value:,} bytes"
def format_change( def format_change(before: int, after: int, threshold: float | None = None) -> str:
before: int, after: int, use_trend_icons: bool = False, threshold: float = 1.0
) -> str:
"""Format memory change with delta and percentage. """Format memory change with delta and percentage.
Args: Args:
before: Memory usage before change (in bytes) before: Memory usage before change (in bytes)
after: Memory usage after change (in bytes) after: Memory usage after change (in bytes)
use_trend_icons: If True, use 📈/📉 chart icons; if False, use status emojis threshold: Optional percentage threshold for "significant" change.
threshold: Percentage threshold for "significant" change (default 1.0%) If provided, adds supplemental emoji (🎉/🚨/🔸/✅) to chart icons.
If None, only shows chart icons (📈/📉/➡️).
Returns: Returns:
Formatted string with delta and percentage Formatted string with delta and percentage
@@ -78,21 +77,25 @@ def format_change(
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 and always show in bytes for precision # Always use chart icons to show direction
if delta > 0: if delta > 0:
delta_str = f"+{delta:,} bytes" delta_str = f"+{delta:,} bytes"
if use_trend_icons: trend_icon = "📈"
emoji = "📈" # Add supplemental emoji based on threshold if provided
if threshold is not None:
significance = "🚨" if abs(percentage) > threshold else "🔸"
emoji = f"{trend_icon} {significance}"
else: else:
# Use 🚨 for significant increases, 🔸 for smaller ones emoji = trend_icon
emoji = "🚨" if abs(percentage) > threshold else "🔸"
elif delta < 0: elif delta < 0:
delta_str = f"{delta:,} bytes" delta_str = f"{delta:,} bytes"
if use_trend_icons: trend_icon = "📉"
emoji = "📉" # Add supplemental emoji based on threshold if provided
if threshold is not None:
significance = "🎉" if abs(percentage) > threshold else ""
emoji = f"{trend_icon} {significance}"
else: else:
# Use 🎉 for significant reductions, ✅ for smaller ones emoji = trend_icon
emoji = "🎉" if abs(percentage) > threshold else ""
else: else:
delta_str = "+0 bytes" delta_str = "+0 bytes"
emoji = "➡️" emoji = "➡️"
@@ -187,7 +190,7 @@ def create_symbol_changes_table(
for symbol, target_size, pr_size, delta in changed_symbols[:30]: for symbol, target_size, pr_size, delta in changed_symbols[:30]:
target_str = format_bytes(target_size) target_str = format_bytes(target_size)
pr_str = format_bytes(pr_size) pr_str = format_bytes(pr_size)
change_str = format_change(target_size, pr_size, use_trend_icons=True) change_str = format_change(target_size, pr_size) # Chart icons only
display_symbol = format_symbol_for_display(symbol) display_symbol = format_symbol_for_display(symbol)
lines.append( lines.append(
f"| {display_symbol} | {target_str} | {pr_str} | {change_str} |" f"| {display_symbol} | {target_str} | {pr_str} | {change_str} |"