Skip to content

Commit

Permalink
days
Browse files Browse the repository at this point in the history
  • Loading branch information
inker committed Sep 29, 2024
1 parent be5a4a3 commit 86eb6e1
Show file tree
Hide file tree
Showing 15 changed files with 333 additions and 43 deletions.
8 changes: 5 additions & 3 deletions src/containers/LeagueStage/Matrix.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ interface Props {
allTeams: readonly Team[];
numMatchdays: number;
pairings: (readonly [Team, Team])[];
schedule: readonly (readonly (readonly [Team, Team])[])[];
schedule: readonly (readonly (readonly (readonly [Team, Team])[])[])[];
potSize: number;
noCellAnimation?: boolean;
}
Expand All @@ -172,8 +172,10 @@ function Matrix({
const scheduleMap = useMemo(() => {
const o: Record<`${string}:${string}`, number> = {};
for (const [mdIndex, md] of schedule.entries()) {
for (const m of md) {
o[`${m[0].id}:${m[1].id}`] = mdIndex;
for (const day of md) {
for (const m of day) {
o[`${m[0].id}:${m[1].id}`] = mdIndex;
}
}
}
return o;
Expand Down
64 changes: 47 additions & 17 deletions src/containers/LeagueStage/Schedule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import styled from 'styled-components';

import ContentWithFlag from '#ui/table/ContentWithFlag';
import { type Country } from '#model/types';
import type Tournament from '#model/Tournament';

const Root = styled.div`
width: 100%;
Expand All @@ -13,6 +14,7 @@ const CalendarContainer = styled.div`
display: grid;
gap: 16px;
grid-template-columns: repeat(4, 1fr);
align-items: self-start;
width: fit-content;
@container (max-width: 1000px) {
Expand All @@ -25,7 +27,7 @@ const CalendarContainer = styled.div`
`;

const MatchdayRoot = styled.div`
border: 1px double rgb(128 128 128);
border: 1px solid rgb(192 192 192);
font-size: 12px;
`;

Expand All @@ -34,6 +36,18 @@ const MatchdayHeader = styled.div`
justify-content: center;
align-items: center;
height: 20px;
background-color: black;
color: white;
font-weight: 600;
`;

const DayHeader = styled.div`
display: flex;
justify-content: center;
align-items: center;
height: 20px;
border-top: 1px solid rgb(192 192 192);
background-color: rgb(240 240 240);
`;

const MatchPair = styled.div`
Expand Down Expand Up @@ -64,10 +78,11 @@ interface Team {
}

interface Props {
schedule: readonly (readonly (readonly [Team, Team])[])[];
tournament: Tournament;
schedule: readonly (readonly (readonly (readonly [Team, Team])[])[])[];
}

function Schedule({ schedule }: Props) {
function Schedule({ tournament, schedule }: Props) {
useLayoutEffect(() => {
if (schedule.some(md => md.length > 0)) {
const elements = document.getElementsByClassName(
Expand All @@ -89,20 +104,35 @@ function Schedule({ schedule }: Props) {
{schedule.map((md, i) => (
<MatchdayRoot className="matchday">
<MatchdayHeader>MATCHDAY {i + 1}</MatchdayHeader>
{md.map(m => (
<MatchPair>
<ScheduleTeamWrapper>
<ContentWithFlag $country={m[0].country}>
{m[0].name}
</ContentWithFlag>
</ScheduleTeamWrapper>
<MatchPairCenter>-</MatchPairCenter>
<ScheduleTeamWrapper>
<ContentWithFlag $country={m[1].country}>
{m[1].name}
</ContentWithFlag>
</ScheduleTeamWrapper>
</MatchPair>
{md.map((day, dayIndex) => (
<>
<DayHeader>
{tournament === 'cl'
? dayIndex === 2
? 'Thursday'
: dayIndex === 1 || md.length === 1
? 'Wednesday'
: 'Tuesday'
: dayIndex === 1 || md.length === 1
? 'Night'
: 'Evening'}
</DayHeader>
{day.map(m => (
<MatchPair>
<ScheduleTeamWrapper>
<ContentWithFlag $country={m[0].country}>
{m[0].name}
</ContentWithFlag>
</ScheduleTeamWrapper>
<MatchPairCenter>-</MatchPairCenter>
<ScheduleTeamWrapper>
<ContentWithFlag $country={m[1].country}>
{m[1].name}
</ContentWithFlag>
</ScheduleTeamWrapper>
</MatchPair>
))}
</>
))}
</MatchdayRoot>
))}
Expand Down
24 changes: 17 additions & 7 deletions src/containers/LeagueStage/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { memo, useEffect, useMemo, useState } from 'react';
import styled from 'styled-components';
import { shuffle } from 'lodash';

import usePopup from '#store/usePopup';
import type Tournament from '#model/Tournament';
import type Team from '#model/team/GsTeam';
import generatePairings from '#engine/dfs/ls/generatePairings/index';
import generateSchedule from '#engine/dfs/ls/generateSchedule/index';
Expand Down Expand Up @@ -31,11 +31,18 @@ const MatrixWrapper = styled.div`
`;

interface Props {
tournament: Tournament;
season: number;
pots: readonly (readonly Team[])[];
tvPairings: readonly (readonly [Team, Team])[];
}

function LeagueStage({ season, pots: initialPots }: Props) {
function LeagueStage({
tournament,
season,
pots: initialPots,
tvPairings,
}: Props) {
const numMatchdays = initialPots.length * 2;

const numMatches = useMemo(() => {
Expand All @@ -48,7 +55,7 @@ function LeagueStage({ season, pots: initialPots }: Props) {
const [isMatchdayMode, setIsMatchdayMode] = useState(false);

const [pairings, setPairings] = useState<(readonly [Team, Team])[]>([]);
const [schedule, setSchedule] = useState<(readonly [Team, Team])[][]>(
const [schedule, setSchedule] = useState<(readonly [Team, Team])[][][]>(
Array.from(
{
length: numMatchdays,
Expand All @@ -64,7 +71,6 @@ function LeagueStage({ season, pots: initialPots }: Props) {
initialPots.map(pot =>
pot.map(team => ({
...team,
id: `${team.country}|${team.name}`,
})),
),
[initialPots],
Expand Down Expand Up @@ -101,13 +107,14 @@ function LeagueStage({ season, pots: initialPots }: Props) {
if (isFixturesDone) {
const formSchedule = async () => {
const it = await generateSchedule({
tournament,
matchdaySize,
tvPairings,
allGames: pairings,
currentSchedule: schedule,
signal: abortSignal,
});
const newSchedule = it.solutionSchedule.map(md => shuffle(md));
setSchedule(newSchedule);
setSchedule(it.solutionSchedule);
setIsMatchdayMode(true);
};

Expand Down Expand Up @@ -137,7 +144,10 @@ function LeagueStage({ season, pots: initialPots }: Props) {
</Button>
</Portal>
{isMatchdayMode ? (
<Schedule schedule={schedule} />
<Schedule
tournament={tournament}
schedule={schedule}
/>
) : (
<MatrixWrapper>
<Matrix
Expand Down
38 changes: 38 additions & 0 deletions src/data/cl/ls/2024/pairings.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Real Madrid
Barcelona

Bayern
Dortmund

Arsenal
Liverpool

Internazionale
Juventus

Paris
Lille

PSV
Feyenoord

Sporting CP
Benfica

Sturm
Salzburg

Man City
Aston Villa

Milan
Atalanta

Stuttgart
Leipzig

Girona
Atlético

Monaco
Brest
35 changes: 35 additions & 0 deletions src/data/el/ls/2024/pairings.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Galatasaray
Fenerbahçe

Ajax
AZ

Man United
Tottenham

Athletic
Real Sociedad

Roma
Lazio

Frankfurt
Hoffenheim

Lyon
Nice

Anderlecht
Union SG

Olympiacos
PAOK

Porto
Braga

Malmö
Elfsborg

Slavia Praha
Plzeň
15 changes: 14 additions & 1 deletion src/engine/dfs/ls/generateSchedule/getFirstSuitableMatchday.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import { range, shuffle } from 'lodash';

import { findFirstSolution } from '#utils/backtrack';
import { type UefaCountry } from '#model/types';
import type Tournament from '#model/Tournament';
import coldCountries from '#engine/predicates/uefa/utils/coldCountries';

import teamsSharingStadium from './teamsSharingStadium';
import splitMatchdaysIntoDays from './splitMatchdaysIntoDays';

interface Team {
readonly name: string;
Expand All @@ -13,11 +15,15 @@ interface Team {

export default ({
teams,
tournament,
matchdaySize,
tvPairings,
allGames,
}: {
teams: readonly Team[];
tournament: Tournament;
matchdaySize: number;
tvPairings: readonly (readonly [number, number])[];
allGames: readonly (readonly [number, number])[];
}) => {
const numGames = allGames.length;
Expand Down Expand Up @@ -205,9 +211,16 @@ export default ({
arr[matchdayIndex].push(m);
}
arr[solution.pickedMatchday].push(allGames[solution.matchIndex]);
const matchdays = splitMatchdaysIntoDays({
matchdays: arr,
tournament,
matchdaySize,
teams,
tvPairings,
});
return {
pickedMatchday,
matchdays: arr,
matchdays,
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { remove, sample, shuffle } from 'lodash';

import raceWorkers from '#utils/raceWorkers';
import { type UefaCountry } from '#model/types';
import type Tournament from '#model/Tournament';

import { type Func } from './getFirstSuitableMatchday.worker';
import teamsSharingStadium from './teamsSharingStadium';
Expand All @@ -14,12 +15,16 @@ interface Team {
}

export default ({
tournament,
teams,
matchdaySize,
tvPairings,
allGames,
signal,
}: {
tournament: Tournament;
teams: readonly Team[];
tvPairings: readonly (readonly [number, number])[];
matchdaySize: number;
allGames: readonly (readonly [number, number])[];
signal?: AbortSignal;
Expand Down Expand Up @@ -79,7 +84,9 @@ export default ({
}

return {
tournament,
teams,
tvPairings,
matchdaySize,
allGames: orderedGames,
};
Expand Down
Loading

0 comments on commit 86eb6e1

Please sign in to comment.