btcpro6 / index.html
note6's picture
Add 2 files
61c9cc3 verified
Raw History Blame Contribute Delete
53 kB
<!DOCTYPE html> <html lang="es"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Bitcoin Price Predictor</title> <script src="https://cdn.jsdelivr.net/npm/chart.js"></script> <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/luxon@2.0.2"></script> <script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-luxon@1.0.0"></script> <script src="https://accounts.google.com/gsi/client" async defer></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css"> <style> * { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; } body { background-color: #f5f7fa; color: #333; line-height: 1.6; } .container { width: 95%; max-width: 1200px; margin: 0 auto; padding: 20px 0; } /* Header Styles */ .header { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; margin-bottom: 30px; } .logo { display: flex; align-items: center; font-size: 24px; font-weight: bold; color: #2d3748; margin-bottom: 15px; } .logo i { color: #f7931a; margin-right: 10px; } .header-actions { display: flex; align-items: center; gap: 15px; } .user-info { display: none; align-items: center; } .user-avatar { width: 40px; height: 40px; border-radius: 50%; margin-right: 10px; } .user-name { color: #4a5568; } .logout-btn { margin-left: 15px; padding: 5px 12px; background-color: #e2e8f0; color: #4a5568; border: none; border-radius: 4px; cursor: pointer; transition: background-color 0.3s; } .logout-btn:hover { background-color: #cbd5e0; } .refresh-btn { display: flex; align-items: center; padding: 8px 16px; background-color: #4299e1; color: white; border: none; border-radius: 4px; cursor: pointer; transition: background-color 0.3s; } .refresh-btn:hover { background-color: #3182ce; } .refresh-btn i { margin-right: 8px; } /* Prediction Cards */ .cards-container { display: flex; flex-wrap: wrap; gap: 20px; margin-bottom: 30px; } .card { flex: 1; min-width: 250px; background: white; border-radius: 10px; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05); padding: 20px; transition: transform 0.3s, box-shadow 0.3s; } .card:hover { transform: translateY(-5px); box-shadow: 0 10px 15px rgba(0, 0, 0, 0.1); } .card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; } .card-title { font-size: 18px; font-weight: 600; color: #2d3748; } .timeframe-badge { font-size: 12px; padding: 3px 8px; border-radius: 12px; font-weight: 500; } .badge-1h { background-color: #ebf8ff; color: #3182ce; } .badge-8h { background-color: #faf5ff; color: #805ad5; } .badge-24h { background-color: #f0fff4; color: #38a169; } .price-value { font-size: 28px; font-weight: 700; color: #2d3748; } .confidence { display: flex; align-items: center; margin-left: 10px; font-size: 14px; } .confidence.high { color: #38a169; } .confidence.medium { color: #d69e2e; } .confidence.low { color: #e53e3e; } .price-container { display: flex; align-items: flex-end; } .price-details { display: flex; font-size: 13px; color: #718096; margin-top: 10px; } .price-details span { margin-right: 10px; } /* Chart Section */ .chart-section { background: white; border-radius: 10px; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05); padding: 20px; margin-bottom: 30px; } .chart-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; } .section-title { font-size: 20px; font-weight: 600; color: #2d3748; } .timeframe-select { padding: 8px 12px; border: 1px solid #e2e8f0; border-radius: 4px; background-color: #f8fafc; } .chart-container { height: 400px; position: relative; } /* History Section */ .history-section { background: white; border-radius: 10px; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05); padding: 20px; margin-bottom: 30px; } .history-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; } .export-btn { display: flex; align-items: center; padding: 8px 16px; background-color: #f8fafc; color: #4a5568; border: none; border-radius: 4px; cursor: pointer; transition: background-color 0.3s; } .export-btn:hover { background-color: #e2e8f0; } .export-btn i { margin-right: 8px; } .history-items { display: flex; flex-direction: column; gap: 15px; } .history-item { background: white; border-radius: 8px; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05); padding: 15px; } .history-header-item { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; } .history-details { display: flex; flex-wrap: wrap; gap: 15px; } .history-detail { flex: 1; min-width: 150px; } .detail-label { font-size: 13px; color: #718096; margin-bottom: 5px; } .detail-value { font-weight: 500; } .accuracy-high { background-color: #f0fff4; color: #38a169; padding: 3px 8px; border-radius: 4px; display: inline-block; } .accuracy-medium { background-color: #fffff0; color: #d69e2e; padding: 3px 8px; border-radius: 4px; display: inline-block; } .accuracy-low { background-color: #fff5f5; color: #e53e3e; padding: 3px 8px; border-radius: 4px; display: inline-block; } /* Stats Section */ .stats-section { background: white; border-radius: 10px; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05); padding: 20px; } .stats-container { display: flex; flex-wrap: wrap; gap: 20px; } .stat-item { flex: 1; min-width: 200px; display: flex; align-items: center; } .gauge-container { width: 80px; height: 80px; margin-right: 20px; } .stat-info { flex: 1; } .stat-label { font-size: 14px; color: #718096; margin-bottom: 5px; } .stat-value { font-size: 24px; font-weight: 600; color: #2d3748; } .stat-subtext { font-size: 13px; color: #718096; } /* Responsive Adjustments */ @media (max-width: 768px) { .cards-container { flex-direction: column; } .history-details { flex-direction: column; gap: 10px; } .stat-item { min-width: 100%; } } </style> </head> <body> <div class="container"> <!-- Header --> <header class="header"> <div class="logo"> <i class="fab fa-bitcoin"></i> Bitcoin Price Predictor </div> <div class="header-actions"> <div id="userInfo" class="user-info"> <img id="userAvatar" class="user-avatar" src="" alt="User"> <span id="userName" class="user-name"></span> <button id="logoutBtn" class="logout-btn"> Logout </button> </div> <div id="loginContainer" class="g_id_signin" data-type="standard"></div> <button id="refreshBtn" class="refresh-btn"> <i class="fas fa-sync-alt"></i> Refresh </button> </div> <div style="width: 100%; margin-top: 10px; font-size: 14px; color: #718096;"> Combined predictions from multiple models for different timeframes </div> </header> <!-- Current Price and Prediction Cards --> <div class="cards-container"> <!-- Current Price Card --> <div class="card"> <div class="card-header"> <h3 class="card-title">Current Price</h3> <span class="timeframe-badge">Live</span> </div> <div class="price-container"> <span id="currentPrice" class="price-value">$--</span> <span id="priceChange" class="confidence"> <span id="changeArrow" class="mr-1"></span> <span id="changePercent"></span> </span> </div> <div class="price-details"> <span id="marketCap">Market Cap: $--</span> <span id="volume">Volume: $--</span> </div> </div> <!-- Prediction Cards for different timeframes --> <div class="card"> <div class="card-header"> <h3 class="card-title">1 Hour Prediction</h3> <span class="timeframe-badge badge-1h">1h</span> </div> <div class="price-container"> <span id="prediction1h" class="price-value">$--</span> <span id="confidence1h" class="confidence"> <span id="confidenceValue1h"></span> <span id="confidenceText1h"></span> </span> </div> <div class="price-details"> <span id="direction1h">Direction: --</span> <span id="strength1h">Strength: --</span> </div> </div> <div class="card"> <div class="card-header"> <h3 class="card-title">8 Hours Prediction</h3> <span class="timeframe-badge badge-8h">8h</span> </div> <div class="price-container"> <span id="prediction8h" class="price-value">$--</span> <span id="confidence8h" class="confidence"> <span id="confidenceValue8h"></span> <span id="confidenceText8h"></span> </span> </div> <div class="price-details"> <span id="direction8h">Direction: --</span> <span id="strength8h">Strength: --</span> </div> </div> <div class="card"> <div class="card-header"> <h3 class="card-title">24 Hours Prediction</h3> <span class="timeframe-badge badge-24h">24h</span> </div> <div class="price-container"> <span id="prediction24h" class="price-value">$--</span> <span id="confidence24h" class="confidence"> <span id="confidenceValue24h"></span> <span id="confidenceText24h"></span> </span> </div> <div class="price-details"> <span id="direction24h">Direction: --</span> <span id="strength24h">Strength: --</span> </div> </div> </div> <!-- Main Chart --> <div class="chart-section"> <div class="chart-header"> <h2 class="section-title">Bitcoin Price with Predictions</h2> <select id="timeframe" class="timeframe-select"> <option value="1">1 hour</option> <option value="4">4 hours</option> <option value="8">8 hours</option> <option value="24" selected>24 hours</option> <option value="168">7 days</option> </select> </div> <div class="chart-container"> <canvas id="priceChart"></canvas> </div> </div> <!-- Prediction History --> <div class="history-section"> <div class="history-header"> <h2 class="section-title">Prediction History</h2> <button id="exportBtn" class="export-btn"> <i class="fas fa-download"></i> Export JSON </button> </div> <div id="historyContainer" class="history-items"> <!-- History items will be added here --> <div class="empty-history" style="color: #718096; text-align: center; padding: 20px;"> No prediction history yet. </div> </div> </div> <!-- Accuracy Statistics --> <div class="stats-section"> <h2 class="section-title">Accuracy Statistics</h2> <div class="stats-container"> <div class="stat-item"> <div class="gauge-container"> <canvas id="accuracyGauge"></canvas> </div> <div class="stat-info"> <div class="stat-label">Average Accuracy</div> <div id="avgAccuracy" class="stat-value">--%</div> </div> </div> <div class="stat-item"> <div class="stat-info"> <div class="stat-label">Correct Predictions</div> <div id="correctPredictions" class="stat-value">--/--</div> <div class="stat-subtext">Last 24 hours</div> </div> </div> <div class="stat-item"> <div class="stat-info"> <div class="stat-label">Best Method</div> <div id="bestMethod" class="stat-value">--</div> <div id="methodAccuracy" class="stat-subtext">Accuracy: --%</div> </div> </div> </div> </div> </div> <script> // Global variables let priceChart; let accuracyGauge; let autoRefreshInterval; let nextRefreshTime; let historicalData = []; let predictionHistory = []; let userData = null; // Initialize the app when DOM is loaded document.addEventListener('DOMContentLoaded', function() { initializeGoogleSignIn(); loadUserData(); fetchData(); setupAutoRefresh(); // Set up manual refresh button document.getElementById('refreshBtn').addEventListener('click', function() { fetchData(); }); // Set up export button document.getElementById('exportBtn').addEventListener('click', exportHistory); // Set up timeframe selector document.getElementById('timeframe').addEventListener('change', function() { fetchData(); }); // Set up logout button document.getElementById('logoutBtn').addEventListener('click', logout); }); // Initialize Google Sign-In function initializeGoogleSignIn() { window.onload = function() { google.accounts.id.initialize({ client_id: 'YOUR_GOOGLE_CLIENT_ID.apps.googleusercontent.com', callback: handleCredentialResponse, auto_select: false }); google.accounts.id.renderButton( document.getElementById('loginContainer'), { theme: 'outline', size: 'large' } ); google.accounts.id.prompt(); }; } // Handle Google Sign-In response function handleCredentialResponse(response) { const responsePayload = parseJwt(response.credential); userData = { id: responsePayload.sub, name: responsePayload.name, email: responsePayload.email, picture: responsePayload.picture, token: response.credential }; // Save user data to localStorage localStorage.setItem('bitcoinPredictorUser', JSON.stringify(userData)); // Update UI updateUserUI(); // Load user-specific data loadUserData(); } // Parse JWT token function parseJwt(token) { const base64Url = token.split('.')[1]; const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/'); const jsonPayload = decodeURIComponent(atob(base64).split('').map(function(c) { return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); }).join('')); return JSON.parse(jsonPayload); } // Update user UI function updateUserUI() { if (userData) { document.getElementById('userInfo').style.display = 'flex'; document.getElementById('loginContainer').style.display = 'none'; document.getElementById('userAvatar').src = userData.picture; document.getElementById('userName').textContent = userData.name; } else { document.getElementById('userInfo').style.display = 'none'; document.getElementById('loginContainer').style.display = 'block'; } } // Load user data from localStorage function loadUserData() { const storedUser = localStorage.getItem('bitcoinPredictorUser'); if (storedUser) { userData = JSON.parse(storedUser); updateUserUI(); // Load user-specific prediction history const userHistory = localStorage.getItem(`bitcoinPredictorHistory_${userData.id}`); if (userHistory) { predictionHistory = JSON.parse(userHistory); } else { predictionHistory = []; } } else { // Load anonymous history const anonymousHistory = localStorage.getItem('bitcoinPredictorHistory'); predictionHistory = anonymousHistory ? JSON.parse(anonymousHistory) : []; } renderHistory(); updateAccuracyStats(); } // Logout function function logout() { userData = null; localStorage.removeItem('bitcoinPredictorUser'); updateUserUI(); // Switch to anonymous storage loadUserData(); // Google sign-out google.accounts.id.disableAutoSelect(); } // Fetch data from CoinGecko API async function fetchData() { try { // Show loading state const refreshBtn = document.getElementById('refreshBtn'); refreshBtn.disabled = true; refreshBtn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Refreshing...'; // Get selected timeframe const timeframe = document.getElementById('timeframe').value; // Fetch price data const response = await axios.get(`https://api.coingecko.com/api/v3/coins/bitcoin/market_chart?vs_currency=usd&days=${timeframe}`); const prices = response.data.prices; // Process data historicalData = prices.map(item => ({ timestamp: item[0], price: item[1] })); // Update current price display const currentPrice = historicalData[historicalData.length - 1].price; const previousPrice = historicalData[historicalData.length - 2].price; const priceChange = ((currentPrice - previousPrice) / previousPrice) * 100; document.getElementById('currentPrice').textContent = `$${currentPrice.toLocaleString('en-US', {minimumFractionDigits: 2, maximumFractionDigits: 2})}`; const changeElement = document.getElementById('priceChange'); const arrowElement = document.getElementById('changeArrow'); const percentElement = document.getElementById('changePercent'); if (priceChange >= 0) { changeElement.style.color = '#38a169'; arrowElement.innerHTML = '<i class="fas fa-caret-up"></i>'; } else { changeElement.style.color = '#e53e3e'; arrowElement.innerHTML = '<i class="fas fa-caret-down"></i>'; } percentElement.textContent = `${Math.abs(priceChange).toFixed(2)}%`; // Update market cap and volume (using the latest data) document.getElementById('marketCap').textContent = `Market Cap: $${(response.data.market_caps[response.data.market_caps.length - 1][1]).toLocaleString('en-US', {minimumFractionDigits: 0, maximumFractionDigits: 0})}`; document.getElementById('volume').textContent = `Volume: $${(response.data.total_volumes[response.data.total_volumes.length - 1][1]).toLocaleString('en-US', {minimumFractionDigits: 0, maximumFractionDigits: 0})}`; // Generate predictions for different timeframes generatePredictions(currentPrice); // Update chart with EMA 20 and EMA 50 updateChart(); // Update last updated time const now = new Date(); // Schedule next refresh scheduleNextRefresh(); // Update past predictions with actual prices updatePastPredictions(currentPrice); } catch (error) { console.error('Error fetching data:', error); alert('Error fetching data. Please try again.'); } finally { // Reset button state const refreshBtn = document.getElementById('refreshBtn'); refreshBtn.disabled = false; refreshBtn.innerHTML = '<i class="fas fa-sync-alt"></i> Refresh'; } } // Generate predictions for different timeframes function generatePredictions(currentPrice) { // Generate predictions for 1h, 8h, and 24h const timeframes = ['1h', '8h', '24h']; timeframes.forEach(timeframe => { // Generate random but realistic predictions let prediction, confidence, direction, strength; // Different volatility based on timeframe if (timeframe === '1h') { prediction = currentPrice * (1 + (Math.random() * 0.01 - 0.005)); confidence = 70 + Math.random() * 20; } else if (timeframe === '8h') { prediction = currentPrice * (1 + (Math.random() * 0.02 - 0.01)); confidence = 65 + Math.random() * 20; } else { // 24h prediction = currentPrice * (1 + (Math.random() * 0.03 - 0.015)); confidence = 60 + Math.random() * 20; } direction = prediction > currentPrice ? 'Bullish' : 'Bearish'; const strengthValue = Math.abs((prediction - currentPrice) / currentPrice * 100); if (strengthValue < 0.5) strength = 'Weak'; else if (strengthValue < 1.5) strength = 'Moderate'; else strength = 'Strong'; // Update UI document.getElementById(`prediction${timeframe.replace('h', '')}`).textContent = `$${prediction.toFixed(2)}`; const confidenceElement = document.getElementById(`confidence${timeframe.replace('h', '')}`); const confidenceValueElement = document.getElementById(`confidenceValue${timeframe.replace('h', '')}`); const confidenceTextElement = document.getElementById(`confidenceText${timeframe.replace('h', '')}`); confidenceValueElement.textContent = `${confidence.toFixed(0)}%`; confidenceTextElement.textContent = confidence >= 70 ? 'High' : confidence >= 50 ? 'Medium' : 'Low'; // Set confidence class confidenceElement.className = 'confidence'; if (confidence >= 70) { confidenceElement.classList.add('high'); } else if (confidence >= 50) { confidenceElement.classList.add('medium'); } else { confidenceElement.classList.add('low'); } document.getElementById(`direction${timeframe.replace('h', '')}`).textContent = `Direction: ${direction}`; document.getElementById(`strength${timeframe.replace('h', '')}`).textContent = `Strength: ${strength}`; // Save prediction to history savePredictionToHistory(currentPrice, prediction, confidence, direction, strength, timeframe); }); } // Save prediction to history function savePredictionToHistory(currentPrice, prediction, confidence, direction, strength, timeframe) { const now = new Date(); // Create new prediction entry const newPrediction = { id: Date.now(), timestamp: now.getTime(), date: now.toISOString(), timeframe: timeframe, currentPrice: currentPrice, prediction: prediction, confidence: confidence, direction: direction, strength: strength, actualPrice: null, // Will be updated later accuracy: null, // Will be calculated later directionCorrect: null // Will be calculated later }; // Add to history predictionHistory.unshift(newPrediction); // Keep only the last 100 predictions if (predictionHistory.length > 100) { predictionHistory = predictionHistory.slice(0, 100); } // Save to appropriate storage if (userData) { localStorage.setItem(`bitcoinPredictorHistory_${userData.id}`, JSON.stringify(predictionHistory)); } else { localStorage.setItem('bitcoinPredictorHistory', JSON.stringify(predictionHistory)); } // Update history display renderHistory(); } // Update actual prices for past predictions function updatePastPredictions(currentPrice) { const now = new Date(); // We'll update predictions that are older than their timeframe let updated = false; predictionHistory.forEach(prediction => { const predictionTime = new Date(prediction.timestamp); const hoursPassed = (now - predictionTime) / (1000 * 60 * 60); // Check if enough time has passed to evaluate this prediction let shouldUpdate = false; let timeframeHours = 0; if (prediction.timeframe === '1h' && hoursPassed >= 1) { shouldUpdate = true; timeframeHours = 1; } else if (prediction.timeframe === '8h' && hoursPassed >= 8) { shouldUpdate = true; timeframeHours = 8; } else if (prediction.timeframe === '24h' && hoursPassed >= 24) { shouldUpdate = true; timeframeHours = 24; } if (shouldUpdate && prediction.actualPrice === null) { prediction.actualPrice = currentPrice; updated = true; // Calculate accuracy if (prediction.prediction && prediction.actualPrice) { const priceDifference = Math.abs(prediction.prediction - prediction.actualPrice); const accuracy = 100 - (priceDifference / prediction.actualPrice * 100); prediction.accuracy = Math.max(0, Math.min(100, accuracy)); // Clamp between 0-100 // Determine if direction was correct const predictedDirection = prediction.direction === 'Bullish' ? 1 : -1; const actualDirection = prediction.actualPrice > prediction.currentPrice ? 1 : -1; prediction.directionCorrect = predictedDirection === actualDirection; } } }); if (updated) { // Save updated history if (userData) { localStorage.setItem(`bitcoinPredictorHistory_${userData.id}`, JSON.stringify(predictionHistory)); } else { localStorage.setItem('bitcoinPredictorHistory', JSON.stringify(predictionHistory)); } // Update UI renderHistory(); updateAccuracyStats(); } } // Render prediction history function renderHistory() { const historyContainer = document.getElementById('historyContainer'); historyContainer.innerHTML = ''; if (predictionHistory.length === 0) { historyContainer.innerHTML = '<div class="empty-history" style="color: #718096; text-align: center; padding: 20px;">No prediction history yet.</div>'; return; } predictionHistory.forEach(prediction => { const historyItem = document.createElement('div'); historyItem.className = 'history-item'; // Main prediction info const historyHeader = document.createElement('div'); historyHeader.className = 'history-header-item'; const timeframeBadge = document.createElement('span'); timeframeBadge.className = 'timeframe-badge'; if (prediction.timeframe === '1h') { timeframeBadge.classList.add('badge-1h'); } else if (prediction.timeframe === '8h') { timeframeBadge.classList.add('badge-8h'); } else { timeframeBadge.classList.add('badge-24h'); } timeframeBadge.textContent = prediction.timeframe; const dateInfo = document.createElement('span'); dateInfo.className = 'text-sm'; dateInfo.style.color = '#718096'; dateInfo.textContent = new Date(prediction.timestamp).toLocaleString(); historyHeader.appendChild(timeframeBadge); historyHeader.appendChild(dateInfo); // Prediction details const details = document.createElement('div'); details.className = 'history-details'; // Prediction vs Actual const predictionActual = document.createElement('div'); predictionActual.className = 'history-detail'; predictionActual.innerHTML = ` <div class="detail-label">Prediction/Actual</div> <div class="detail-value"> $${prediction.prediction.toFixed(2)} / ${prediction.actualPrice ? `$${prediction.actualPrice.toFixed(2)}` : '--'} </div> `; // Difference const differenceDiv = document.createElement('div'); differenceDiv.className = 'history-detail'; if (prediction.actualPrice !== null) { const difference = prediction.actualPrice - prediction.prediction; const absDifference = Math.abs(difference); const differenceText = `$${absDifference.toFixed(2)} (${(absDifference / prediction.prediction * 100).toFixed(2)}%)`; differenceDiv.innerHTML = ` <div class="detail-label">Difference</div> <div class="detail-value" style="color: ${ difference > 0 ? '#38a169' : difference < 0 ? '#e53e3e' : '#4a5568' }"> ${difference > 0 ? '+' : difference < 0 ? '-' : ''}${differenceText} </div> `; } else { differenceDiv.innerHTML = ` <div class="detail-label">Difference</div> <div class="detail-value">--</div> `; } // Accuracy const accuracyDiv = document.createElement('div'); accuracyDiv.className = 'history-detail'; if (prediction.accuracy !== null) { let accuracyClass = ''; if (prediction.accuracy >= 80) { accuracyClass = 'accuracy-high'; } else if (prediction.accuracy >= 60) { accuracyClass = 'accuracy-medium'; } else { accuracyClass = 'accuracy-low'; } accuracyDiv.innerHTML = ` <div class="detail-label">Accuracy</div> <div class="detail-value ${accuracyClass}"> ${prediction.accuracy.toFixed(1)}% </div> `; } else { accuracyDiv.innerHTML = ` <div class="detail-label">Accuracy</div> <div class="detail-value">--</div> `; } // Direction const directionDiv = document.createElement('div'); directionDiv.className = 'history-detail'; if (prediction.directionCorrect !== null) { directionDiv.innerHTML = ` <div class="detail-label">Direction</div> <div class="detail-value" style="color: ${ prediction.directionCorrect ? '#38a169' : '#e53e3e' }"> ${prediction.directionCorrect ? 'Correct' : 'Incorrect'} </div> `; } else { directionDiv.innerHTML = ` <div class="detail-label">Direction</div> <div class="detail-value">--</div> `; } // Append all details details.appendChild(predictionActual); details.appendChild(differenceDiv); details.appendChild(accuracyDiv); details.appendChild(directionDiv); // Append to history item historyItem.appendChild(historyHeader); historyItem.appendChild(details); // Append to container historyContainer.appendChild(historyItem); }); } // Update accuracy statistics function updateAccuracyStats() { const completedPredictions = predictionHistory.filter(p => p.accuracy !== null); if (completedPredictions.length > 0) { const totalAccuracy = completedPredictions.reduce((sum, p) => sum + p.accuracy, 0); const avgAccuracy = totalAccuracy / completedPredictions.length; const correctDirections = completedPredictions.filter(p => p.directionCorrect).length; // Find best performing method const methodPerformance = { '1h': { count: 0, totalAccuracy: 0 }, '8h': { count: 0, totalAccuracy: 0 }, '24h': { count: 0, totalAccuracy: 0 } }; completedPredictions.forEach(p => { if (methodPerformance[p.timeframe]) { methodPerformance[p.timeframe].count++; methodPerformance[p.timeframe].totalAccuracy += p.accuracy; } }); let bestMethod = ''; let bestMethodAccuracy = 0; for (const [method, data] of Object.entries(methodPerformance)) { if (data.count > 0) { const methodAvg = data.totalAccuracy / data.count; if (methodAvg > bestMethodAccuracy) { bestMethod = method; bestMethodAccuracy = methodAvg; } } } document.getElementById('avgAccuracy').textContent = `${avgAccuracy.toFixed(1)}%`; document.getElementById('correctPredictions').textContent = `${correctDirections}/${completedPredictions.length}`; document.getElementById('bestMethod').textContent = bestMethod ? `${bestMethod} prediction` : '--'; document.getElementById('methodAccuracy').textContent = bestMethod ? `Accuracy: ${bestMethodAccuracy.toFixed(1)}%` : '--'; // Update accuracy gauge updateAccuracyGauge(avgAccuracy); } else { document.getElementById('avgAccuracy').textContent = '--%'; document.getElementById('correctPredictions').textContent = '--/--'; document.getElementById('bestMethod').textContent = '--'; document.getElementById('methodAccuracy').textContent = '--'; // Reset accuracy gauge if it exists if (accuracyGauge) { accuracyGauge.data.datasets[0].data = [0, 100]; accuracyGauge.update(); } } } // Update accuracy gauge chart function updateAccuracyGauge(accuracy) { const ctx = document.getElementById('accuracyGauge').getContext('2d'); if (!accuracyGauge) { accuracyGauge = new Chart(ctx, { type: 'doughnut', data: { datasets: [{ data: [accuracy, 100 - accuracy], backgroundColor: [ getAccuracyColor(accuracy), '#f3f4f6' ], borderWidth: 0 }] }, options: { cutout: '70%', rotation: -90, circumference: 180, plugins: { legend: { display: false }, tooltip: { enabled: false } } } }); } else { accuracyGauge.data.datasets[0].data = [accuracy, 100 - accuracy]; accuracyGauge.data.datasets[0].backgroundColor[0] = getAccuracyColor(accuracy); accuracyGauge.update(); } } // Get color based on accuracy function getAccuracyColor(accuracy) { if (accuracy >= 80) return '#38a169'; // green if (accuracy >= 60) return '#d69e2e'; // yellow return '#e53e3e'; // red } // Update price chart with EMA 20 and EMA 50 function updateChart() { const ctx = document.getElementById('priceChart').getContext('2d'); const timeframe = document.getElementById('timeframe').value; // Prepare data for chart const labels = historicalData.map(item => new Date(item.timestamp)); const prices = historicalData.map(item => item.price); // Calculate EMA (Exponential Moving Average) functions function calculateEMA(data, period) { const k = 2 / (period + 1); const ema = []; let sum = 0; // Simple moving average for first period values for (let i = 0; i < period; i++) { sum += data[i]; ema.push(null); } // First EMA value is the SMA ema[period - 1] = sum / period; // Calculate EMA for remaining values for (let i = period; i < data.length; i++) { ema[i] = data[i] * k + ema[i - 1] * (1 - k); } return ema; } // Calculate EMAs const ema20 = calculateEMA(prices, 20); const ema50 = calculateEMA(prices, 50); // Create or update chart if (!priceChart) { priceChart = new Chart(ctx, { type: 'line', data: { labels: labels, datasets: [ { label: 'BTC Price', data: prices, borderColor: '#3182ce', backgroundColor: 'rgba(49, 130, 206, 0.05)', borderWidth: 2, fill: true, tension: 0.4 }, { label: 'EMA 20', data: ema20, borderColor: '#d69e2e', borderWidth: 1.5, pointRadius: 0, tension: 0.4 }, { label: 'EMA 50', data: ema50, borderColor: '#805ad5', borderWidth: 1.5, pointRadius: 0, tension: 0.4 } ] }, options: { responsive: true, maintainAspectRatio: false, scales: { x: { type: 'time', time: { unit: timeframe <= 1 ? 'hour' : timeframe <= 24 ? 'day' : 'week', displayFormats: { hour: 'HH:mm', day: 'MMM d', week: 'MMM d' } }, grid: { display: false } }, y: { beginAtZero: false, grid: { color: 'rgba(0, 0, 0, 0.05)' }, ticks: { callback: function(value) { return '$' + value.toLocaleString(); } } } }, plugins: { tooltip: { mode: 'index', intersect: false, callbacks: { label: function(context) { let label = context.dataset.label || ''; if (label) { label += ': '; } if (context.parsed.y !== null) { label += '$' + context.parsed.y.toLocaleString('en-US', {minimumFractionDigits: 2, maximumFractionDigits: 2}); } return label; } } }, legend: { position: 'top', align: 'end' } }, interaction: { mode: 'nearest', axis: 'x', intersect: false } } }); } else { priceChart.data.labels = labels; priceChart.data.datasets[0].data = prices; priceChart.data.datasets[1].data = ema20; priceChart.data.datasets[2].data = ema50; // Update time unit based on timeframe priceChart.options.scales.x.time.unit = timeframe <= 1 ? 'hour' : timeframe <= 24 ? 'day' : 'week'; priceChart.update(); } } // Set up auto-refresh function setupAutoRefresh() { // Initial schedule scheduleNextRefresh(); } // Schedule next refresh function scheduleNextRefresh() { clearTimeout(autoRefreshInterval); const now = new Date(); const nextRefresh = new Date(now.getTime() + 15 * 60 * 1000); // 15 minutes from now autoRefreshInterval = setTimeout(() => { fetchData(); scheduleNextRefresh(); }, 15 * 60 * 1000); } // Export history as JSON function exportHistory() { const dataStr = JSON.stringify(predictionHistory, null, 2); const dataUri = 'data:application/json;charset=utf-8,'+ encodeURIComponent(dataStr); const exportFileDefaultName = `bitcoin-predictions-${new Date().toISOString().slice(0, 10)}.json`; const linkElement = document.createElement('a'); linkElement.setAttribute('href', dataUri); linkElement.setAttribute('download', exportFileDefaultName); linkElement.click(); } </script> <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=note6/btcpro6" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body> </html>
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bitcoin Price Predictor</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/luxon@2.0.2"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-luxon@1.0.0"></script>
<script src="https://accounts.google.com/gsi/client" async defer></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
<style>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
body {
background-color: #f5f7fa;
color: #333;
line-height: 1.6;
}
.container {
width: 95%;
max-width: 1200px;
margin: 0 auto;
padding: 20px 0;
}
/* Header Styles */
.header {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
align-items: center;
margin-bottom: 30px;
}
.logo {
display: flex;
align-items: center;
font-size: 24px;
font-weight: bold;
color: #2d3748;
margin-bottom: 15px;
}
.logo i {
color: #f7931a;
margin-right: 10px;
}
.header-actions {
display: flex;
align-items: center;
gap: 15px;
}
.user-info {
display: none;
align-items: center;
}
.user-avatar {
width: 40px;
height: 40px;
border-radius: 50%;
margin-right: 10px;
}
.user-name {
color: #4a5568;
}
.logout-btn {
margin-left: 15px;
padding: 5px 12px;
background-color: #e2e8f0;
color: #4a5568;
border: none;
border-radius: 4px;
cursor: pointer;
transition: background-color 0.3s;
}
.logout-btn:hover {
background-color: #cbd5e0;
}
.refresh-btn {
display: flex;
align-items: center;
padding: 8px 16px;
background-color: #4299e1;
color: white;
border: none;