From 28799766bbfba78f8f7df88f605c6450eecbe92a Mon Sep 17 00:00:00 2001 From: Ed_ Date: Thu, 25 Jun 2026 20:28:52 -0400 Subject: [PATCH] refactor(gui_2): migrate MMAUsageStats consumers (Phase 10 batch 1) Phase 10 (batch 1): MMAUsageStats Before: 8 .get('model'/'input'/'output') sites in src/gui_2.py After: 0 Delta: -8 Migrates the tier usage rendering and the tier_total calculation in mma_usage rendering. Each 'stats' iteration variable is converted via MMAUsageStats.from_dict() and accessed via direct field access: stats.model (was stats.get('model', 'unknown')) stats.input (was stats.get('input', 0)) stats.output (was stats.get('output', 0)) Sites migrated: 1. gui_2.py:2200-2202 (tier iteration in mma usage rendering) 2. gui_2.py:2217 (tier_total sum generator) 3. gui_2.py:6609 (total_cost in active_track panel) 4. gui_2.py:6784-6786 (tier iteration in 'Tier Usage' panel) Tests: 7/7 pass (test_mma_usage_stats, test_gui2_events). --- src/gui_2.py | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/gui_2.py b/src/gui_2.py index e867087a..48d82378 100644 --- a/src/gui_2.py +++ b/src/gui_2.py @@ -2197,9 +2197,11 @@ def render_token_budget_panel(app: App) -> None: imgui.table_setup_column("Est. Cost") imgui.table_headers_row() for tier, stats in app.mma_tier_usage.items(): - model = stats.get('model', 'unknown') - in_t = stats.get('input', 0) - out_t = stats.get('output', 0) + from src.type_aliases import MMAUsageStats as _MMA + stats = _MMA.from_dict(stats) if isinstance(stats, dict) else stats + model = stats.model or 'unknown' + in_t = stats.input + out_t = stats.output tokens = in_t + out_t cost = cost_tracker.estimate_cost(model, in_t, out_t) imgui.table_next_row() @@ -2214,7 +2216,8 @@ def render_token_budget_panel(app: App) -> None: cost_str = "-" imgui.table_set_column_index(3); render_selectable_label(app, f"cost_{tier}", cost_str, width=-1, color=theme.get_color("status_success")) imgui.end_table() - tier_total = sum(cost_tracker.estimate_cost(stats.get('model', ''), stats.get('input', 0), stats.get('output', 0)) for stats in app.mma_tier_usage.values()) + from src.type_aliases import MMAUsageStats as _MMA + tier_total = sum(cost_tracker.estimate_cost(_MMA.from_dict(s).model, _MMA.from_dict(s).input, _MMA.from_dict(s).output) for s in app.mma_tier_usage.values()) if caps.local: total_str = "Free (local)" elif caps.cost_tracking: @@ -6607,7 +6610,7 @@ def render_mma_track_summary(app: App) -> None: track_name = app.active_track.description if app.active_track else "None" if getattr(app, "ui_project_execution_mode", "native") == "beads": track_name = "Beads Graph" track_stats = project_manager.calculate_track_progress(app.active_track.tickets if app.active_track else app.active_tickets) - total_cost = sum(cost_tracker.estimate_cost(u.get('model','unknown'), u.get('input',0), u.get('output',0)) for u in app.mma_tier_usage.values()) + total_cost = sum(cost_tracker.estimate_cost(MMAUsageStats.from_dict(u).model or 'unknown', MMAUsageStats.from_dict(u).input, MMAUsageStats.from_dict(u).output) for u in app.mma_tier_usage.values()) imgui.text("Track:"); imgui.same_line(); imgui.text_colored(C_VAL(), track_name); imgui.same_line(); imgui.text(" | Status:"); imgui.same_line() if app.mma_status == "paused": imgui.text_colored(theme.get_color("status_warning") if is_nerv else theme.get_color("status_warning"), "PIPELINE PAUSED"); imgui.same_line() @@ -6778,14 +6781,16 @@ def render_mma_usage_section(app: App) -> None: if imgui.begin_table("mma_usage", 5, imgui.TableFlags_.borders | imgui.TableFlags_.row_bg): imgui.table_setup_column("Tier"); imgui.table_setup_column("Model"); imgui.table_setup_column("Input"); imgui.table_setup_column("Output"); imgui.table_setup_column("Est. Cost"); imgui.table_headers_row() total_cost = 0.0 - for tier, stats in app.mma_tier_usage.items(): - imgui.table_next_row(); - imgui.table_next_column(); - imgui.text(tier); imgui.table_next_column(); - model = stats.get('model', 'unknown'); imgui.text(model); imgui.table_next_column(); - in_t = stats.get('input', 0); imgui.text(f"{in_t:,}"); imgui.table_next_column(); - out_t = stats.get('output', 0); imgui.text(f"{out_t:,}"); imgui.table_next_column(); - cost = cost_tracker.estimate_cost(model, in_t, out_t); + for tier, stats_raw in app.mma_tier_usage.items(): + from src.type_aliases import MMAUsageStats as _MMA2 + stats = _MMA2.from_dict(stats_raw) if isinstance(stats_raw, dict) else stats_raw + imgui.table_next_row(); + imgui.table_next_column(); + imgui.text(tier); imgui.table_next_column(); + model = stats.model or 'unknown'; imgui.text(model); imgui.table_next_column(); + in_t = stats.input; imgui.text(f"{in_t:,}"); imgui.table_next_column(); + out_t = stats.output; imgui.text(f"{out_t:,}"); imgui.table_next_column(); + cost = cost_tracker.estimate_cost(model, in_t, out_t); total_cost += cost; imgui.text(f"${cost:,.4f}") imgui.table_next_row(); imgui.table_set_bg_color(imgui.TableBgTarget_.row_bg0, imgui.get_color_u32(imgui.Col_.plot_lines_hovered)); imgui.table_next_column();