teamRounds = {
const rounds = { Mens: [], Womens: [] };
let roundSize = 64;
while (roundSize >= 1) {
rounds.Mens.push(new Array(roundSize).fill(null));
rounds.Womens.push(new Array(roundSize).fill(null));
roundSize /= 2;
}
const placeTeams = (teams, gender) => {
teams[gender].forEach(team => {
let rd = 1;
while (rd <= 7) {
if (team[`rd${rd}_win`] == 1) {
const placementIdx = findPlacementForTeam(
rd,
team.team_region,
+team.team_seed.replace("a", "").replace("b", ""),
gender
);
rounds[gender][rd - 1][placementIdx] = {
seed: +team.team_seed.replace("a", "").replace("b", ""),
name: team.team_name,
id: team.team_id,
winProb: findWinProb(rd, team.team_name, gender)
};
}
rd += 1;
}
});
rounds[gender].forEach(round =>
round.forEach((team, tIdx) => {
if (team) {
team.opponentName = round[tIdx + (tIdx % 2 ? -1 : 1)]?.name ?? '???'
team.opponentSeed = round[tIdx + (tIdx % 2 ? -1 : 1)]?.seed ?? null
}
})
);
};
placeTeams(teams, 'Mens');
placeTeams(teams, 'Womens');
return rounds;
}