golf-stat-tracker / index.html
SwePalm's picture
Golf Stat Tracker Web App Requirements 1. Application Goal Develop a single-page web application for tracking golf statistics per hole, per round. The app should allow users to input data for each hole played and visualize trends over time. 2. Core Functionality 2.1. Round Registration Users must be able to register a new golf round with the following information: Course Name: Text input (e.g., "Pebble Beach Golf Links"). Date Played: Date input (e.g., "2025-06-18"). 2.2. Hole-by-Hole Stat Entry For each hole played in a registered round, users must be able to input the following statistics: Bad Tee Shot: Checkbox (Yes/No). If "Yes," then require text input for Club Used (e.g., "Driver," "3-wood") and radio button selection for Direction (Left/Right). Penalty Strokes: Number input (e.g., 0, 1, 2). Missed Green from Inside 120m: Checkbox (Yes/No). If "Yes," then require number input for Distance (e.g., "75" meters) and text input for Club Used (e.g., "PW," "9-iron"). Green Save (if Missed Green): Checkbox (Yes/No). This input should only be enabled if "Missed Green from Inside 120m" is "Yes." Three Putt (if Green in Regulation - GIR): Checkbox (Yes/No). This input should only be enabled if "Missed Green from Inside 120m" is "No" (implying a GIR). 2.3. Round Overview The application should display an overview table of all registered rounds, including: Course Name Date Played Total Score (This will need to be calculated based on inputting the actual score for each hole, which isn't explicitly listed above, so the AI might need to infer this or you might need to add it later. For now, let's assume 'Total Score' is a sum of strokes which will be entered implicitly with penalties, or you'll add a 'Strokes for Hole' field later). 2.4. Round Detail View Upon selecting a round from the overview, users should be able to view all the detailed statistics entered for each hole within that specific round. 2.5. Trend Visualization Users must be able to select individual statistics (e.g., "Bad Tee Shot percentage," "Average Penalty Strokes per round," "Green Save percentage") and view a trend over time. This could be a simple line graph or bar chart. 3. User Interface (UI) Considerations The application should be a single-page interface, potentially with different sections or views accessible via navigation. The design should be clean and intuitive for data entry and visualization. 4. Technical Considerations (Optional, but good for AI) The application should be a web app (HTML, CSS, JavaScript). Data persistence is required (e.g., local storage, or a simple embedded database if the AI can manage it, to save rounds between sessions). - Initial Deployment
e7f347b verified
<!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 &copy; 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>