✅ Major Achievement: - Implemented comprehensive multi-screenshot AI analysis - Both AI and DIY layout screenshots analyzed simultaneously - Cross-layout comparison for enhanced trading decisions - Cost-optimized with GPT-4o mini (~0.6 cents per analysis) 🔧 Technical Implementation: - Added analyzeMultipleScreenshots() method to AIAnalysisService - Enhanced API to handle single vs multi-screenshot analysis - Updated UI to display layout comparison insights - Fixed deprecated gpt-4-vision-preview → gpt-4o-mini 🎯 AI Analysis Features: - Layout-specific insights (AI Layout vs DIY Module) - Consensus detection between different chart views - Divergence analysis for conflicting signals - Enhanced confidence scoring based on multi-layout agreement - Comprehensive trading setup with entry/stop/targets 💰 Cost Optimization: - Switched from GPT-4o (/usr/bin/bash.048/analysis) to GPT-4o mini (/usr/bin/bash.006/analysis) - 8x cost reduction while maintaining analysis quality - ~.80/month for 10 daily analyses 🖥️ Enhanced UI Components: - Multi-layout analysis display sections - Cross-layout consensus indicators - Layout comparison visualization - Enhanced trading setup presentation 📊 Test Results: - Both AI and DIY screenshots captured successfully - Multi-layout analysis working flawlessly - Comprehensive trading recommendations generated - Entry/stop/target levels provided with rationale Ready for production trading analysis! 🚀
131 lines
4.6 KiB
JavaScript
131 lines
4.6 KiB
JavaScript
#!/usr/bin/env node
|
||
|
||
/**
|
||
* Test script for the dual-session enhanced screenshot service
|
||
* Uses API calls instead of direct imports for Docker compatibility
|
||
*/
|
||
|
||
async function testDualSessionScreenshots() {
|
||
console.log('🚀 Testing Enhanced Screenshot Service with Dual Sessions (API)')
|
||
|
||
try {
|
||
// Test configuration
|
||
const config = {
|
||
symbol: 'SOLUSD',
|
||
timeframe: '240',
|
||
layouts: ['ai', 'diy'],
|
||
analyze: true // Request AI analysis of both screenshots
|
||
}
|
||
|
||
console.log('📋 Test Configuration:', config)
|
||
|
||
// Test API endpoint availability
|
||
console.log('\n🔍 Checking API endpoint...')
|
||
const healthResponse = await fetch('http://localhost:3000/api/enhanced-screenshot')
|
||
if (!healthResponse.ok) {
|
||
throw new Error(`API endpoint not available: ${healthResponse.status}`)
|
||
}
|
||
const healthData = await healthResponse.json()
|
||
console.log('✅ API endpoint available:', healthData.message)
|
||
|
||
// Perform the dual-session screenshot capture via API
|
||
console.log('\n🔄 Starting dual-session capture via API...')
|
||
const startTime = Date.now()
|
||
|
||
const response = await fetch('http://localhost:3000/api/enhanced-screenshot', {
|
||
method: 'POST',
|
||
headers: {
|
||
'Content-Type': 'application/json'
|
||
},
|
||
body: JSON.stringify(config)
|
||
})
|
||
|
||
const endTime = Date.now()
|
||
const duration = (endTime - startTime) / 1000
|
||
|
||
if (!response.ok) {
|
||
const errorData = await response.json()
|
||
throw new Error(`API request failed: ${errorData.error || response.statusText}`)
|
||
}
|
||
|
||
const result = await response.json()
|
||
|
||
console.log('\n✅ Capture completed!')
|
||
console.log(`⏱️ Duration: ${duration.toFixed(2)} seconds`)
|
||
console.log(`📸 Screenshots captured: ${result.screenshots?.length || 0}`)
|
||
|
||
if (result.screenshots) {
|
||
result.screenshots.forEach((screenshot, index) => {
|
||
console.log(` ${index + 1}. ${screenshot}`)
|
||
})
|
||
}
|
||
|
||
if (result.screenshots?.length === 2) {
|
||
console.log('\n🎯 SUCCESS: Both AI and DIY layouts captured successfully!')
|
||
} else {
|
||
console.log('\n⚠️ WARNING: Expected 2 screenshots, got', result.screenshots?.length || 0)
|
||
if (result.errors) {
|
||
console.log('📋 Errors encountered:')
|
||
result.errors.forEach((error, index) => {
|
||
console.log(` ${index + 1}. ${error}`)
|
||
})
|
||
}
|
||
}
|
||
|
||
// Display AI analysis results if available
|
||
if (result.analysis) {
|
||
console.log('\n🤖 AI Analysis Results:')
|
||
console.log(` 📊 Market Sentiment: ${result.analysis.marketSentiment}`)
|
||
console.log(` 📈 Recommendation: ${result.analysis.recommendation}`)
|
||
console.log(` 🎯 Confidence: ${result.analysis.confidence}%`)
|
||
if (result.analysis.entry) {
|
||
console.log(` 💰 Entry: $${result.analysis.entry.price}`)
|
||
}
|
||
if (result.analysis.keyLevels) {
|
||
console.log(` 🔴 Resistance: ${result.analysis.keyLevels.resistance?.join(', ') || 'None'}`)
|
||
console.log(` 🟢 Support: ${result.analysis.keyLevels.support?.join(', ') || 'None'}`)
|
||
}
|
||
if (result.analysis.layoutComparison) {
|
||
console.log('\n🔄 Layout Comparison:')
|
||
console.log(` 📊 AI Layout: ${result.analysis.layoutComparison.aiLayout}`)
|
||
console.log(` 🔧 DIY Layout: ${result.analysis.layoutComparison.diyLayout}`)
|
||
console.log(` ✅ Consensus: ${result.analysis.layoutComparison.consensus}`)
|
||
}
|
||
} else {
|
||
console.log('\n⚠️ No AI analysis results received')
|
||
}
|
||
|
||
// Test summary
|
||
console.log('\n📊 Test Summary:')
|
||
console.log(` • API Response: ${response.ok ? 'Success' : 'Failed'}`)
|
||
console.log(` • Duration: ${duration.toFixed(2)}s`)
|
||
console.log(` • Screenshots: ${result.screenshots?.length || 0}/2`)
|
||
console.log(` • Success Rate: ${((result.screenshots?.length || 0) / 2 * 100).toFixed(0)}%`)
|
||
|
||
} catch (error) {
|
||
console.error('\n❌ Test failed:', error.message)
|
||
console.error('Stack trace:', error.stack)
|
||
process.exit(1)
|
||
}
|
||
}
|
||
|
||
// Run the test
|
||
if (require.main === module) {
|
||
// Add fetch for Node.js environments that don't have it built-in
|
||
if (typeof fetch === 'undefined') {
|
||
global.fetch = require('node-fetch')
|
||
}
|
||
|
||
testDualSessionScreenshots()
|
||
.then(() => {
|
||
console.log('\n🎉 All tests completed successfully!')
|
||
process.exit(0)
|
||
})
|
||
.catch((error) => {
|
||
console.error('\n💥 Test suite failed:', error)
|
||
process.exit(1)
|
||
})
|
||
}
|
||
|
||
module.exports = { testDualSessionScreenshots }
|