-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
380 lines (355 loc) · 16.8 KB
/
index.html
File metadata and controls
380 lines (355 loc) · 16.8 KB
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
<!DOCTYPE html>
<html lang="en" class="dark">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Matchmaking & Analytics Dashboard</title>
<script src="https://cdn.tailwindcss.com"></script>
<script>
tailwind.config = {
darkMode: 'class',
theme: {
extend: {
colors: {
'primary': '#1a202c',
'secondary': '#2d3748',
'accent': '#4a5568',
'highlight': '#a0aec0',
'text-primary': '#e2e8f0',
'text-secondary': '#cbd5e0',
}
}
}
}
</script>
<style>
body {
background-color: #1a202c;
color: #e2e8f0;
font-family: 'Inter', sans-serif;
}
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap');
.card {
background-color: #2d3748;
border-radius: 0.75rem;
padding: 1.5rem;
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}
.btn {
padding-left: 1rem;
padding-right: 1rem;
padding-top: 0.5rem;
padding-bottom: 0.5rem;
background-color: #4f46e5; /* indigo-600 */
color: #fff;
font-weight: 600;
border-radius: 0.5rem;
box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
outline: none;
transition: all 0.2s;
}
.btn:hover {
background-color: #4338ca; /* indigo-700 */
}
.btn:focus {
outline: none;
box-shadow: 0 0 0 2px #818cf8; /* indigo-400 */
}
.input {
width: 100%;
padding-left: 0.75rem;
padding-right: 0.75rem;
padding-top: 0.5rem;
padding-bottom: 0.5rem;
background-color: #ebf2ff; /* bg-accent */
color: #021844; /* text-gray-900 */
border-radius: 0.375rem; /* rounded-md */
outline: none;
transition: box-shadow 0.2s;
}
.input:focus {
outline: none;
box-shadow: 0 0 0 2px #6366f1; /* focus:ring-2 focus:ring-indigo-500 */
}
.input::placeholder {
color: #373838; /* highlight color */
}
.notification {
animation: fadeIn 0.5s ease-in-out;
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(-10px); }
to { opacity: 1; transform: translateY(0); }
}
</style>
</head>
<body class="p-4 sm:p-8">
<div class="max-w-6xl mx-auto space-y-8">
<header class="text-center">
<h1 class="text-3xl sm:text-4xl font-bold text-text-primary">Intelligent Gaming Matchmaking Dashboard 🎮</h1>
<p class="text-text-secondary mt-2">Manage your game's matchmaking queue and player data.</p>
</header>
<div class="grid grid-cols-1 lg:grid-cols-3 gap-8">
<div class="lg:col-span-2 space-y-8">
<div class="card">
<h2 class="text-2xl font-bold mb-4">Matchmaking</h2>
<div id="matchmaking-form" class="space-y-4">
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
<div>
<label for="player-id" class="block text-sm font-medium text-highlight mb-1">Player ID</label>
<input type="text" id="player-id" class="input" placeholder="e.g., player_123">
</div>
<div>
<label for="mmr" class="block text-sm font-medium text-highlight mb-1">MMR (defaults to 1000)</label>
<input type="number" id="mmr" class="input" placeholder="e.g., 1500">
</div>
</div>
<div class="flex items-center gap-4">
<button id="join-queue-btn" class="btn">Join Queue</button>
<div>
<label for="existing-players" class="block text-sm font-medium text-highlight mb-1">Or select existing player</label>
<select id="existing-players" class="input">
<option value="">-- Select Player --</option>
</select>
</div>
</div>
</div>
</div>
<div class="card">
<h2 class="text-2xl font-bold mb-4">Player Stats</h2>
<div class="flex space-x-4 mb-4">
<input type="text" id="search-player-id" class="input" placeholder="Enter Player ID to search">
<button id="search-btn" class="btn">Search</button>
</div>
<div id="player-stats-display" class="p-4 bg-primary rounded-lg min-h-[100px]">
<p class="text-highlight">Search for a player to see their stats.</p>
</div>
</div>
<div class="card">
<h2 class="text-2xl font-bold mb-4">Match Simulator</h2>
<p class="text-highlight mb-4">Simulate a match result. Use player IDs from a 'Match Found' notification.</p>
<div id="match-simulator-display" class="space-y-4">
<p class="text-highlight">Waiting for a match to be found...</p>
</div>
</div>
<div class="card">
<h2 class="text-2xl font-bold mb-4">Recent Matches</h2>
<div id="recent-matches-display" class="space-y-3 max-h-96 overflow-y-auto">
<p class="text-highlight">No recent matches to display.</p>
</div>
</div>
</div>
<div class="lg:col-span-1 space-y-8">
<div class="card">
<h2 class="text-2xl font-bold mb-4">Current Queue</h2>
<div id="queue-display" class="space-y-2 h-48 overflow-y-auto pr-2">
<p class="text-highlight text-sm">No players in queue.</p>
</div>
</div>
<div class="card">
<h2 class="text-2xl font-bold mb-4">Real-time Notifications</h2>
<div id="notifications" class="space-y-3 h-96 overflow-y-auto pr-2">
<p class="text-highlight text-sm">Waiting for server events...</p>
</div>
</div>
</div>
</div>
</div>
<script>
const API_BASE_URL = 'http://localhost:5000';
// --- DOM Elements ---
const joinQueueBtn = document.getElementById('join-queue-btn');
const playerIdInput = document.getElementById('player-id');
const mmrInput = document.getElementById('mmr');
const searchBtn = document.getElementById('search-btn');
const searchPlayerIdInput = document.getElementById('search-player-id');
const playerStatsDisplay = document.getElementById('player-stats-display');
const notificationsLog = document.getElementById('notifications');
const matchSimulatorDisplay = document.getElementById('match-simulator-display');
const existingPlayersSelect = document.getElementById('existing-players');
const queueDisplay = document.getElementById('queue-display');
const recentMatchesDisplay = document.getElementById('recent-matches-display');
// --- API Functions ---
async function joinQueue() {
const playerId = playerIdInput.value;
const mmr = mmrInput.value ? parseInt(mmrInput.value, 10) : 1000;
if (!playerId) {
alert('Please enter a Player ID.');
return;
}
try {
const response = await fetch(`${API_BASE_URL}/queue`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ player_id: playerId, mmr: mmr })
});
const data = await response.json();
console.log('Join queue response:', data);
playerIdInput.value = '';
mmrInput.value = '';
logNotification(`Player ${playerId} joined the queue.`, 'info');
updateQueueDisplay();
populateExistingPlayers();
} catch (error) {
console.error('Error joining queue:', error);
logNotification('Failed to join queue.', 'error');
}
}
async function getPlayerStats() {
const playerId = searchPlayerIdInput.value;
if (!playerId) {
alert('Please enter a Player ID to search.');
return;
}
playerStatsDisplay.innerHTML = `<p class="text-highlight">Loading...</p>`;
try {
const response = await fetch(`${API_BASE_URL}/player/${playerId}/stats`);
const data = await response.json();
playerStatsDisplay.innerHTML = `
<h3 class="font-bold text-lg">${data.player_id}</h3>
<p><strong>MMR:</strong> ${data.mmr}</p>
<p><strong>Wins:</strong> ${data.wins}</p>
<p><strong>Losses:</strong> ${data.losses}</p>
<p><strong>Preferred Characters:</strong> ${data.character_preferences.join(', ')}</p>
`;
} catch (error) {
console.error('Error getting player stats:', error);
playerStatsDisplay.innerHTML = `<p class="text-red-400">Could not fetch stats for ${playerId}.</p>`;
}
}
async function reportMatchResult(matchId, winnerTeam, loserTeam) {
try {
const response = await fetch(`${API_BASE_URL}/matches/${matchId}/results`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ winner_team: winnerTeam, loser_team: loserTeam })
});
const data = await response.json();
console.log('Report match result response:', data);
logNotification(`Match ${matchId} result reported.`, 'info');
matchSimulatorDisplay.innerHTML = `<p class="text-highlight">Waiting for a new match to be found...</p>`;
updateRecentMatches(); // Refresh recent matches list
} catch(error) {
console.error('Error reporting match result:', error);
logNotification('Failed to report match result.', 'error');
}
}
async function populateExistingPlayers() {
try {
const response = await fetch(`${API_BASE_URL}/players`);
const players = await response.json();
existingPlayersSelect.innerHTML = '<option value="">-- Select Player --</option>';
players.forEach(player => {
const option = document.createElement('option');
option.value = player.player_id;
option.textContent = player.player_id;
existingPlayersSelect.appendChild(option);
});
} catch (error) {
console.error('Error fetching existing players:', error);
}
}
async function updateQueueDisplay() {
try {
const response = await fetch(`${API_BASE_URL}/queue/players`);
const players = await response.json();
if (players.length > 0) {
queueDisplay.innerHTML = players.map(p => `<div class="text-sm"><strong>${p.player_id}</strong> (MMR: ${p.mmr})</div>`).join('');
} else {
queueDisplay.innerHTML = '<p class="text-highlight text-sm">No players in queue.</p>';
}
} catch (error) {
console.error('Error updating queue display:', error);
}
}
async function updateRecentMatches() {
try {
const response = await fetch(`${API_BASE_URL}/matches/recent`);
const matches = await response.json();
if (matches.length > 0) {
recentMatchesDisplay.innerHTML = matches.map(match => `
<div class="p-2 bg-primary rounded">
<p class="text-sm font-bold text-green-400">WINNERS: ${match.winner_team.join(', ')}</p>
<p class="text-sm text-red-400">LOSERS: ${match.loser_team.join(', ')}</p>
</div>
`).join('');
} else {
recentMatchesDisplay.innerHTML = '<p class="text-highlight">No recent matches to display.</p>';
}
} catch(error) {
console.error('Error updating recent matches:', error);
}
}
// --- UI Logic & Event Listeners ---
function logNotification(message, type = 'info') {
if (notificationsLog.querySelector('p')) {
notificationsLog.innerHTML = ''; // Clear initial message
}
const color = type === 'error' ? 'text-red-400' : (type === 'match') ? 'text-green-400 font-bold' : 'text-text-secondary';
const time = new Date().toLocaleTimeString();
const logEntry = document.createElement('div');
logEntry.className = `notification text-sm ${color}`;
logEntry.innerHTML = `[${time}] ${message}`;
notificationsLog.prepend(logEntry);
}
function setupMatchSimulator(matchDetails) {
const { match_id, team_a, team_b } = matchDetails;
matchSimulatorDisplay.innerHTML = `
<div>
<h4 class="font-bold">Team A</h4>
<p>${team_a.join(', ')}</p>
</div>
<div>
<h4 class="font-bold">Team B</h4>
<p>${team_b.join(', ')}</p>
</div>
<div class="flex flex-wrap gap-4 mt-4">
<button class="btn btn-sm" onclick="reportMatchResult('${match_id}', ['${team_a.join("','")}'], ['${team_b.join("','")}'])">Team A Wins</button>
<button class="btn btn-sm" onclick="reportMatchResult('${match_id}', ['${team_b.join("','")}'], ['${team_a.join("','")}'])">Team B Wins</button>
</div>
`;
}
joinQueueBtn.addEventListener('click', joinQueue);
searchBtn.addEventListener('click', getPlayerStats);
searchPlayerIdInput.addEventListener('keyup', (event) => {
if (event.key === 'Enter') {
getPlayerStats();
}
});
existingPlayersSelect.addEventListener('change', (event) => {
playerIdInput.value = event.target.value;
});
// --- Server-Sent Events (SSE) for Real-time Notifications ---
function initializeSSE() {
const eventSource = new EventSource(`${API_BASE_URL}/stream`);
eventSource.onopen = () => {
logNotification('Connected to server for real-time events.', 'info');
};
eventSource.onmessage = (event) => {
console.log("SSE message received:", event.data);
const data = JSON.parse(event.data);
if (data.match_id) {
const message = `Match Found! ID: ${data.match_id}`;
logNotification(message, 'match');
setupMatchSimulator(data);
updateQueueDisplay(); // Update queue after match is found
}
};
eventSource.onerror = (err) => {
console.error('EventSource failed:', err);
logNotification('Connection to server lost. Trying to reconnect...', 'error');
eventSource.close();
setTimeout(initializeSSE, 5000); // Attempt to reconnect every 5 seconds
};
}
// --- Initial Load ---
document.addEventListener('DOMContentLoaded', () => {
initializeSSE();
populateExistingPlayers();
updateQueueDisplay();
updateRecentMatches();
setInterval(updateQueueDisplay, 5000); // Refresh queue every 5 seconds
});
</script>
</body>
</html>