vn6295337 Claude Opus 4.5 commited on
Commit
19c947a
·
1 Parent(s): cbb2179

Fix analyzer.py to handle temporal dict format for margins

Browse files

- Extract net_margin_pct, gross_margin_pct, operating_margin_pct as temporal dicts
- Fix revenue_cagr_3yr field name (was revenue_cagr_3yr, source has revenue_growth_3yr)
- Update formatting code to handle dict format for net_margin and debt_to_equity
- Add fiscal period labels to margin and debt metrics in LLM prompt

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Files changed (1) hide show
  1. src/nodes/analyzer.py +23 -7
src/nodes/analyzer.py CHANGED
@@ -72,12 +72,15 @@ def _extract_key_metrics(raw_data: str) -> dict:
72
  fin = metrics.get("financials", {})
73
  if fin and "error" not in fin:
74
  fin_data = fin.get("financials", {})
 
75
  extracted["financials"] = {
76
  "revenue": _extract_temporal_metric(fin_data.get("revenue", {})),
77
- "revenue_cagr_3yr": fin_data.get("revenue_cagr_3yr"),
78
- "net_margin": fin_data.get("net_margin"),
 
 
79
  "eps": _extract_temporal_metric(fin_data.get("eps", {})),
80
- "debt_to_equity": fin.get("debt", {}).get("debt_to_equity"),
81
  "free_cash_flow": _extract_temporal_metric(fin.get("cash_flow", {}).get("free_cash_flow", {})),
82
  "net_income": _extract_temporal_metric(fin_data.get("net_income", {})),
83
  }
@@ -158,8 +161,15 @@ def _format_metrics_for_prompt(extracted: dict) -> str:
158
 
159
  if fin.get("revenue_cagr_3yr"):
160
  lines.append(f"- Revenue CAGR (3yr): {fin['revenue_cagr_3yr']:.1f}%")
161
- if fin.get("net_margin"):
162
- lines.append(f"- Net Margin: {fin['net_margin']:.1f}%")
 
 
 
 
 
 
 
163
 
164
  # EPS with fiscal period
165
  eps = fin.get("eps", {})
@@ -170,8 +180,14 @@ def _format_metrics_for_prompt(extracted: dict) -> str:
170
  elif isinstance(eps, (int, float)):
171
  lines.append(f"- EPS: ${eps:.2f}")
172
 
173
- if fin.get("debt_to_equity"):
174
- lines.append(f"- Debt/Equity: {fin['debt_to_equity']:.2f}")
 
 
 
 
 
 
175
 
176
  # Free Cash Flow with fiscal period
177
  fcf = fin.get("free_cash_flow", {})
 
72
  fin = metrics.get("financials", {})
73
  if fin and "error" not in fin:
74
  fin_data = fin.get("financials", {})
75
+ debt_data = fin.get("debt", {})
76
  extracted["financials"] = {
77
  "revenue": _extract_temporal_metric(fin_data.get("revenue", {})),
78
+ "revenue_cagr_3yr": fin_data.get("revenue_growth_3yr"),
79
+ "net_margin": _extract_temporal_metric(fin_data.get("net_margin_pct", {})),
80
+ "gross_margin": _extract_temporal_metric(fin_data.get("gross_margin_pct", {})),
81
+ "operating_margin": _extract_temporal_metric(fin_data.get("operating_margin_pct", {})),
82
  "eps": _extract_temporal_metric(fin_data.get("eps", {})),
83
+ "debt_to_equity": _extract_temporal_metric(debt_data.get("debt_to_equity", {})),
84
  "free_cash_flow": _extract_temporal_metric(fin.get("cash_flow", {}).get("free_cash_flow", {})),
85
  "net_income": _extract_temporal_metric(fin_data.get("net_income", {})),
86
  }
 
161
 
162
  if fin.get("revenue_cagr_3yr"):
163
  lines.append(f"- Revenue CAGR (3yr): {fin['revenue_cagr_3yr']:.1f}%")
164
+
165
+ # Net margin with fiscal period
166
+ net_margin = fin.get("net_margin", {})
167
+ if isinstance(net_margin, dict) and net_margin.get("value") is not None:
168
+ period = _get_fiscal_period_label(net_margin)
169
+ period_str = f" ({period})" if period else ""
170
+ lines.append(f"- Net Margin: {net_margin['value']:.1f}%{period_str}")
171
+ elif isinstance(net_margin, (int, float)):
172
+ lines.append(f"- Net Margin: {net_margin:.1f}%")
173
 
174
  # EPS with fiscal period
175
  eps = fin.get("eps", {})
 
180
  elif isinstance(eps, (int, float)):
181
  lines.append(f"- EPS: ${eps:.2f}")
182
 
183
+ # Debt/Equity with fiscal period
184
+ d_to_e = fin.get("debt_to_equity", {})
185
+ if isinstance(d_to_e, dict) and d_to_e.get("value") is not None:
186
+ period = _get_fiscal_period_label(d_to_e)
187
+ period_str = f" ({period})" if period else ""
188
+ lines.append(f"- Debt/Equity: {d_to_e['value']:.2f}{period_str}")
189
+ elif isinstance(d_to_e, (int, float)):
190
+ lines.append(f"- Debt/Equity: {d_to_e:.2f}")
191
 
192
  # Free Cash Flow with fiscal period
193
  fcf = fin.get("free_cash_flow", {})