2528bc4b5d
- Remove unnecessary refresh button that only returned cached data - Change button text from "Calculate Approx Rating" to "Predict Rating" - Make player names clickable links to their PDGA profile pages - Add link styling with hover effects 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
225 lines
7.9 KiB
HTML
225 lines
7.9 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>PDGA Ratings</title>
|
|
<style>
|
|
body {
|
|
font-family: Arial, sans-serif;
|
|
margin: 40px;
|
|
background-color: #f5f5f5;
|
|
}
|
|
.container {
|
|
max-width: 800px;
|
|
margin: 0 auto;
|
|
background: white;
|
|
padding: 30px;
|
|
border-radius: 8px;
|
|
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
|
}
|
|
h1 {
|
|
color: #333;
|
|
text-align: center;
|
|
margin-bottom: 30px;
|
|
}
|
|
.loading {
|
|
text-align: center;
|
|
padding: 20px;
|
|
font-size: 18px;
|
|
color: #666;
|
|
}
|
|
table {
|
|
width: 100%;
|
|
border-collapse: collapse;
|
|
margin-top: 20px;
|
|
}
|
|
th, td {
|
|
padding: 12px;
|
|
text-align: left;
|
|
border-bottom: 1px solid #ddd;
|
|
}
|
|
th {
|
|
background-color: #f8f9fa;
|
|
font-weight: bold;
|
|
color: #495057;
|
|
}
|
|
tr:hover {
|
|
background-color: #f5f5f5;
|
|
}
|
|
.rating {
|
|
font-weight: bold;
|
|
color: #007bff;
|
|
}
|
|
.pdga-number {
|
|
color: #6c757d;
|
|
font-size: 14px;
|
|
}
|
|
.difference {
|
|
font-weight: bold;
|
|
}
|
|
.positive {
|
|
color: #28a745;
|
|
}
|
|
.negative {
|
|
color: #dc3545;
|
|
}
|
|
.neutral {
|
|
color: #6c757d;
|
|
}
|
|
.calc-btn {
|
|
background-color: #17a2b8;
|
|
color: white;
|
|
border: none;
|
|
padding: 5px 10px;
|
|
border-radius: 3px;
|
|
cursor: pointer;
|
|
font-size: 12px;
|
|
}
|
|
.calc-btn:hover {
|
|
background-color: #138496;
|
|
}
|
|
.calc-btn:disabled {
|
|
background-color: #6c757d;
|
|
cursor: not-allowed;
|
|
}
|
|
.rating-change {
|
|
font-weight: bold;
|
|
font-size: 14px;
|
|
}
|
|
a {
|
|
color: #007bff;
|
|
text-decoration: none;
|
|
}
|
|
a:hover {
|
|
text-decoration: underline;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<h1>PDGA Player Ratings</h1>
|
|
<div id="loading" class="loading">Loading ratings...</div>
|
|
<div id="ratings-table"></div>
|
|
</div>
|
|
|
|
<script>
|
|
async function fetchRatings() {
|
|
const loadingDiv = document.getElementById('loading');
|
|
const tableDiv = document.getElementById('ratings-table');
|
|
|
|
loadingDiv.style.display = 'block';
|
|
tableDiv.innerHTML = '';
|
|
|
|
try {
|
|
const response = await fetch('/api/ratings');
|
|
const ratings = await response.json();
|
|
|
|
loadingDiv.style.display = 'none';
|
|
|
|
if (ratings.length === 0) {
|
|
tableDiv.innerHTML = '<p>No ratings found.</p>';
|
|
return;
|
|
}
|
|
|
|
let tableHTML = `
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Rank</th>
|
|
<th>Player Name</th>
|
|
<th>PDGA #</th>
|
|
<th>Current Rating</th>
|
|
<th>Rating Change</th>
|
|
<th>Predicted Rating</th>
|
|
<th>Difference</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
`;
|
|
|
|
ratings.forEach((player, index) => {
|
|
const difference = player.predictedRating && player.rating ?
|
|
player.predictedRating - player.rating : 0;
|
|
const diffText = difference > 0 ? `+${difference}` : difference.toString();
|
|
const diffClass = difference > 0 ? 'positive' : difference < 0 ? 'negative' : 'neutral';
|
|
|
|
const ratingChangeText = player.ratingChange ?
|
|
(player.ratingChange > 0 ? `+${player.ratingChange}` : player.ratingChange.toString()) : 'N/A';
|
|
const ratingChangeClass = player.ratingChange > 0 ? 'positive' :
|
|
player.ratingChange < 0 ? 'negative' : 'neutral';
|
|
|
|
tableHTML += `
|
|
<tr id="row-${player.pdgaNumber}">
|
|
<td>${index + 1}</td>
|
|
<td><a href="https://www.pdga.com/player/${player.pdgaNumber}" target="_blank">${player.name}</a></td>
|
|
<td class="pdga-number">#${player.pdgaNumber}</td>
|
|
<td class="rating">${player.rating || 'N/A'}</td>
|
|
<td class="rating-change ${ratingChangeClass}">${ratingChangeText}</td>
|
|
<td class="predicted-rating" id="predicted-${player.pdgaNumber}">
|
|
${player.predictedRating || 'N/A'}
|
|
</td>
|
|
<td class="difference ${diffClass}" id="diff-${player.pdgaNumber}">
|
|
${difference ? diffText :
|
|
`<button class="calc-btn" onclick="calculatePredictedRating(${player.pdgaNumber})">Predict Rating</button>`}
|
|
</td>
|
|
</tr>
|
|
`;
|
|
});
|
|
|
|
tableHTML += `
|
|
</tbody>
|
|
</table>
|
|
`;
|
|
|
|
tableDiv.innerHTML = tableHTML;
|
|
|
|
} catch (error) {
|
|
loadingDiv.style.display = 'none';
|
|
tableDiv.innerHTML = '<p>Error loading ratings. Please try again.</p>';
|
|
console.error('Error:', error);
|
|
}
|
|
}
|
|
|
|
async function calculatePredictedRating(pdgaNumber) {
|
|
const button = document.querySelector(`#diff-${pdgaNumber} .calc-btn`);
|
|
const predictedCell = document.getElementById(`predicted-${pdgaNumber}`);
|
|
const diffCell = document.getElementById(`diff-${pdgaNumber}`);
|
|
|
|
button.disabled = true;
|
|
button.textContent = 'Calculating...';
|
|
|
|
try {
|
|
const response = await fetch(`/api/predicted-rating/${pdgaNumber}`, {
|
|
method: 'POST'
|
|
});
|
|
|
|
const data = await response.json();
|
|
|
|
if (data.predictedRating) {
|
|
predictedCell.textContent = data.predictedRating;
|
|
|
|
const currentRating = parseInt(document.querySelector(`#row-${pdgaNumber} .rating`).textContent);
|
|
const difference = data.predictedRating - currentRating;
|
|
const diffText = difference > 0 ? `+${difference}` : difference.toString();
|
|
const diffClass = difference > 0 ? 'positive' : difference < 0 ? 'negative' : 'neutral';
|
|
|
|
diffCell.className = `difference ${diffClass}`;
|
|
diffCell.textContent = diffText;
|
|
} else {
|
|
predictedCell.textContent = 'Error';
|
|
diffCell.textContent = 'Error';
|
|
}
|
|
|
|
} catch (error) {
|
|
console.error('Error calculating predicted rating:', error);
|
|
predictedCell.textContent = 'Error';
|
|
button.disabled = false;
|
|
button.textContent = 'Predict Rating';
|
|
}
|
|
}
|
|
|
|
fetchRatings();
|
|
</script>
|
|
</body>
|
|
</html> |