-
Notifications
You must be signed in to change notification settings - Fork 2k
fix(web): prevent NaN% display in competition gap calculation (#633) #670
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(web): prevent NaN% display in competition gap calculation (#633) #670
Conversation
…OS#633) **Problem:** Competition page shows "NaN%" for gap difference when trader P&L percentages are null/undefined. **Root Cause:** Line 227: `const gap = trader.total_pnl_pct - opponent.total_pnl_pct` - If either value is `undefined` or `null`, result is `NaN` - Display shows "领先 NaN%" or "落后 NaN%" **Solution:** Add null coalescing to default undefined/null values to 0: ```typescript const gap = (trader.total_pnl_pct ?? 0) - (opponent.total_pnl_pct ?? 0) ``` **Impact:** - ✅ Gap calculation returns 0 when data is missing (shows 0.00%) - ✅ Prevents confusing "NaN%" display - ✅ Graceful degradation for incomplete data Fixes NoFxAiOS#633 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
🤖 Advisory Check ResultsThese are advisory checks to help improve code quality. They won't block your PR from being merged. 📋 PR InformationTitle Format: ✅ Good - Follows Conventional Commits 🔧 Backend ChecksGo Formatting: Files needing formattingGo Vet: ✅ Good Fix locally: go fmt ./... # Format code
go vet ./... # Check for issues
go test ./... # Run tests⚛️ Frontend ChecksBuild & Type Check: ✅ Success Fix locally: cd web
npm run build # Test build (includes type checking)📖 ResourcesQuestions? Feel free to ask in the comments! 🙏 These checks are advisory and won't block your PR from being merged. This comment is automatically generated from pr-checks-run.yml. |
| const opponent = sortedTraders[1 - index] | ||
| const gap = trader.total_pnl_pct - opponent.total_pnl_pct | ||
| const gap = (trader.total_pnl_pct ?? 0) - (opponent.total_pnl_pct ?? 0) | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果没有值,应该显示 —— 而不是 0 吧,显示 0 会有误导用户
…OS#633) (NoFxAiOS#670) **Problem:** Competition page shows "NaN%" for gap difference when trader P&L percentages are null/undefined. **Root Cause:** Line 227: `const gap = trader.total_pnl_pct - opponent.total_pnl_pct` - If either value is `undefined` or `null`, result is `NaN` - Display shows "领先 NaN%" or "落后 NaN%" **Solution:** Add null coalescing to default undefined/null values to 0: ```typescript const gap = (trader.total_pnl_pct ?? 0) - (opponent.total_pnl_pct ?? 0) ``` **Impact:** - ✅ Gap calculation returns 0 when data is missing (shows 0.00%) - ✅ Prevents confusing "NaN%" display - ✅ Graceful degradation for incomplete data Fixes NoFxAiOS#633 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <[email protected]>
…OS#633) (NoFxAiOS#670) **Problem:** Competition page shows "NaN%" for gap difference when trader P&L percentages are null/undefined. **Root Cause:** Line 227: `const gap = trader.total_pnl_pct - opponent.total_pnl_pct` - If either value is `undefined` or `null`, result is `NaN` - Display shows "领先 NaN%" or "落后 NaN%" **Solution:** Add null coalescing to default undefined/null values to 0: ```typescript const gap = (trader.total_pnl_pct ?? 0) - (opponent.total_pnl_pct ?? 0) ``` **Impact:** - ✅ Gap calculation returns 0 when data is missing (shows 0.00%) - ✅ Prevents confusing "NaN%" display - ✅ Graceful degradation for incomplete data Fixes NoFxAiOS#633 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <[email protected]>
…OS#633) (NoFxAiOS#670) **Problem:** Competition page shows "NaN%" for gap difference when trader P&L percentages are null/undefined. **Root Cause:** Line 227: `const gap = trader.total_pnl_pct - opponent.total_pnl_pct` - If either value is `undefined` or `null`, result is `NaN` - Display shows "领先 NaN%" or "落后 NaN%" **Solution:** Add null coalescing to default undefined/null values to 0: ```typescript const gap = (trader.total_pnl_pct ?? 0) - (opponent.total_pnl_pct ?? 0) ``` **Impact:** - ✅ Gap calculation returns 0 when data is missing (shows 0.00%) - ✅ Prevents confusing "NaN%" display - ✅ Graceful degradation for incomplete data Fixes NoFxAiOS#633 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <[email protected]>
…OS#633) (NoFxAiOS#670) **Problem:** Competition page shows "NaN%" for gap difference when trader P&L percentages are null/undefined. **Root Cause:** Line 227: `const gap = trader.total_pnl_pct - opponent.total_pnl_pct` - If either value is `undefined` or `null`, result is `NaN` - Display shows "领先 NaN%" or "落后 NaN%" **Solution:** Add null coalescing to default undefined/null values to 0: ```typescript const gap = (trader.total_pnl_pct ?? 0) - (opponent.total_pnl_pct ?? 0) ``` **Impact:** - ✅ Gap calculation returns 0 when data is missing (shows 0.00%) - ✅ Prevents confusing "NaN%" display - ✅ Graceful degradation for incomplete data Fixes NoFxAiOS#633 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <[email protected]>
Summary
Fixes "NaN%" display in competition page's head-to-head comparison when trader P&L percentage data is null or undefined.
Problem
Competition page shows confusing "NaN%" for gap difference:
Example:
Root Cause
File:
web/src/components/CompetitionPage.tsx:395When either trader has missing
total_pnl_pctdata:undefined - 5.23=NaN5.23 - null=NaNSolution
Add null coalescing operator to default missing values to 0:
Behavior:
Changes
web/src/components/CompetitionPage.tsx?? 0null coalescing to both operandsImpact
total_pnl ?? 0)Testing
Fixes #633
🤖 Generated with Claude Code
Co-Authored-By: Claude [email protected]