This commit is contained in:
parent
476cd0bd61
commit
1e7c8ad504
2 changed files with 50 additions and 19 deletions
|
@ -5,6 +5,7 @@ import {
|
||||||
import {
|
import {
|
||||||
Participant,
|
Participant,
|
||||||
participantFromApiParticipant,
|
participantFromApiParticipant,
|
||||||
|
Result,
|
||||||
} from '../models/Participant';
|
} from '../models/Participant';
|
||||||
|
|
||||||
export interface SpeedRoundParticipant {
|
export interface SpeedRoundParticipant {
|
||||||
|
@ -13,9 +14,14 @@ export interface SpeedRoundParticipant {
|
||||||
hasWon: boolean;
|
hasWon: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface SpeedLane {
|
||||||
|
result?: Result;
|
||||||
|
participant: Participant;
|
||||||
|
}
|
||||||
|
|
||||||
export interface SpeedRoundPair {
|
export interface SpeedRoundPair {
|
||||||
laneA?: Participant;
|
laneA?: SpeedLane;
|
||||||
laneB?: Participant;
|
laneB?: SpeedLane;
|
||||||
winner?: 'A' | 'B';
|
winner?: 'A' | 'B';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,14 +71,18 @@ function getRoundRank(name: string): number {
|
||||||
*/
|
*/
|
||||||
function computeWinnerOfPair(pair: SpeedRoundPair, roundIndex: number) {
|
function computeWinnerOfPair(pair: SpeedRoundPair, roundIndex: number) {
|
||||||
if (
|
if (
|
||||||
pair.laneA?.results[roundIndex]?.rank === undefined ||
|
pair.laneA?.participant.results[roundIndex]?.rank === undefined ||
|
||||||
pair.laneB?.results[roundIndex]?.rank === undefined
|
pair.laneB?.participant.results[roundIndex]?.rank === undefined
|
||||||
)
|
)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
pair.laneA.result = pair.laneA.participant.results[roundIndex];
|
||||||
|
pair.laneB.result = pair.laneB.participant.results[roundIndex];
|
||||||
|
|
||||||
if (pair.winner === undefined) {
|
if (pair.winner === undefined) {
|
||||||
pair.winner =
|
pair.winner =
|
||||||
pair.laneA.results[roundIndex].rank > pair.laneB.results[roundIndex].rank
|
pair.laneA.participant.results[roundIndex].rank >
|
||||||
|
pair.laneB.participant.results[roundIndex].rank
|
||||||
? 'B'
|
? 'B'
|
||||||
: 'A';
|
: 'A';
|
||||||
}
|
}
|
||||||
|
@ -89,7 +99,9 @@ function getWinnerOfPair(
|
||||||
roundNumber: number,
|
roundNumber: number,
|
||||||
): Participant | undefined {
|
): Participant | undefined {
|
||||||
computeWinnerOfPair(pair, roundNumber);
|
computeWinnerOfPair(pair, roundNumber);
|
||||||
return pair.winner === 'A' ? pair.laneA : pair.laneB;
|
return pair.winner === 'A'
|
||||||
|
? pair.laneA?.participant
|
||||||
|
: pair.laneB?.participant;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -103,7 +115,9 @@ function getLooserOfPair(
|
||||||
roundNumber: number,
|
roundNumber: number,
|
||||||
): Participant | undefined {
|
): Participant | undefined {
|
||||||
computeWinnerOfPair(pair, roundNumber);
|
computeWinnerOfPair(pair, roundNumber);
|
||||||
return pair.winner === 'A' ? pair.laneB : pair.laneA;
|
return pair.winner === 'A'
|
||||||
|
? pair.laneB?.participant
|
||||||
|
: pair.laneA?.participant;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -126,15 +140,28 @@ function computeRoundFromPreviousRound(
|
||||||
const nextRoundPairs = new Array(previousRound.pairs.length / 2)
|
const nextRoundPairs = new Array(previousRound.pairs.length / 2)
|
||||||
.fill(0)
|
.fill(0)
|
||||||
.map((_, i) => {
|
.map((_, i) => {
|
||||||
|
const laneAParticipant = getAdvancingParticipant(
|
||||||
|
previousRound.pairs[i * 2],
|
||||||
|
previousRound.roundIndex,
|
||||||
|
);
|
||||||
|
const laneBParticipant = getAdvancingParticipant(
|
||||||
|
previousRound.pairs[i * 2 + 1],
|
||||||
|
previousRound.roundIndex,
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
laneA: getAdvancingParticipant(
|
laneA:
|
||||||
previousRound.pairs[i * 2],
|
laneAParticipant === undefined
|
||||||
previousRound.roundIndex,
|
? undefined
|
||||||
),
|
: {
|
||||||
laneB: getAdvancingParticipant(
|
participant: laneAParticipant,
|
||||||
previousRound.pairs[i * 2 + 1],
|
},
|
||||||
previousRound.roundIndex,
|
laneB:
|
||||||
),
|
laneBParticipant === undefined
|
||||||
|
? undefined
|
||||||
|
: {
|
||||||
|
participant: laneBParticipant,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -191,8 +218,8 @@ export function convertResultsToSpeedFlowchartResult(
|
||||||
|
|
||||||
const firstRoundPairs = ranksOfLaneAInOrder.map(rank => {
|
const firstRoundPairs = ranksOfLaneAInOrder.map(rank => {
|
||||||
return {
|
return {
|
||||||
laneA: convertedParticipants[rank - 1],
|
laneA: { participant: convertedParticipants[rank - 1] },
|
||||||
laneB: getOpponent(rank - 1),
|
laneB: { participant: getOpponent(rank - 1) },
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -51,14 +51,18 @@ export default function SpeedFlowchartPage() {
|
||||||
fontWeight: pair.winner === 'A' ? 'bold' : 'plain',
|
fontWeight: pair.winner === 'A' ? 'bold' : 'plain',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
A: {pair.laneA?.firstName} {pair.laneA?.lastName}
|
A: {pair.laneA?.participant.firstName}{' '}
|
||||||
|
{pair.laneA?.participant.lastName}:{' '}
|
||||||
|
{pair.laneA?.result?.result}
|
||||||
</Typography>
|
</Typography>
|
||||||
<Typography
|
<Typography
|
||||||
sx={{
|
sx={{
|
||||||
fontWeight: pair.winner === 'B' ? 'bold' : 'plain',
|
fontWeight: pair.winner === 'B' ? 'bold' : 'plain',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
B: {pair.laneB?.firstName} {pair.laneB?.lastName}
|
B: {pair.laneB?.participant.firstName}{' '}
|
||||||
|
{pair.laneB?.participant.lastName}:{' '}
|
||||||
|
{pair.laneB?.result?.result}
|
||||||
</Typography>
|
</Typography>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
Loading…
Reference in a new issue