import { RankingTrackProps } from '../model/rankingTrack'; import { allAvatars } from '../model/user'; const randomTeamsNames = [ 'Rogue', 'MAD Lions', 'G2', 'Fanatic', 'SK Gaming', 'FC Schalke 04', 'Excel', 'Team Vitality', 'Misfits', 'Astralis', ]; const generateRandomRanking = (): RankingTrackProps => { // From 1 to 10 const totalTeamsInTrack = 1 + Math.floor(Math.random() * 10); const totalStages = 1 + Math.floor(Math.random() * 5); // Random sort randomTeamsNames.sort(() => Math.random() * 2 - 1); let teams = new Array(totalTeamsInTrack).fill({}).map((_, i) => ({ id: i, name: randomTeamsNames[i], position: i, points: new Array(totalStages).fill(0), mainAvatar: allAvatars[Math.floor(Math.random() * allAvatars.length)], })); teams.forEach((team) => { let accumulatedPoints = 0; for (let i = 0; i < totalStages; i++) { accumulatedPoints += Math.floor(5 * Math.random()); // eslint-disable-next-line no-param-reassign team.points[i] = accumulatedPoints; } }); teams.sort((a, b) => b.points[totalStages - 1] - a.points[totalStages - 1]); teams = teams.map((x, i) => ({ ...x, position: i, })); for (let i = 1; i < teams.length; i++) { const team = teams[i]; const lastTeam = teams[i-1]; if(lastTeam.points[totalStages - 1] === team.points[totalStages- 1]) { team.position = lastTeam.position; } } teams.sort((a, b) => a.id - b.id); return { teams, maxPoints: Math.max(10, ...teams.map((x) => x.points[totalStages-1])), xOffset: 0, yOffset: 0, totalStages, }; }; export default generateRandomRanking;