import { PrismaClient } from '@prisma/client'; import * as dotenv from 'dotenv'; import axios from 'axios'; dotenv.config(); // BigInt serialization fix (BigInt.prototype as any).toJSON = function () { return this.toString(); }; const prisma = new PrismaClient(); const matchIds = [ '7cnm7h7qbsq2bbaxngusojh90', // Club Brugge vs Anderlecht - TESTED āœ… '7lmrfu2k1e2uxprxfxgaevcb8', // Castellon vs Granada '3ko3otchy41d28rzxfpvl3d3o' // SV Ried vs Altach ]; async function getPrediction(matchId: string) { try { console.log(`\n${'='.repeat(80)}`); console.log(`šŸ”® PREDICTION REQUEST: ${matchId}`); console.log('='.repeat(80)); // Fetch match from database const match = await prisma.liveMatch.findUnique({ where: { id: matchId }, include: { homeTeam: true, awayTeam: true, league: true, }, }); if (!match) { console.log(`āŒ Match not found: ${matchId}`); return null; } console.log(`šŸ“Š ${match.homeTeam?.name} vs ${match.awayTeam?.name}`); console.log(`šŸ† League: ${match.league?.name}`); console.log(`šŸ“… Match Time: ${new Date(Number(match.mstUtc)).toISOString()}`); // Send prediction request to AI Engine const aiEngineUrl = 'http://localhost:8007'; const predictionUrl = `${aiEngineUrl}/v20plus/analyze/${matchId}`; console.log(`\nšŸ¤– Sending to AI Engine: ${predictionUrl}`); const startTime = Date.now(); const response = await axios.post(predictionUrl, {}, { timeout: 120000, // 2 minutes timeout }); const elapsed = ((Date.now() - startTime) / 1000).toFixed(2); console.log(`āœ… Prediction received in ${elapsed}s`); console.log(`\n${'='.repeat(80)}`); console.log(`šŸ“Š FULL PREDICTION JSON:`); console.log('='.repeat(80)); console.log(JSON.stringify(response.data, null, 2)); // Summary const pkg = response.data; if (pkg.main_pick) { console.log(`\n${'='.repeat(80)}`); console.log(`šŸŽÆ SUMMARY:`); console.log('='.repeat(80)); console.log(`Main Pick: ${pkg.main_pick.market} → ${pkg.main_pick.pick}`); console.log(`Confidence: ${pkg.main_pick.confidence}%`); console.log(`Odds: ${pkg.main_pick.odds}`); console.log(`Bet Grade: ${pkg.main_pick.bet_grade}`); console.log(`Edge: ${pkg.main_pick.edge || 'N/A'}`); if (pkg.value_pick) { console.log(`\nValue Pick: ${pkg.value_pick.market} → ${pkg.value_pick.pick}`); console.log(`Confidence: ${pkg.value_pick.confidence}%`); console.log(`Odds: ${pkg.value_pick.odds}`); } if (pkg.bet_advice) { console.log(`\nšŸ’” Bet Advice:`); console.log(` Playable: ${pkg.bet_advice.playable}`); console.log(` Stake: ${pkg.bet_advice.suggested_stake_units} units`); console.log(` Reason: ${pkg.bet_advice.reason}`); } if (pkg.score_prediction) { console.log(`\n⚽ Score Prediction:`); console.log(` FT: ${pkg.score_prediction.ft}`); console.log(` HT: ${pkg.score_prediction.ht}`); console.log(` xG: ${pkg.score_prediction.xg_home} - ${pkg.score_prediction.xg_away}`); } if (pkg.risk) { console.log(`\nāš ļø Risk Level: ${pkg.risk.level} (${pkg.risk.score})`); if (pkg.risk.warnings?.length > 0) { console.log(` Warnings: ${pkg.risk.warnings.join(', ')}`); } } if (pkg.ai_commentary) { console.log(`\nšŸ’¬ AI Commentary:`); console.log(` ${pkg.ai_commentary}`); } } return response.data; } catch (error: any) { console.error(`āŒ Error for match ${matchId}:`); if (error.response) { console.error(` Status: ${error.response.status}`); console.error(` Data: ${JSON.stringify(error.response.data, null, 2)}`); } else { console.error(` Message: ${error.message}`); } return null; } } async function main() { console.log('šŸš€ VQWEN v3 Prediction Engine - Batch Analysis'); console.log(`šŸ“” AI Engine: ${process.env.AI_ENGINE_URL || 'http://localhost:8007'}`); console.log(`šŸŽÆ Matches: ${matchIds.length}`); const results: { matchId: string; success: boolean }[] = []; for (const matchId of matchIds) { const result = await getPrediction(matchId); if (result) { results.push({ matchId, success: true }); } else { results.push({ matchId, success: false }); } // Small delay between requests await new Promise(resolve => setTimeout(resolve, 1000)); } console.log(`\n${'='.repeat(80)}`); console.log(`šŸ“Š BATCH SUMMARY:`); console.log('='.repeat(80)); results.forEach((r, i) => { console.log(`${r.success ? 'āœ…' : 'āŒ'} ${i + 1}. ${r.matchId}`); }); console.log(`\nTotal: ${results.filter(r => r.success).length}/${results.length} successful`); await prisma.$disconnect(); } main().catch(console.error);