vn6295337 Claude Opus 4.5 commited on
Commit
1f4f8e3
·
1 Parent(s): e6a47ad

fix: Improve SWOT output formatting

Browse files

- Format large numbers with B/M suffixes ($177.6B instead of $177,556,000,000)
- Fix SWOT line parsing to require spaces around separator ( - not just -)
- Prevents dates like 2024-12-31 from being split across columns

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

Files changed (2) hide show
  1. frontend/src/App.tsx +3 -2
  2. src/nodes/analyzer.py +7 -1
frontend/src/App.tsx CHANGED
@@ -105,8 +105,9 @@ const parseSwotLine = (line: string): SwotRow | null => {
105
  const cleaned = cleanMarkdown(line)
106
 
107
  // Pattern: [M##] Metric: Value - Insight
 
108
  // Also handle: [M##] Metric: Value | Insight (pipe separator)
109
- const match = cleaned.match(/^\[?(M\d+)\]?\s*(.+?)\s*[-|]\s*(.+)$/i)
110
  if (match) {
111
  return {
112
  ref: match[1],
@@ -116,7 +117,7 @@ const parseSwotLine = (line: string): SwotRow | null => {
116
  }
117
 
118
  // Fallback: no ref pattern, just "Metric: Value - Insight"
119
- const fallback = cleaned.match(/^(.+?)\s*[-|]\s*(.+)$/)
120
  if (fallback) {
121
  return {
122
  ref: '',
 
105
  const cleaned = cleanMarkdown(line)
106
 
107
  // Pattern: [M##] Metric: Value - Insight
108
+ // Use " - " (space-hyphen-space) to avoid matching hyphens in dates like "2024-12-31"
109
  // Also handle: [M##] Metric: Value | Insight (pipe separator)
110
+ const match = cleaned.match(/^\[?(M\d+)\]?\s*(.+?)\s+[-|]\s+(.+)$/i)
111
  if (match) {
112
  return {
113
  ref: match[1],
 
117
  }
118
 
119
  // Fallback: no ref pattern, just "Metric: Value - Insight"
120
+ const fallback = cleaned.match(/^(.+?)\s+[-|]\s+(.+)$/)
121
  if (fallback) {
122
  return {
123
  ref: '',
src/nodes/analyzer.py CHANGED
@@ -930,7 +930,13 @@ def _format_metric_for_reference(key: str, value, temporal_info: dict = None) ->
930
  # Format value based on metric type
931
  if key in ("revenue", "net_income", "free_cash_flow", "market_cap", "enterprise_value",
932
  "total_assets", "total_liabilities", "stockholders_equity", "operating_cash_flow"):
933
- formatted = f"${value:,.0f}"
 
 
 
 
 
 
934
  elif key in ("net_margin", "gross_margin", "operating_margin", "gdp_growth",
935
  "inflation", "unemployment", "historical_volatility", "revenue_cagr_3yr"):
936
  formatted = f"{value:.1f}%"
 
930
  # Format value based on metric type
931
  if key in ("revenue", "net_income", "free_cash_flow", "market_cap", "enterprise_value",
932
  "total_assets", "total_liabilities", "stockholders_equity", "operating_cash_flow"):
933
+ # Use human-readable format with B/M suffixes
934
+ if abs(value) >= 1e9:
935
+ formatted = f"${value/1e9:.1f}B"
936
+ elif abs(value) >= 1e6:
937
+ formatted = f"${value/1e6:.0f}M"
938
+ else:
939
+ formatted = f"${value:,.0f}"
940
  elif key in ("net_margin", "gross_margin", "operating_margin", "gdp_growth",
941
  "inflation", "unemployment", "historical_volatility", "revenue_cagr_3yr"):
942
  formatted = f"{value:.1f}%"