File size: 39,998 Bytes
479619f ea7f268 479619f ea7f268 479619f ea7f268 479619f ea7f268 479619f ea7f268 479619f ea7f268 479619f ea7f268 479619f ea7f268 479619f ea7f268 479619f ea7f268 479619f ea7f268 479619f ea7f268 479619f ea7f268 479619f ea7f268 479619f ea7f268 479619f ea7f268 479619f ea7f268 479619f ea7f268 479619f ea7f268 479619f ea7f268 479619f ea7f268 479619f ea7f268 479619f ea7f268 479619f ea7f268 479619f ea7f268 479619f ea7f268 479619f ea7f268 479619f ea7f268 479619f ea7f268 479619f ea7f268 479619f ea7f268 479619f ea7f268 479619f ea7f268 479619f ea7f268 479619f ea7f268 479619f ea7f268 479619f ea7f268 479619f ea7f268 479619f ea7f268 479619f ea7f268 479619f ea7f268 479619f ea7f268 479619f ea7f268 479619f ea7f268 479619f ea7f268 479619f ea7f268 479619f ea7f268 479619f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 | <!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>
<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: 100%;
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}
/* Header styles */
.header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 30px;
flex-wrap: wrap;
}
.header-title {
display: flex;
align-items: center;
font-size: 28px;
font-weight: bold;
color: #2d3748;
}
.header-title i {
color: #f7931a;
margin-right: 10px;
}
.header-controls {
display: flex;
align-items: center;
}
.refresh-btn {
background-color: #3182ce;
color: white;
border: none;
padding: 8px 16px;
border-radius: 6px;
cursor: pointer;
display: flex;
align-items: center;
margin-right: 15px;
transition: background-color 0.3s;
}
.refresh-btn:hover {
background-color: #2c5282;
}
.refresh-btn i {
margin-right: 5px;
}
.last-updated {
font-size: 14px;
color: #718096;
}
.header-subtitle {
width: 100%;
margin-top: 10px;
color: #4a5568;
font-size: 14px;
}
/* Prediction cards */
.predictions-container {
display: flex;
flex-wrap: wrap;
gap: 20px;
margin-bottom: 30px;
}
.prediction-card {
flex: 1;
min-width: 200px;
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;
}
.prediction-card:hover {
transform: translateY(-5px);
box-shadow: 0 10px 15px rgba(0, 0, 0, 0.1);
}
.prediction-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 15px;
}
.prediction-title {
font-size: 16px;
font-weight: 600;
color: #2d3748;
}
.prediction-badge {
font-size: 12px;
padding: 3px 8px;
border-radius: 20px;
}
.badge-1h {
background-color: #ebf8ff;
color: #3182ce;
}
.badge-8h {
background-color: #faf5ff;
color: #805ad5;
}
.badge-12h {
background-color: #fff5f5;
color: #e53e3e;
}
.badge-24h {
background-color: #f0fff4;
color: #38a169;
}
.prediction-price {
font-size: 24px;
font-weight: 700;
color: #2d3748;
margin-bottom: 5px;
}
.prediction-stats {
display: flex;
flex-direction: column;
gap: 5px;
font-size: 14px;
color: #4a5568;
}
.prediction-row {
display: flex;
justify-content: space-between;
}
.prediction-label {
color: #718096;
}
.prediction-value {
font-weight: 500;
}
.price-up {
color: #38a169;
}
.price-down {
color: #e53e3e;
}
/* Main chart */
.chart-container {
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;
}
.chart-title {
font-size: 20px;
font-weight: 600;
color: #2d3748;
}
.timeframe-select {
padding: 6px 12px;
border-radius: 6px;
border: 1px solid #e2e8f0;
background-color: #f8fafc;
font-size: 14px;
}
.chart-wrapper {
height: 400px;
position: relative;
}
/* History table */
.history-container {
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;
}
.history-title {
font-size: 20px;
font-weight: 600;
color: #2d3748;
}
.history-controls {
display: flex;
gap: 10px;
}
.history-btn {
background-color: #e2e8f0;
color: #4a5568;
border: none;
padding: 6px 12px;
border-radius: 6px;
cursor: pointer;
display: flex;
align-items: center;
font-size: 14px;
transition: background-color 0.3s;
}
.history-btn:hover {
background-color: #cbd5e0;
}
.history-btn i {
margin-right: 5px;
}
.history-table {
width: 100%;
border-collapse: collapse;
}
.history-table th {
text-align: left;
padding: 12px 15px;
font-size: 13px;
font-weight: 600;
color: #718096;
background-color: #f8fafc;
border-bottom: 1px solid #e2e8f0;
}
.history-table td {
padding: 12px 15px;
font-size: 14px;
color: #4a5568;
border-bottom: 1px solid #e2e8f0;
}
.history-table tr:nth-child(even) {
background-color: #f8fafc;
}
/* Accuracy colors */
.accuracy-high {
color: #38a169;
}
.accuracy-medium {
color: #d69e2e;
}
.accuracy-low {
color: #e53e3e;
}
/* Direction colors */
.direction-correct {
color: #38a169;
}
.direction-incorrect {
color: #e53e3e;
}
/* Responsive adjustments */
@media (max-width: 768px) {
.prediction-card {
min-width: 100%;
}
.header-title {
font-size: 24px;
margin-bottom: 10px;
}
.header-controls {
width: 100%;
justify-content: space-between;
}
.chart-wrapper {
height: 300px;
}
.history-controls {
flex-direction: column;
width: 100%;
}
.history-btn {
width: 100%;
justify-content: center;
}
}
</style>
</head>
<body>
<div class="container">
<header class="header">
<div class="header-title">
<i class="fab fa-bitcoin"></i> Bitcoin Price Predictor
</div>
<div class="header-controls">
<button id="refreshBtn" class="refresh-btn">
<i class="fas fa-sync-alt"></i> Actualizar
</button>
<span id="lastUpdated" class="last-updated"></span>
</div>
<div class="header-subtitle">
Predicciones para diferentes horizontes temporales
</div>
</header>
<!-- Prediction Cards -->
<div class="predictions-container">
<!-- 1h Prediction -->
<div class="prediction-card">
<div class="prediction-header">
<div class="prediction-title">Predicción 1h</div>
<span class="prediction-badge badge-1h">1 hora</span>
</div>
<div class="prediction-price" id="prediction-1h-price">$--</div>
<div class="prediction-stats">
<div class="prediction-row">
<span class="prediction-label">Confianza:</span>
<span class="prediction-value" id="prediction-1h-confidence">--%</span>
</div>
<div class="prediction-row">
<span class="prediction-label">Dirección:</span>
<span class="prediction-value" id="prediction-1h-direction">--</span>
</div>
<div class="prediction-row">
<span class="prediction-label">Precisión:</span>
<span class="prediction-value" id="prediction-1h-accuracy">--%</span>
</div>
</div>
</div>
<!-- 8h Prediction -->
<div class="prediction-card">
<div class="prediction-header">
<div class="prediction-title">Predicción 8h</div>
<span class="prediction-badge badge-8h">8 horas</span>
</div>
<div class="prediction-price" id="prediction-8h-price">$--</div>
<div class="prediction-stats">
<div class="prediction-row">
<span class="prediction-label">Confianza:</span>
<span class="prediction-value" id="prediction-8h-confidence">--%</span>
</div>
<div class="prediction-row">
<span class="prediction-label">Dirección:</span>
<span class="prediction-value" id="prediction-8h-direction">--</span>
</div>
<div class="prediction-row">
<span class="prediction-label">Precisión:</span>
<span class="prediction-value" id="prediction-8h-accuracy">--%</span>
</div>
</div>
</div>
<!-- 12h Prediction -->
<div class="prediction-card">
<div class="prediction-header">
<div class="prediction-title">Predicción 12h</div>
<span class="prediction-badge badge-12h">12 horas</span>
</div>
<div class="prediction-price" id="prediction-12h-price">$--</div>
<div class="prediction-stats">
<div class="prediction-row">
<span class="prediction-label">Confianza:</span>
<span class="prediction-value" id="prediction-12h-confidence">--%</span>
</div>
<div class="prediction-row">
<span class="prediction-label">Dirección:</span>
<span class="prediction-value" id="prediction-12h-direction">--</span>
</div>
<div class="prediction-row">
<span class="prediction-label">Precisión:</span>
<span class="prediction-value" id="prediction-12h-accuracy">--%</span>
</div>
</div>
</div>
<!-- 24h Prediction -->
<div class="prediction-card">
<div class="prediction-header">
<div class="prediction-title">Predicción 24h</div>
<span class="prediction-badge badge-24h">24 horas</span>
</div>
<div class="prediction-price" id="prediction-24h-price">$--</div>
<div class="prediction-stats">
<div class="prediction-row">
<span class="prediction-label">Confianza:</span>
<span class="prediction-value" id="prediction-24h-confidence">--%</span>
</div>
<div class="prediction-row">
<span class="prediction-label">Dirección:</span>
<span class="prediction-value" id="prediction-24h-direction">--</span>
</div>
<div class="prediction-row">
<span class="prediction-label">Precisión:</span>
<span class="prediction-value" id="prediction-24h-accuracy">--%</span>
</div>
</div>
</div>
</div>
<!-- Main Chart -->
<div class="chart-container">
<div class="chart-header">
<div class="chart-title">Precio de Bitcoin</div>
<div>
<select id="timeframe" class="timeframe-select">
<option value="1">1 hora</option>
<option value="4">4 horas</option>
<option value="12">12 horas</option>
<option value="24" selected>24 horas</option>
<option value="168">7 días</option>
</select>
</div>
</div>
<div class="chart-wrapper">
<canvas id="priceChart"></canvas>
</div>
</div>
<!-- Historical Predictions -->
<div class="history-container">
<div class="history-header">
<div class="history-title">Historial de Predicciones</div>
<div class="history-controls">
<button id="exportBtn" class="history-btn">
<i class="fas fa-download"></i> Exportar JSON
</button>
<button id="importBtn" class="history-btn">
<i class="fas fa-upload"></i> Importar JSON
</button>
<input type="file" id="importFile" style="display: none;" accept=".json">
</div>
</div>
<div style="overflow-x: auto;">
<table class="history-table">
<thead>
<tr>
<th>Fecha</th>
<th>Horizonte</th>
<th>Predicción</th>
<th>Real</th>
<th>Diferencia</th>
<th>Precisión</th>
<th>Dirección</th>
</tr>
</thead>
<tbody id="historyTable">
<!-- Rows will be added dynamically -->
</tbody>
</table>
</div>
</div>
</div>
<script>
// Global variables
let priceChart;
let historicalData = [];
let predictionHistory = JSON.parse(localStorage.getItem('predictionHistory')) || [];
let autoRefreshInterval;
// Initialize the app when DOM is loaded
document.addEventListener('DOMContentLoaded', function() {
fetchData();
setupAutoRefresh();
renderHistoryTable();
// Set up manual refresh button
document.getElementById('refreshBtn').addEventListener('click', function() {
fetchData();
});
// Set up export button
document.getElementById('exportBtn').addEventListener('click', exportHistory);
// Set up import button
document.getElementById('importBtn').addEventListener('click', function() {
document.getElementById('importFile').click();
});
document.getElementById('importFile').addEventListener('change', importHistory);
// Set up timeframe selector
document.getElementById('timeframe').addEventListener('change', function() {
fetchData();
});
});
// 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> Actualizando...';
// 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;
// Generate predictions for all timeframes
generatePredictions(currentPrice);
// Update chart
updateChart();
// Update last updated time
const now = new Date();
document.getElementById('lastUpdated').textContent = `Última actualización: ${now.toLocaleTimeString()}`;
// Schedule next refresh
scheduleNextRefresh();
// Update past predictions with actual prices
updatePastPredictions(currentPrice);
} catch (error) {
console.error('Error fetching data:', error);
alert('Error al obtener datos. Por favor intenta nuevamente.');
} finally {
// Reset button state
const refreshBtn = document.getElementById('refreshBtn');
refreshBtn.disabled = false;
refreshBtn.innerHTML = '<i class="fas fa-sync-alt"></i> Actualizar';
}
}
// Generate predictions for all timeframes
function generatePredictions(currentPrice) {
const timeframes = [1, 8, 12, 24];
timeframes.forEach(timeframe => {
// Generate random predictions (in a real app, this would be your prediction logic)
const prediction = currentPrice * (1 + (Math.random() * 0.02 - 0.01));
const confidence = 70 + Math.random() * 20;
const direction = prediction > currentPrice ? 'Alcista' : 'Bajista';
const accuracy = 75 + Math.random() * 20;
// Update prediction cards
updatePredictionCard(timeframe, prediction, confidence, direction, accuracy);
// Save prediction to history (only if it's a new prediction)
savePredictionToHistory(timeframe, currentPrice, prediction, confidence, direction);
});
}
// Update prediction card UI
function updatePredictionCard(timeframe, prediction, confidence, direction, accuracy) {
document.getElementById(`prediction-${timeframe}h-price`).textContent = `$${prediction.toFixed(2)}`;
document.getElementById(`prediction-${timeframe}h-confidence`).textContent = `${confidence.toFixed(0)}%`;
document.getElementById(`prediction-${timeframe}h-direction`).textContent = direction;
document.getElementById(`prediction-${timeframe}h-accuracy`).textContent = `${accuracy.toFixed(0)}%`;
// Color direction based on prediction
const directionElement = document.getElementById(`prediction-${timeframe}h-direction`);
if (direction === 'Alcista') {
directionElement.className = 'prediction-value price-up';
} else {
directionElement.className = 'prediction-value price-down';
}
}
// Save prediction to history
function savePredictionToHistory(timeframe, currentPrice, prediction, confidence, direction) {
const now = new Date();
// Check if we already have a prediction for this timeframe that hasn't been resolved
const existingPredictionIndex = predictionHistory.findIndex(p =>
p.timeframe === timeframe &&
p.actualPrice === null
);
if (existingPredictionIndex === -1) {
// Create new prediction entry
const newPrediction = {
timestamp: now.getTime(),
date: now.toISOString(),
currentPrice: currentPrice,
prediction: prediction,
confidence: confidence,
direction: direction,
timeframe: timeframe,
actualPrice: null,
accuracy: null,
directionCorrect: null
};
// Add to history
predictionHistory.unshift(newPrediction);
// Keep only the last 100 predictions per timeframe
const timeframePredictions = predictionHistory.filter(p => p.timeframe === timeframe);
if (timeframePredictions.length > 100) {
const toRemove = timeframePredictions.length - 100;
predictionHistory = predictionHistory.filter((p, index) =>
p.timeframe !== timeframe || index >= toRemove
);
}
// Save to localStorage
localStorage.setItem('predictionHistory', JSON.stringify(predictionHistory));
// Update history table
renderHistoryTable();
}
}
// Update actual prices for past predictions
function updatePastPredictions(currentPrice) {
const now = new Date();
[1, 8, 12, 24].forEach(timeframe => {
const timeframeMs = timeframe * 60 * 60 * 1000;
const predictionTime = now.getTime() - timeframeMs;
// Find the prediction made at the prediction time for this timeframe
const prediction = predictionHistory.find(p =>
p.timeframe === timeframe &&
p.timestamp <= predictionTime &&
p.actualPrice === null
);
if (prediction) {
prediction.actualPrice = currentPrice;
// 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 === 'Alcista' ? 1 : -1;
const actualDirection = prediction.actualPrice > prediction.currentPrice ? 1 : -1;
prediction.directionCorrect = predictedDirection === actualDirection;
}
}
});
// Save updated history
localStorage.setItem('predictionHistory', JSON.stringify(predictionHistory));
// Update UI
renderHistoryTable();
}
// Render history table
function renderHistoryTable() {
const tableBody = document.getElementById('historyTable');
tableBody.innerHTML = '';
// Sort by timestamp descending
const sortedHistory = [...predictionHistory].sort((a, b) => b.timestamp - a.timestamp);
sortedHistory.forEach((prediction, index) => {
const row = document.createElement('tr');
// Date cell
const dateCell = document.createElement('td');
dateCell.textContent = new Date(prediction.timestamp).toLocaleString();
// Timeframe cell
const timeframeCell = document.createElement('td');
timeframeCell.textContent = `${prediction.timeframe}h`;
// Prediction cell
const predictionCell = document.createElement('td');
predictionCell.textContent = prediction.prediction ? `$${prediction.prediction.toFixed(2)}` : '--';
// Actual price cell
const actualCell = document.createElement('td');
if (prediction.actualPrice !== null) {
actualCell.textContent = `$${prediction.actualPrice.toFixed(2)}`;
} else {
actualCell.textContent = '--';
}
// Difference cell
const differenceCell = document.createElement('td');
if (prediction.prediction && 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)}%)`;
if (difference > 0) {
differenceCell.innerHTML = `<span style="color: #38a169;">+${differenceText}</span>`;
} else if (difference < 0) {
differenceCell.innerHTML = `<span style="color: #e53e3e;">-${differenceText}</span>`;
} else {
differenceCell.textContent = differenceText;
}
} else {
differenceCell.textContent = '--';
}
// Accuracy cell
const accuracyCell = document.createElement('td');
if (prediction.accuracy !== null) {
const accuracyText = `${prediction.accuracy.toFixed(1)}%`;
let accuracyClass = '';
if (prediction.accuracy >= 90) accuracyClass = 'accuracy-high';
else if (prediction.accuracy >= 70) accuracyClass = 'accuracy-medium';
else accuracyClass = 'accuracy-low';
accuracyCell.innerHTML = `<span class="${accuracyClass}">${accuracyText}</span>`;
} else {
accuracyCell.textContent = '--';
}
// Direction cell
const directionCell = document.createElement('td');
if (prediction.directionCorrect !== null) {
if (prediction.directionCorrect) {
directionCell.innerHTML = `<span class="direction-correct">Correcta</span>`;
} else {
directionCell.innerHTML = `<span class="direction-incorrect">Incorrecta</span>`;
}
} else {
directionCell.textContent = '--';
}
// Add cells to row
row.appendChild(dateCell);
row.appendChild(timeframeCell);
row.appendChild(predictionCell);
row.appendChild(actualCell);
row.appendChild(differenceCell);
row.appendChild(accuracyCell);
row.appendChild(directionCell);
tableBody.appendChild(row);
});
}
// Update price chart
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: 'Precio BTC',
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() {
const autoRefreshCheckbox = document.getElementById('autoRefresh');
autoRefreshCheckbox.addEventListener('change', function() {
if (this.checked) {
scheduleNextRefresh();
} else {
clearTimeout(autoRefreshInterval);
}
});
// Initial schedule
scheduleNextRefresh();
}
// Schedule next refresh
function scheduleNextRefresh() {
clearTimeout(autoRefreshInterval);
autoRefreshInterval = setTimeout(() => {
fetchData();
scheduleNextRefresh();
}, 15 * 60 * 1000); // 15 minutes
}
// 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();
}
// Import history from JSON file
function importHistory(event) {
const file = event.target.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = function(e) {
try {
const importedData = JSON.parse(e.target.result);
if (Array.isArray(importedData)) {
predictionHistory = importedData;
localStorage.setItem('predictionHistory', JSON.stringify(predictionHistory));
// Update UI
renderHistoryTable();
alert('Datos importados correctamente!');
} else {
alert('El archivo no contiene datos válidos.');
}
} catch (error) {
console.error('Error importing data:', error);
alert('Error al importar datos. El archivo puede estar corrupto.');
}
// Reset file input
event.target.value = '';
};
reader.readAsText(file);
}
</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/btcpro7" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html> |