Spaces:
Running
Running
File size: 48,014 Bytes
e7f347b |
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 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Golf Stat Tracker</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
.fade-enter-active, .fade-leave-active {
transition: opacity 0.3s;
}
.fade-enter, .fade-leave-to {
opacity: 0;
}
.slide-enter-active, .slide-leave-active {
transition: transform 0.3s;
}
.slide-enter, .slide-leave-to {
transform: translateX(100%);
}
.stat-card:hover {
transform: translateY(-5px);
box-shadow: 0 10px 20px rgba(0,0,0,0.1);
}
.hole-input:checked + label {
background-color: #10b981;
color: white;
}
</style>
</head>
<body class="bg-gray-50 min-h-screen">
<div class="container mx-auto px-4 py-8 max-w-6xl">
<!-- Header -->
<header class="mb-8">
<div class="flex justify-between items-center">
<h1 class="text-3xl font-bold text-green-800 flex items-center">
<i class="fas fa-golf-ball mr-3"></i> Golf Stat Tracker
</h1>
<button id="newRoundBtn" class="bg-green-600 hover:bg-green-700 text-white px-4 py-2 rounded-lg flex items-center">
<i class="fas fa-plus mr-2"></i> New Round
</button>
</div>
<p class="text-gray-600 mt-2">Track your golf performance and improve your game</p>
</header>
<!-- Main Content Area -->
<main>
<!-- Dashboard View (default) -->
<div id="dashboardView" class="space-y-8">
<!-- Stats Summary -->
<section class="bg-white rounded-xl shadow-md p-6">
<h2 class="text-xl font-semibold text-gray-800 mb-4">Your Performance Summary</h2>
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4">
<div class="stat-card bg-white border border-gray-200 rounded-lg p-4 transition-all duration-300">
<div class="flex justify-between items-start">
<div>
<p class="text-gray-500 text-sm">Bad Tee Shots</p>
<h3 class="text-2xl font-bold text-gray-800" id="badTeeShotsStat">0%</h3>
</div>
<div class="bg-red-100 p-2 rounded-full">
<i class="fas fa-times text-red-500"></i>
</div>
</div>
<p class="text-xs text-gray-500 mt-2">Last 5 rounds</p>
</div>
<div class="stat-card bg-white border border-gray-200 rounded-lg p-4 transition-all duration-300">
<div class="flex justify-between items-start">
<div>
<p class="text-gray-500 text-sm">Green Saves</p>
<h3 class="text-2xl font-bold text-gray-800" id="greenSavesStat">0%</h3>
</div>
<div class="bg-green-100 p-2 rounded-full">
<i class="fas fa-check text-green-500"></i>
</div>
</div>
<p class="text-xs text-gray-500 mt-2">When missed GIR</p>
</div>
<div class="stat-card bg-white border border-gray-200 rounded-lg p-4 transition-all duration-300">
<div class="flex justify-between items-start">
<div>
<p class="text-gray-500 text-sm">Penalties</p>
<h3 class="text-2xl font-bold text-gray-800" id="penaltiesStat">0.0</h3>
</div>
<div class="bg-yellow-100 p-2 rounded-full">
<i class="fas fa-exclamation text-yellow-500"></i>
</div>
</div>
<p class="text-xs text-gray-500 mt-2">Per round average</p>
</div>
<div class="stat-card bg-white border border-gray-200 rounded-lg p-4 transition-all duration-300">
<div class="flex justify-between items-start">
<div>
<p class="text-gray-500 text-sm">3-Putts</p>
<h3 class="text-2xl font-bold text-gray-800" id="threePuttsStat">0.0</h3>
</div>
<div class="bg-blue-100 p-2 rounded-full">
<i class="fas fa-flag text-blue-500"></i>
</div>
</div>
<p class="text-xs text-gray-500 mt-2">When GIR achieved</p>
</div>
</div>
</section>
<!-- Trend Chart -->
<section class="bg-white rounded-xl shadow-md p-6">
<div class="flex justify-between items-center mb-4">
<h2 class="text-xl font-semibold text-gray-800">Performance Trends</h2>
<div class="flex space-x-2">
<select id="trendStatSelect" class="border border-gray-300 rounded-md px-3 py-1 text-sm">
<option value="badTeeShots">Bad Tee Shots %</option>
<option value="greenSaves">Green Saves %</option>
<option value="penalties">Penalties per Round</option>
<option value="threePutts">3-Putts per Round</option>
</select>
<select id="trendTimeSelect" class="border border-gray-300 rounded-md px-3 py-1 text-sm">
<option value="5">Last 5 Rounds</option>
<option value="10">Last 10 Rounds</option>
<option value="all">All Rounds</option>
</select>
</div>
</div>
<div class="h-64">
<canvas id="trendChart"></canvas>
</div>
</section>
<!-- Recent Rounds -->
<section class="bg-white rounded-xl shadow-md p-6">
<h2 class="text-xl font-semibold text-gray-800 mb-4">Recent Rounds</h2>
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Date</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Course</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Score</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Bad Tee Shots</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Actions</th>
</tr>
</thead>
<tbody id="roundsTableBody" class="bg-white divide-y divide-gray-200">
<!-- Rounds will be inserted here by JavaScript -->
</tbody>
</table>
</div>
<p id="noRoundsMessage" class="text-gray-500 text-center py-4">No rounds recorded yet. Add your first round to get started!</p>
</section>
</div>
<!-- New Round View (hidden by default) -->
<div id="newRoundView" class="hidden">
<div class="flex justify-between items-center mb-6">
<h2 class="text-2xl font-bold text-gray-800 flex items-center">
<button id="backToDashboard" class="mr-4 text-gray-500 hover:text-gray-700">
<i class="fas fa-arrow-left"></i>
</button>
<span>New Round</span>
</h2>
<button id="saveRoundBtn" class="bg-green-600 hover:bg-green-700 text-white px-4 py-2 rounded-lg flex items-center">
<i class="fas fa-save mr-2"></i> Save Round
</button>
</div>
<div class="bg-white rounded-xl shadow-md p-6 mb-6">
<h3 class="text-lg font-semibold text-gray-800 mb-4">Round Information</h3>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<label for="courseName" class="block text-sm font-medium text-gray-700 mb-1">Course Name</label>
<input type="text" id="courseName" class="w-full border border-gray-300 rounded-md px-3 py-2 focus:outline-none focus:ring-2 focus:ring-green-500">
</div>
<div>
<label for="roundDate" class="block text-sm font-medium text-gray-700 mb-1">Date Played</label>
<input type="date" id="roundDate" class="w-full border border-gray-300 rounded-md px-3 py-2 focus:outline-none focus:ring-2 focus:ring-green-500">
</div>
</div>
</div>
<div class="bg-white rounded-xl shadow-md p-6">
<div class="flex justify-between items-center mb-4">
<h3 class="text-lg font-semibold text-gray-800">Hole-by-Hole Stats</h3>
<div class="flex space-x-2">
<button id="prevHole" class="bg-gray-200 hover:bg-gray-300 text-gray-800 px-3 py-1 rounded-md">
<i class="fas fa-chevron-left"></i>
</button>
<span id="currentHoleDisplay" class="px-3 py-1 font-medium">Hole 1</span>
<button id="nextHole" class="bg-gray-200 hover:bg-gray-300 text-gray-800 px-3 py-1 rounded-md">
<i class="fas fa-chevron-right"></i>
</button>
</div>
</div>
<div id="holeStatsContainer">
<!-- Hole stats will be dynamically generated for each hole -->
</div>
</div>
</div>
<!-- Round Detail View (hidden by default) -->
<div id="roundDetailView" class="hidden">
<div class="flex justify-between items-center mb-6">
<h2 class="text-2xl font-bold text-gray-800 flex items-center">
<button id="backToDashboardFromDetail" class="mr-4 text-gray-500 hover:text-gray-700">
<i class="fas fa-arrow-left"></i>
</button>
<span id="detailRoundTitle">Round Details</span>
</h2>
<button id="deleteRoundBtn" class="bg-red-600 hover:bg-red-700 text-white px-4 py-2 rounded-lg flex items-center">
<i class="fas fa-trash mr-2"></i> Delete Round
</button>
</div>
<div class="bg-white rounded-xl shadow-md p-6 mb-6">
<div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-4">
<div>
<p class="text-sm text-gray-500">Course</p>
<p id="detailCourseName" class="font-medium">-</p>
</div>
<div>
<p class="text-sm text-gray-500">Date</p>
<p id="detailRoundDate" class="font-medium">-</p>
</div>
<div>
<p class="text-sm text-gray-500">Total Score</p>
<p id="detailTotalScore" class="font-medium">-</p>
</div>
</div>
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Hole</th>
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Bad Tee Shot</th>
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Penalties</th>
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Missed GIR</th>
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Green Save</th>
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">3-Putt</th>
</tr>
</thead>
<tbody id="roundDetailTableBody" class="bg-white divide-y divide-gray-200">
<!-- Round details will be inserted here by JavaScript -->
</tbody>
</table>
</div>
</div>
<div class="bg-white rounded-xl shadow-md p-6">
<h3 class="text-lg font-semibold text-gray-800 mb-4">Round Summary</h3>
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4">
<div class="bg-green-50 p-4 rounded-lg">
<p class="text-sm text-green-800">Bad Tee Shots</p>
<p id="detailBadTeeShots" class="text-2xl font-bold text-green-800">0%</p>
</div>
<div class="bg-blue-50 p-4 rounded-lg">
<p class="text-sm text-blue-800">Green Saves</p>
<p id="detailGreenSaves" class="text-2xl font-bold text-blue-800">0%</p>
</div>
<div class="bg-yellow-50 p-4 rounded-lg">
<p class="text-sm text-yellow-800">Total Penalties</p>
<p id="detailTotalPenalties" class="text-2xl font-bold text-yellow-800">0</p>
</div>
<div class="bg-red-50 p-4 rounded-lg">
<p class="text-sm text-red-800">3-Putts</p>
<p id="detailThreePutts" class="text-2xl font-bold text-red-800">0</p>
</div>
</div>
</div>
</div>
</main>
<!-- Footer -->
<footer class="mt-12 text-center text-gray-500 text-sm">
<p>Golf Stat Tracker © 2023 | Track your game, improve your scores</p>
</footer>
</div>
<script>
// Data storage
let rounds = JSON.parse(localStorage.getItem('golfRounds')) || [];
let currentRound = {
courseName: '',
date: '',
holes: Array(18).fill().map(() => ({
badTeeShot: false,
badTeeShotClub: '',
badTeeShotDirection: '',
penaltyStrokes: 0,
missedGreen: false,
missedGreenDistance: '',
missedGreenClub: '',
greenSave: false,
threePutt: false,
score: 0
}))
};
let currentHoleIndex = 0;
let currentDetailRoundId = null;
let trendChart = null;
// DOM Elements
const dashboardView = document.getElementById('dashboardView');
const newRoundView = document.getElementById('newRoundView');
const roundDetailView = document.getElementById('roundDetailView');
const holeStatsContainer = document.getElementById('holeStatsContainer');
const roundsTableBody = document.getElementById('roundsTableBody');
const noRoundsMessage = document.getElementById('noRoundsMessage');
const currentHoleDisplay = document.getElementById('currentHoleDisplay');
const trendStatSelect = document.getElementById('trendStatSelect');
const trendTimeSelect = document.getElementById('trendTimeSelect');
const trendChartCanvas = document.getElementById('trendChart');
// Initialize the app
document.addEventListener('DOMContentLoaded', () => {
// Set today's date as default
document.getElementById('roundDate').valueAsDate = new Date();
// Generate hole inputs
generateHoleInputs();
// Load rounds table
updateRoundsTable();
// Update stats
updateDashboardStats();
// Initialize trend chart
updateTrendChart();
// Event listeners
setupEventListeners();
});
function setupEventListeners() {
// Navigation buttons
document.getElementById('newRoundBtn').addEventListener('click', showNewRoundView);
document.getElementById('backToDashboard').addEventListener('click', showDashboardView);
document.getElementById('backToDashboardFromDetail').addEventListener('click', showDashboardView);
document.getElementById('saveRoundBtn').addEventListener('click', saveRound);
document.getElementById('deleteRoundBtn').addEventListener('click', deleteRound);
// Hole navigation
document.getElementById('prevHole').addEventListener('click', () => navigateHole(-1));
document.getElementById('nextHole').addEventListener('click', () => navigateHole(1));
// Trend chart controls
trendStatSelect.addEventListener('change', updateTrendChart);
trendTimeSelect.addEventListener('change', updateTrendChart);
}
function generateHoleInputs() {
holeStatsContainer.innerHTML = '';
for (let i = 0; i < 18; i++) {
const holeDiv = document.createElement('div');
holeDiv.className = `hole-input-section ${i === 0 ? '' : 'hidden'}`;
holeDiv.dataset.holeNumber = i + 1;
holeDiv.innerHTML = `
<h4 class="text-md font-medium text-gray-700 mb-4">Hole ${i + 1}</h4>
<div class="space-y-4">
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<label class="flex items-center space-x-3">
<input type="checkbox" id="badTeeShot-${i}" class="form-checkbox h-5 w-5 text-green-600"
data-hole="${i}" onchange="toggleBadTeeShot(this)">
<span class="text-gray-700">Bad Tee Shot?</span>
</label>
<div id="badTeeShotDetails-${i}" class="mt-2 ml-8 space-y-2 hidden">
<div>
<label for="badTeeShotClub-${i}" class="block text-sm text-gray-600 mb-1">Club Used</label>
<input type="text" id="badTeeShotClub-${i}" class="w-full border border-gray-300 rounded-md px-3 py-2 text-sm"
data-hole="${i}" placeholder="e.g., Driver, 3-wood">
</div>
<div>
<label class="block text-sm text-gray-600 mb-1">Direction</label>
<div class="flex space-x-4">
<label class="flex items-center space-x-2">
<input type="radio" name="badTeeShotDirection-${i}" value="left" class="form-radio h-4 w-4 text-green-600" data-hole="${i}">
<span class="text-gray-700">Left</span>
</label>
<label class="flex items-center space-x-2">
<input type="radio" name="badTeeShotDirection-${i}" value="right" class="form-radio h-4 w-4 text-green-600" data-hole="${i}">
<span class="text-gray-700">Right</span>
</label>
</div>
</div>
</div>
</div>
<div>
<label for="penaltyStrokes-${i}" class="block text-sm text-gray-600 mb-1">Penalty Strokes</label>
<input type="number" id="penaltyStrokes-${i}" min="0" max="5" value="0"
class="w-full border border-gray-300 rounded-md px-3 py-2 text-sm" data-hole="${i}">
</div>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<label class="flex items-center space-x-3">
<input type="checkbox" id="missedGreen-${i}" class="form-checkbox h-5 w-5 text-green-600"
data-hole="${i}" onchange="toggleMissedGreen(this)">
<span class="text-gray-700">Missed Green from Inside 120m?</span>
</label>
<div id="missedGreenDetails-${i}" class="mt-2 ml-8 space-y-2 hidden">
<div>
<label for="missedGreenDistance-${i}" class="block text-sm text-gray-600 mb-1">Distance (m)</label>
<input type="number" id="missedGreenDistance-${i}" min="1" max="120"
class="w-full border border-gray-300 rounded-md px-3 py-2 text-sm" data-hole="${i}" placeholder="e.g., 75">
</div>
<div>
<label for="missedGreenClub-${i}" class="block text-sm text-gray-600 mb-1">Club Used</label>
<input type="text" id="missedGreenClub-${i}"
class="w-full border border-gray-300 rounded-md px-3 py-2 text-sm" data-hole="${i}" placeholder="e.g., PW, 9-iron">
</div>
</div>
</div>
<div id="greenSaveContainer-${i}">
<label class="flex items-center space-x-3">
<input type="checkbox" id="greenSave-${i}" class="form-checkbox h-5 w-5 text-green-600"
data-hole="${i}" disabled>
<span class="text-gray-700">Green Save?</span>
</label>
</div>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div id="threePuttContainer-${i}">
<label class="flex items-center space-x-3">
<input type="checkbox" id="threePutt-${i}" class="form-checkbox h-5 w-5 text-green-600"
data-hole="${i}" disabled>
<span class="text-gray-700">3-Putt?</span>
</label>
</div>
<div>
<label for="score-${i}" class="block text-sm text-gray-600 mb-1">Score for Hole</label>
<input type="number" id="score-${i}" min="1" max="10" value="4"
class="w-full border border-gray-300 rounded-md px-3 py-2 text-sm" data-hole="${i}">
</div>
</div>
</div>
`;
holeStatsContainer.appendChild(holeDiv);
}
}
function toggleBadTeeShot(checkbox) {
const holeIndex = parseInt(checkbox.dataset.hole);
currentRound.holes[holeIndex].badTeeShot = checkbox.checked;
const detailsDiv = document.getElementById(`badTeeShotDetails-${holeIndex}`);
if (checkbox.checked) {
detailsDiv.classList.remove('hidden');
} else {
detailsDiv.classList.add('hidden');
document.getElementById(`badTeeShotClub-${holeIndex}`).value = '';
document.querySelector(`input[name="badTeeShotDirection-${holeIndex}"]:checked`)?.checked = false;
currentRound.holes[holeIndex].badTeeShotClub = '';
currentRound.holes[holeIndex].badTeeShotDirection = '';
}
}
function toggleMissedGreen(checkbox) {
const holeIndex = parseInt(checkbox.dataset.hole);
currentRound.holes[holeIndex].missedGreen = checkbox.checked;
const detailsDiv = document.getElementById(`missedGreenDetails-${holeIndex}`);
const greenSaveCheckbox = document.getElementById(`greenSave-${holeIndex}`);
const threePuttCheckbox = document.getElementById(`threePutt-${holeIndex}`);
if (checkbox.checked) {
detailsDiv.classList.remove('hidden');
greenSaveCheckbox.disabled = false;
threePuttCheckbox.disabled = true;
threePuttCheckbox.checked = false;
currentRound.holes[holeIndex].threePutt = false;
} else {
detailsDiv.classList.add('hidden');
greenSaveCheckbox.disabled = true;
greenSaveCheckbox.checked = false;
threePuttCheckbox.disabled = false;
document.getElementById(`missedGreenDistance-${holeIndex}`).value = '';
document.getElementById(`missedGreenClub-${holeIndex}`).value = '';
currentRound.holes[holeIndex].missedGreenDistance = '';
currentRound.holes[holeIndex].missedGreenClub = '';
currentRound.holes[holeIndex].greenSave = false;
}
}
function navigateHole(direction) {
const holeSections = document.querySelectorAll('.hole-input-section');
holeSections[currentHoleIndex].classList.add('hidden');
currentHoleIndex = (currentHoleIndex + direction + 18) % 18;
currentHoleDisplay.textContent = `Hole ${currentHoleIndex + 1}`;
holeSections[currentHoleIndex].classList.remove('hidden');
}
function showNewRoundView() {
// Reset current round
currentRound = {
courseName: '',
date: '',
holes: Array(18).fill().map(() => ({
badTeeShot: false,
badTeeShotClub: '',
badTeeShotDirection: '',
penaltyStrokes: 0,
missedGreen: false,
missedGreenDistance: '',
missedGreenClub: '',
greenSave: false,
threePutt: false,
score: 4
}))
};
// Reset form
document.getElementById('courseName').value = '';
document.getElementById('roundDate').valueAsDate = new Date();
// Reset all hole inputs
for (let i = 0; i < 18; i++) {
document.getElementById(`badTeeShot-${i}`).checked = false;
document.getElementById(`badTeeShotClub-${i}`).value = '';
document.querySelector(`input[name="badTeeShotDirection-${i}"]:checked`)?.checked = false;
document.getElementById(`penaltyStrokes-${i}`).value = 0;
document.getElementById(`missedGreen-${i}`).checked = false;
document.getElementById(`missedGreenDistance-${i}`).value = '';
document.getElementById(`missedGreenClub-${i}`).value = '';
document.getElementById(`greenSave-${i}`).checked = false;
document.getElementById(`threePutt-${i}`).checked = false;
document.getElementById(`score-${i}`).value = 4;
document.getElementById(`badTeeShotDetails-${i}`).classList.add('hidden');
document.getElementById(`missedGreenDetails-${i}`).classList.add('hidden');
document.getElementById(`greenSave-${i}`).disabled = true;
document.getElementById(`threePutt-${i}`).disabled = true;
}
// Show first hole
currentHoleIndex = 0;
currentHoleDisplay.textContent = 'Hole 1';
document.querySelector('.hole-input-section').classList.remove('hidden');
// Switch views
dashboardView.classList.add('hidden');
roundDetailView.classList.add('hidden');
newRoundView.classList.remove('hidden');
}
function showDashboardView() {
dashboardView.classList.remove('hidden');
newRoundView.classList.add('hidden');
roundDetailView.classList.add('hidden');
// Update the table and stats
updateRoundsTable();
updateDashboardStats();
updateTrendChart();
}
function showRoundDetailView(roundId) {
const round = rounds.find(r => r.id === roundId);
if (!round) return;
currentDetailRoundId = roundId;
// Set round info
document.getElementById('detailRoundTitle').textContent = `${round.courseName} - ${formatDate(round.date)}`;
document.getElementById('detailCourseName').textContent = round.courseName;
document.getElementById('detailRoundDate').textContent = formatDate(round.date);
// Calculate total score
const totalScore = round.holes.reduce((sum, hole) => sum + hole.score, 0);
document.getElementById('detailTotalScore').textContent = totalScore;
// Populate hole details table
const tableBody = document.getElementById('roundDetailTableBody');
tableBody.innerHTML = '';
round.holes.forEach((hole, index) => {
const row = document.createElement('tr');
row.innerHTML = `
<td class="px-4 py-2 whitespace-nowrap text-sm font-medium text-gray-900">${index + 1}</td>
<td class="px-4 py-2 whitespace-nowrap text-sm text-gray-500">
${hole.badTeeShot ?
`${hole.badTeeShotClub} (${hole.badTeeShotDirection})` :
'<span class="text-gray-400">No</span>'}
</td>
<td class="px-4 py-2 whitespace-nowrap text-sm text-gray-500">${hole.penaltyStrokes}</td>
<td class="px-4 py-2 whitespace-nowrap text-sm text-gray-500">
${hole.missedGreen ?
`${hole.missedGreenDistance}m (${hole.missedGreenClub})` :
'<span class="text-gray-400">No</span>'}
</td>
<td class="px-4 py-2 whitespace-nowrap text-sm text-gray-500">
${hole.missedGreen ?
(hole.greenSave ? '<span class="text-green-600">Yes</span>' : '<span class="text-red-600">No</span>') :
'<span class="text-gray-400">-</span>'}
</td>
<td class="px-4 py-2 whitespace-nowrap text-sm text-gray-500">
${!hole.missedGreen ?
(hole.threePutt ? '<span class="text-red-600">Yes</span>' : '<span class="text-green-600">No</span>') :
'<span class="text-gray-400">-</span>'}
</td>
`;
tableBody.appendChild(row);
});
// Calculate and display stats
const badTeeShots = round.holes.filter(h => h.badTeeShot).length;
const missedGreens = round.holes.filter(h => h.missedGreen).length;
const greenSaves = round.holes.filter(h => h.missedGreen && h.greenSave).length;
const threePutts = round.holes.filter(h => !h.missedGreen && h.threePutt).length;
const totalPenalties = round.holes.reduce((sum, hole) => sum + hole.penaltyStrokes, 0);
document.getElementById('detailBadTeeShots').textContent = `${Math.round((badTeeShots / 18) * 100)}%`;
document.getElementById('detailGreenSaves').textContent = missedGreens > 0 ?
`${Math.round((greenSaves / missedGreens) * 100)}%` : '0%';
document.getElementById('detailTotalPenalties').textContent = totalPenalties;
document.getElementById('detailThreePutts').textContent = threePutts;
// Switch views
dashboardView.classList.add('hidden');
newRoundView.classList.add('hidden');
roundDetailView.classList.remove('hidden');
}
function saveRound() {
// Get round info
const courseName = document.getElementById('courseName').value.trim();
const date = document.getElementById('roundDate').value;
if (!courseName) {
alert('Please enter a course name');
return;
}
if (!date) {
alert('Please select a date');
return;
}
// Update current round with form data
currentRound.courseName = courseName;
currentRound.date = date;
// Get all hole data
for (let i = 0; i < 18; i++) {
currentRound.holes[i].badTeeShot = document.getElementById(`badTeeShot-${i}`).checked;
currentRound.holes[i].badTeeShotClub = document.getElementById(`badTeeShotClub-${i}`).value;
currentRound.holes[i].badTeeShotDirection = document.querySelector(`input[name="badTeeShotDirection-${i}"]:checked`)?.value || '';
currentRound.holes[i].penaltyStrokes = parseInt(document.getElementById(`penaltyStrokes-${i}`).value) || 0;
currentRound.holes[i].missedGreen = document.getElementById(`missedGreen-${i}`).checked;
currentRound.holes[i].missedGreenDistance = document.getElementById(`missedGreenDistance-${i}`).value;
currentRound.holes[i].missedGreenClub = document.getElementById(`missedGreenClub-${i}`).value;
currentRound.holes[i].greenSave = document.getElementById(`greenSave-${i}`).checked;
currentRound.holes[i].threePutt = document.getElementById(`threePutt-${i}`).checked;
currentRound.holes[i].score = parseInt(document.getElementById(`score-${i}`).value) || 4;
}
// Add ID and save to storage
currentRound.id = Date.now().toString();
rounds.push(currentRound);
localStorage.setItem('golfRounds', JSON.stringify(rounds));
// Show dashboard
showDashboardView();
}
function deleteRound() {
if (!currentDetailRoundId) return;
if (confirm('Are you sure you want to delete this round?')) {
rounds = rounds.filter(r => r.id !== currentDetailRoundId);
localStorage.setItem('golfRounds', JSON.stringify(rounds));
showDashboardView();
}
}
function updateRoundsTable() {
if (rounds.length === 0) {
noRoundsMessage.classList.remove('hidden');
roundsTableBody.innerHTML = '';
return;
}
noRoundsMessage.classList.add('hidden');
// Sort rounds by date (newest first)
const sortedRounds = [...rounds].sort((a, b) => new Date(b.date) - new Date(a.date));
// Clear table
roundsTableBody.innerHTML = '';
// Add rows
sortedRounds.forEach(round => {
const totalScore = round.holes.reduce((sum, hole) => sum + hole.score, 0);
const badTeeShots = round.holes.filter(h => h.badTeeShot).length;
const row = document.createElement('tr');
row.className = 'hover:bg-gray-50';
row.innerHTML = `
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${formatDate(round.date)}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">${round.courseName}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${totalScore}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${badTeeShots} (${Math.round((badTeeShots / 18) * 100)}%)</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
<button onclick="showRoundDetailView('${round.id}')" class="text-green-600 hover:text-green-900 mr-3">
<i class="fas fa-eye"></i> View
</button>
</td>
`;
roundsTableBody.appendChild(row);
});
}
function updateDashboardStats() {
if (rounds.length === 0) {
document.getElementById('badTeeShotsStat').textContent = '0%';
document.getElementById('greenSavesStat').textContent = '0%';
document.getElementById('penaltiesStat').textContent = '0.0';
document.getElementById('threePuttsStat').textContent = '0.0';
return;
}
// Calculate stats from last 5 rounds
const recentRounds = [...rounds].sort((a, b) => new Date(b.date) - new Date(a.date)).slice(0, 5);
let totalBadTeeShots = 0;
let totalHoles = 0;
let totalMissedGreens = 0;
let totalGreenSaves = 0;
let totalPenalties = 0;
let totalThreePutts = 0;
let totalGIRHoles = 0;
recentRounds.forEach(round => {
round.holes.forEach(hole => {
totalHoles++;
if (hole.badTeeShot) totalBadTeeShots++;
if (hole.missedGreen) {
totalMissedGreens++;
if (hole.greenSave) totalGreenSaves++;
} else {
totalGIRHoles++;
if (hole.threePutt) totalThreePutts++;
}
totalPenalties += hole.penaltyStrokes;
});
});
// Update stats
document.getElementById('badTeeShotsStat').textContent = `${Math.round((totalBadTeeShots / totalHoles) * 100)}%`;
document.getElementById('greenSavesStat').textContent = totalMissedGreens > 0 ?
`${Math.round((totalGreenSaves / totalMissedGreens) * 100)}%` : '0%';
document.getElementById('penaltiesStat').textContent = (totalPenalties / recentRounds.length).toFixed(1);
document.getElementById('threePuttsStat').textContent = totalGIRHoles > 0 ?
(totalThreePutts / recentRounds.length).toFixed(1) : '0.0';
}
function updateTrendChart() {
const stat = trendStatSelect.value;
const timeFrame = trendTimeSelect.value;
// Filter rounds based on time frame
let filteredRounds = [...rounds];
if (timeFrame !== 'all') {
filteredRounds = filteredRounds.slice(0, parseInt(timeFrame));
}
// Sort rounds by date (oldest first)
filteredRounds.sort((a, b) => new Date(a.date) - new Date(b.date));
// Prepare data
const labels = filteredRounds.map(round => formatDate(round.date, true));
const data = filteredRounds.map(round => {
switch (stat) {
case 'badTeeShots':
const badTeeShots = round.holes.filter(h => h.badTeeShot).length;
return Math.round((badTeeShots / 18) * 100);
case 'greenSaves':
const missedGreens = round.holes.filter(h => h.missedGreen).length;
const greenSaves = round.holes.filter(h => h.missedGreen && h.greenSave).length;
return missedGreens > 0 ? Math.round((greenSaves / missedGreens) * 100) : 0;
case 'penalties':
return round.holes.reduce((sum, hole) => sum + hole.penaltyStrokes, 0);
case 'threePutts':
const threePutts = round.holes.filter(h => !h.missedGreen && h.threePutt).length;
return threePutts;
default:
return 0;
}
});
// Chart config
const config = {
type: 'line',
data: {
labels: labels,
datasets: [{
label: getStatLabel(stat),
data: data,
backgroundColor: getStatColor(stat, 0.2),
borderColor: getStatColor(stat),
borderWidth: 2,
tension: 0.3,
fill: true
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: {
display: false
},
tooltip: {
callbacks: {
label: function(context) {
return `${getStatLabel(stat)}: ${context.raw}${stat === 'badTeeShots' || stat === 'greenSaves' ? '%' : ''}`;
}
}
}
},
scales: {
y: {
beginAtZero: true,
max: stat === 'badTeeShots' || stat === 'greenSaves' ? 100 : undefined,
ticks: {
callback: function(value) {
return stat === 'badTeeShots' || stat === 'greenSaves' ? `${value}%` : value;
}
}
}
}
}
};
// Destroy previous chart if exists
if (trendChart) {
trendChart.destroy();
}
// Create new chart
trendChart = new Chart(trendChartCanvas, config);
}
function getStatLabel(stat) {
switch (stat) {
case 'badTeeShots': return 'Bad Tee Shots';
case 'greenSaves': return 'Green Saves';
case 'penalties': return 'Penalties';
case 'threePutts': return '3-Putts';
default: return '';
}
}
function getStatColor(stat, opacity = 1) {
switch (stat) {
case 'badTeeShots': return `rgba(239, 68, 68, ${opacity})`;
case 'greenSaves': return `rgba(16, 185, 129, ${opacity})`;
case 'penalties': return `rgba(245, 158, 11, ${opacity})`;
case 'threePutts': return `rgba(59, 130, 246, ${opacity})`;
default: return `rgba(99, 102, 241, ${opacity})`;
}
}
function formatDate(dateString, short = false) {
const date = new Date(dateString);
if (short) {
return date.toLocaleDateString('en-US', { month: 'short', day: 'numeric' });
}
return date.toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' });
}
// Make functions available globally for inline event handlers
window.toggleBadTeeShot = toggleBadTeeShot;
window.toggleMissedGreen = toggleMissedGreen;
window.showRoundDetailView = showRoundDetailView;
</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=SwePalm/golf-stat-tracker" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html> |