fix: address review feedback on PR #85 dataflows hardening

- y_finance.py: replace print() with logger.warning() in bulk-stats fallback
- macro_bridge.py: add elapsed_seconds field to TickerResult, populate in
  run_ticker_analysis (success + error paths)
- cli/main.py: move inline 'import time as _time' and rich.progress imports
  to module level; use result.elapsed_seconds for accurate per-ticker timing

Co-authored-by: aguzererler <6199053+aguzererler@users.noreply.github.com>
Agent-Logs-Url: https://github.com/aguzererler/TradingAgents/sessions/68fcf34c-8d55-4436-b743-f79fff68713f
This commit is contained in:
copilot-swe-agent[bot] 2026-03-22 06:02:39 +00:00
parent d2808c2252
commit 9ff531f293
3 changed files with 10 additions and 8 deletions

View File

@ -27,6 +27,7 @@ import time
from rich import box from rich import box
from rich.align import Align from rich.align import Align
from rich.rule import Rule from rich.rule import Rule
from rich.progress import Progress, SpinnerColumn, BarColumn, TextColumn, TimeElapsedColumn
from tradingagents.graph.trading_graph import TradingAgentsGraph from tradingagents.graph.trading_graph import TradingAgentsGraph
from tradingagents.report_paths import get_daily_dir, get_market_dir, get_ticker_dir from tradingagents.report_paths import get_daily_dir, get_market_dir, get_ticker_dir
@ -1588,10 +1589,8 @@ def run_pipeline(
f" [dim]{c.sector} · {c.conviction.upper()} conviction[/dim]" f" [dim]{c.sector} · {c.conviction.upper()} conviction[/dim]"
) )
console.print() console.print()
import time as _time
from rich.progress import Progress, SpinnerColumn, BarColumn, TextColumn, TimeElapsedColumn
pipeline_start = _time.monotonic() pipeline_start = time.monotonic()
with Progress( with Progress(
SpinnerColumn(), SpinnerColumn(),
@ -1605,17 +1604,17 @@ def run_pipeline(
overall = progress.add_task("[bold]Pipeline progress[/bold]", total=len(candidates)) overall = progress.add_task("[bold]Pipeline progress[/bold]", total=len(candidates))
def on_done(result, done_count, total_count): def on_done(result, done_count, total_count):
ticker_elapsed = _time.monotonic() - pipeline_start ticker_elapsed = result.elapsed_seconds
if result.error: if result.error:
console.print( console.print(
f" [red]✗ {result.ticker}[/red]" f" [red]✗ {result.ticker}[/red]"
f" [dim]failed ({ticker_elapsed:.0f}s elapsed) — {result.error[:80]}[/dim]" f" [dim]failed ({ticker_elapsed:.0f}s) — {result.error[:80]}[/dim]"
) )
else: else:
decision_preview = str(result.final_trade_decision)[:70].replace("\n", " ") decision_preview = str(result.final_trade_decision)[:70].replace("\n", " ")
console.print( console.print(
f" [green]✓ {result.ticker}[/green]" f" [green]✓ {result.ticker}[/green]"
f" [dim]({done_count}/{total_count}, {ticker_elapsed:.0f}s elapsed)[/dim]" f" [dim]({done_count}/{total_count}, {ticker_elapsed:.0f}s)[/dim]"
f"{decision_preview}" f"{decision_preview}"
) )
progress.advance(overall) progress.advance(overall)
@ -1631,7 +1630,7 @@ def run_pipeline(
console.print(f"[red]Pipeline failed: {e}[/red]") console.print(f"[red]Pipeline failed: {e}[/red]")
raise typer.Exit(1) raise typer.Exit(1)
elapsed_total = _time.monotonic() - pipeline_start elapsed_total = time.monotonic() - pipeline_start
console.print( console.print(
f"\n[bold green]All {len(candidates)} ticker(s) finished in {elapsed_total:.0f}s[/bold green]\n" f"\n[bold green]All {len(candidates)} ticker(s) finished in {elapsed_total:.0f}s[/bold green]\n"
) )

View File

@ -168,7 +168,7 @@ def get_stock_stats_indicators_window(
ind_string += f"{date_str}: {value}\n" ind_string += f"{date_str}: {value}\n"
except Exception as e: except Exception as e:
print(f"Error getting bulk stockstats data: {e}") logger.warning("Bulk stockstats failed for %s/%s, falling back to per-day loop: %s", symbol, indicator, e)
# Fallback to original implementation if bulk method fails # Fallback to original implementation if bulk method fails
ind_string = "" ind_string = ""
curr_date_dt = datetime.strptime(curr_date, "%Y-%m-%d") curr_date_dt = datetime.strptime(curr_date, "%Y-%m-%d")

View File

@ -70,6 +70,7 @@ class TickerResult:
final_trade_decision: str = "" final_trade_decision: str = ""
error: str | None = None error: str | None = None
elapsed_seconds: float = 0.0
# ─── Parsing ────────────────────────────────────────────────────────────────── # ─── Parsing ──────────────────────────────────────────────────────────────────
@ -207,6 +208,7 @@ def run_ticker_analysis(
result.final_trade_decision = decision result.final_trade_decision = decision
elapsed = time.monotonic() - t0 elapsed = time.monotonic() - t0
result.elapsed_seconds = elapsed
logger.info( logger.info(
"[%s] ✓ Analysis complete in %.0fs — decision: %s", "[%s] ✓ Analysis complete in %.0fs — decision: %s",
candidate.ticker, elapsed, str(decision)[:80], candidate.ticker, elapsed, str(decision)[:80],
@ -214,6 +216,7 @@ def run_ticker_analysis(
except Exception as exc: except Exception as exc:
elapsed = time.monotonic() - t0 elapsed = time.monotonic() - t0
result.elapsed_seconds = elapsed
logger.error( logger.error(
"[%s] ✗ Analysis FAILED after %.0fs: %s", "[%s] ✗ Analysis FAILED after %.0fs: %s",
candidate.ticker, elapsed, exc, exc_info=True, candidate.ticker, elapsed, exc, exc_info=True,