Completed matches scheduling
This commit is contained in:
26
scripts/clearRoundRobin.js
Normal file
26
scripts/clearRoundRobin.js
Normal file
@@ -0,0 +1,26 @@
|
||||
const { PrismaClient } = require('../generated/prisma');
|
||||
|
||||
async function main() {
|
||||
const prisma = new PrismaClient();
|
||||
// Find the round robin stage(s)
|
||||
const rrStages = await prisma.tournamentStage.findMany({ where: { type: 'ROUND_ROBIN' } });
|
||||
const rrStageIds = rrStages.map(s => s.id);
|
||||
if (rrStageIds.length === 0) {
|
||||
console.log('No round robin stage found.');
|
||||
await prisma.$disconnect();
|
||||
return;
|
||||
}
|
||||
// Find all matches for these stages
|
||||
const rrMatches = await prisma.match.findMany({ where: { stageId: { in: rrStageIds } } });
|
||||
const rrMatchIds = rrMatches.map(m => m.id);
|
||||
// Delete results for these matches
|
||||
await prisma.result.deleteMany({ where: { matchId: { in: rrMatchIds } } });
|
||||
// Delete matches
|
||||
await prisma.match.deleteMany({ where: { id: { in: rrMatchIds } } });
|
||||
// Delete the round robin stages
|
||||
await prisma.tournamentStage.deleteMany({ where: { id: { in: rrStageIds } } });
|
||||
console.log(`Deleted ${rrStages.length} round robin stage(s), ${rrMatches.length} matches, and their results.`);
|
||||
await prisma.$disconnect();
|
||||
}
|
||||
|
||||
main().catch(e => { console.error(e); process.exit(1); });
|
||||
@@ -58,7 +58,7 @@ async function resetTournament() {
|
||||
console.log('🏆 Creating new tournament...');
|
||||
const tournament = await prisma.tournament.create({
|
||||
data: {
|
||||
name: 'Championship Tournament',
|
||||
name: 'Spring Championship 2024',
|
||||
date: new Date(),
|
||||
location: 'Main Arena'
|
||||
}
|
||||
|
||||
74
scripts/testSchedule.js
Normal file
74
scripts/testSchedule.js
Normal file
@@ -0,0 +1,74 @@
|
||||
const fetch = require('node-fetch');
|
||||
|
||||
async function testSchedule() {
|
||||
try {
|
||||
console.log('Testing current round robin schedule...\n');
|
||||
|
||||
// Get all matches
|
||||
const matchesRes = await fetch('http://localhost:4000/api/matches');
|
||||
const matches = await matchesRes.json();
|
||||
|
||||
if (!Array.isArray(matches)) {
|
||||
console.log('Failed to fetch matches:', matches);
|
||||
return;
|
||||
}
|
||||
|
||||
// Filter round robin matches
|
||||
const roundRobinMatches = matches.filter(match => match.stage.type === 'ROUND_ROBIN');
|
||||
|
||||
if (roundRobinMatches.length === 0) {
|
||||
console.log('No round robin matches found.');
|
||||
return;
|
||||
}
|
||||
|
||||
// Group matches by pool
|
||||
const pools = {};
|
||||
roundRobinMatches.forEach(match => {
|
||||
if (!pools[match.pool]) {
|
||||
pools[match.pool] = [];
|
||||
}
|
||||
pools[match.pool].push(match);
|
||||
});
|
||||
|
||||
// Check each pool for consecutive games
|
||||
Object.keys(pools).forEach(poolNum => {
|
||||
console.log(`\n=== Pool ${poolNum} ===`);
|
||||
const poolMatches = pools[poolNum];
|
||||
|
||||
let consecutiveGames = 0;
|
||||
|
||||
poolMatches.forEach((match, index) => {
|
||||
const team1Id = match.team1.id;
|
||||
const team2Id = match.team2.id;
|
||||
|
||||
console.log(`Match ${index + 1}: ${match.team1.name} vs ${match.team2.name}`);
|
||||
|
||||
// Check if either team played in the previous match
|
||||
if (index > 0) {
|
||||
const prevMatch = poolMatches[index - 1];
|
||||
const prevTeams = [prevMatch.team1.id, prevMatch.team2.id];
|
||||
|
||||
if (prevTeams.includes(team1Id)) {
|
||||
console.log(` ⚠️ ${match.team1.name} played in previous match!`);
|
||||
consecutiveGames++;
|
||||
}
|
||||
if (prevTeams.includes(team2Id)) {
|
||||
console.log(` ⚠️ ${match.team2.name} played in previous match!`);
|
||||
consecutiveGames++;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
console.log(`\nPool ${poolNum} consecutive games: ${consecutiveGames}`);
|
||||
});
|
||||
|
||||
console.log('\n=== Summary ===');
|
||||
console.log(`Total round robin matches: ${roundRobinMatches.length}`);
|
||||
console.log(`Total pools: ${Object.keys(pools).length}`);
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error testing schedule:', error);
|
||||
}
|
||||
}
|
||||
|
||||
testSchedule();
|
||||
Reference in New Issue
Block a user