Fix: Correct Profit Factor calculation and display units in AI Learning

Backend changes (logger/decision_logger.go):
- Fixed Profit Factor to use standard formula (total profit / total loss)
- Previously used average values which was incorrect when win/loss counts differ
- Now saves total amounts before calculating averages for accurate ratio
Frontend changes (web/src/components/AILearning.tsx):
- Fixed display units: changed USDT amounts from "%" to "USDT"
- Updated avg_win and avg_loss to show "USDT Average" instead of "%"
- Updated best/worst performer displays to show "USDT" instead of "%"
- Added "(USDT)" labels to table headers for clarity
- Removed "%" from all table data cells showing monetary amounts
This ensures accurate performance metrics and eliminates user confusion
between percentage values and absolute USDT amounts.
Co-Authored-By: tinkle-community <tinklefund@gmail.com>
This commit is contained in:
tinkle-community
2025-10-29 17:59:19 +08:00
parent 3e5a701859
commit b9ea3f68ea
2 changed files with 18 additions and 12 deletions

View File

@@ -429,6 +429,10 @@ func (l *DecisionLogger) AnalyzePerformance(lookbackCycles int) (*PerformanceAna
if analysis.TotalTrades > 0 {
analysis.WinRate = (float64(analysis.WinningTrades) / float64(analysis.TotalTrades)) * 100
// 计算总盈利和总亏损
totalWinAmount := analysis.AvgWin // 当前是累加的总和
totalLossAmount := analysis.AvgLoss // 当前是累加的总和(负数)
if analysis.WinningTrades > 0 {
analysis.AvgWin /= float64(analysis.WinningTrades)
}
@@ -436,8 +440,10 @@ func (l *DecisionLogger) AnalyzePerformance(lookbackCycles int) (*PerformanceAna
analysis.AvgLoss /= float64(analysis.LosingTrades)
}
if analysis.AvgLoss != 0 {
analysis.ProfitFactor = analysis.AvgWin / (-analysis.AvgLoss)
// Profit Factor = 总盈利 / 总亏损(绝对值)
// 注意totalLossAmount 是负数,所以取负号得到绝对值
if totalLossAmount != 0 {
analysis.ProfitFactor = totalWinAmount / (-totalLossAmount)
}
}