Completed matches scheduling
This commit is contained in:
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