LeaderBoard creado v1

This commit is contained in:
2025-08-27 19:43:23 -06:00
parent fb07bdab51
commit bbfbd047c6
4 changed files with 311 additions and 12 deletions

View File

@@ -87,35 +87,66 @@ function buildCsvByRoom(): string {
return lines.join('\n') + '\n';
}
function buildCsvByUuid(): string {
async function buildCsvByUuid(): Promise<string> {
const headers = [
'roomId', 'variant', 'round', 'status',
'uuid', 'name', 'role', 'pavo', 'elote', 'shame'
'uuid', 'name', 'role', 'pavo', 'elote', 'shame', 'events_made'
];
const lines: string[] = [headers.join(',')];
gameRooms.value.forEach(room => {
const apiBase = (import.meta as any).env?.VITE_API_URL || `${window.location.protocol}//${window.location.host}/api`;
const historyCache = new Map<string, any[]>();
for (const room of gameRooms.value) {
const det = (props.roomDetails[room.roomId] || {}) as any;
const status = det.gameStatus || room?.metadata?.gameStatus || 'waiting';
const variant = det.variant || room?.metadata?.currentVariant || 'G1';
const round = det.round || room?.metadata?.currentRound || 1;
const players = (det.players || []) as PlayerRow[];
players.forEach(p => {
for (const p of players) {
const uuid = (p?.uuid || '').toString();
let history = uuid ? historyCache.get(uuid) : [];
if (uuid && !history) {
try {
const resp = await fetch(`${apiBase}/players/${uuid}/history`);
const data = await resp.json();
history = Array.isArray(data?.history) ? data.history : [];
} catch {
history = [];
}
historyCache.set(uuid, history);
}
// Build events_made generically:
// - If kind starts with p1_ or p2_, include only when event.role matches P1/P2
// - Otherwise include by default (system/agnostic events)
const events = (history || []).filter((h: any) => {
const kind = (h?.kind || '').toString();
if (!kind) return false;
const evRole = kind.startsWith('p1_') ? 'P1' : (kind.startsWith('p2_') ? 'P2' : null);
if (!evRole) return true; // role-agnostic
const r = ((h?.role || '') as string).toUpperCase();
return r === evRole;
}).map((h: any) => h.kind);
const eventsHistory = events.join('|');
const row = [
room.roomId,
variant,
round,
status,
p?.uuid || '',
uuid,
p?.name || '',
p?.role || '',
p?.pavoTokens ?? 0,
p?.eloteTokens ?? 0,
p?.shameTokens ?? 0
p?.shameTokens ?? 0,
eventsHistory
].map(csvEscape).join(',');
lines.push(row);
});
});
}
}
return lines.join('\n') + '\n';
}
@@ -137,7 +168,7 @@ function triggerDownload(csv: string, suffix: string) {
}
function downloadCsvByRoom() { triggerDownload(buildCsvByRoom(), 'by-room'); }
function downloadCsvByUuid() { triggerDownload(buildCsvByUuid(), 'by-uuid'); }
async function downloadCsvByUuid() { const csv = await buildCsvByUuid(); triggerDownload(csv, 'by-uuid'); }
</script>
<style scoped>