feat: fix AI learning dashboard data display and analysis tools

- Fix position-history API case sensitivity for WIN/LOSS outcomes
- Update trade filtering to properly distinguish real vs simulation trades
- Correct database record for real trade (6.13 profit, 100% win rate)

- ai-learning-dashboard.js: Comprehensive AI intelligence report
- analyze-learning-progress.js: Learning system progress analysis
- analyze-decision-patterns.js: AI decision pattern analysis
- analyze-learning-intelligence.js: Deep learning system insights
- test-trade-data.js: Trade data validation and filtering tests
- fix-real-trade.js: Utility to correct trade classifications

- Dashboard now shows 1 real trade (previously 0)
- 100% win rate with .13 total P&L
- 9,767+ AI learning records properly separated from real trades
- Real-time trading performance data vs analysis-only data

 Result: AI Learning System dashboard displays accurate real trading data
This commit is contained in:
mindesbunister
2025-07-28 18:40:05 +02:00
parent fd25f4c8e9
commit 3a305c8cc4
8 changed files with 934 additions and 12 deletions

View File

@@ -183,15 +183,12 @@ export async function GET() {
const prisma = new PrismaClient();
try {
// Get completed trades from database
// Get completed trades from database (exclude simulation trades)
const completedTrades = await prisma.trades.findMany({
where: {
status: 'COMPLETED',
driftTxId: {
not: null,
not: { startsWith: 'SIM_' } // Exclude simulation trades
},
tradingMode: 'PERP' // Only perpetual trades
profit: { not: null }, // Must have profit/loss data
outcome: { not: null } // Must have win/loss outcome
},
orderBy: {
closedAt: 'desc'
@@ -199,10 +196,28 @@ export async function GET() {
take: 50 // Last 50 trades
});
console.log(`📊 Found ${completedTrades.length} completed trades in database`);
console.log(`📊 Found ${completedTrades.length} completed trades with profit data`);
// Filter out simulation trades after fetching
const realTrades = completedTrades.filter(trade => {
// Exclude if driftTxId starts with SIM_
if (trade.driftTxId && trade.driftTxId.startsWith('SIM_')) {
console.log(`🚫 Excluding simulation trade: ${trade.driftTxId}`);
return false;
}
// Exclude if tradingMode is explicitly SIMULATION
if (trade.tradingMode === 'SIMULATION') {
console.log(`🚫 Excluding simulation mode trade: ${trade.id}`);
return false;
}
console.log(`✅ Including real trade: ${trade.id} (${trade.tradingMode})`);
return true;
});
console.log(`📊 After filtering simulations: ${realTrades.length} real trades`);
// Convert to standardized format
realTradeHistory = completedTrades.map(trade => ({
realTradeHistory = realTrades.map(trade => ({
id: trade.id,
symbol: trade.symbol,
side: trade.side,
@@ -222,7 +237,7 @@ export async function GET() {
aiAnalysis: trade.aiAnalysis
}));
console.log(`✅ Successfully processed ${realTradeHistory.length} trades from database`);
console.log(`✅ Successfully processed ${realTradeHistory.length} real trades from database`);
} finally {
await prisma.$disconnect();
@@ -243,9 +258,13 @@ export async function GET() {
// Only use real data - no demo/mock data
const historicalTrades = realTradeHistory
// Calculate statistics
const wins = historicalTrades.filter(trade => trade.outcome === 'win')
const losses = historicalTrades.filter(trade => trade.outcome === 'loss')
// Calculate statistics (case-insensitive matching)
const wins = historicalTrades.filter(trade =>
trade.outcome && trade.outcome.toUpperCase() === 'WIN'
)
const losses = historicalTrades.filter(trade =>
trade.outcome && trade.outcome.toUpperCase() === 'LOSS'
)
const totalPnl = historicalTrades.reduce((sum, trade) => sum + (trade.pnl || 0), 0)
const winsPnl = wins.reduce((sum, trade) => sum + (trade.pnl || 0), 0)