Skip to content

Commit

Permalink
Merge pull request #180 from the-orange-alliance/fgc-2024/playoffs
Browse files Browse the repository at this point in the history
Playoffs commit
  • Loading branch information
kyle-flynn authored Sep 29, 2024
2 parents 725488c + 0ce8db1 commit d43ffea
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 15 deletions.
4 changes: 2 additions & 2 deletions front-end/src/apps/admin/admin-app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ export const AdminApp: FC = () => {
(t) => t.tournamentKey === tournamentKey
);
if (!tournament) return;
// FGC2023 SPECIFIC
if (tournamentKey === '2' || tournamentKey === '3') {
// FGC2024 SPECIFIC
if (tournamentKey === 't3' || tournamentKey === 't4') {
await recalculatePlayoffsRankings(
tournament.eventKey,
tournament.tournamentKey
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ import styled from '@emotion/styled';
import { FC, useMemo } from 'react';
import RED_BANNER from '../assets/red-top-banner.png';
import BLUE_BANNER from '../assets/blue-top-banner.png';
import { Alliance, BLUE_STATION, Match, Ranking, Team } from '@toa-lib/models';
import {
Alliance,
BLUE_STATION,
Match,
QUALIFICATION_LEVEL,
Ranking,
Team
} from '@toa-lib/models';
import { CountryFlag } from './country-flag';
import ArrowUpwardIcon from '@mui/icons-material/ArrowUpward';
import ArrowDownwardIcon from '@mui/icons-material/ArrowDownward';
Expand All @@ -12,6 +19,8 @@ import { Breakdown as Breakdown2024 } from '../../fgc_2024';
import { Grid } from '@mui/material';
import BreakdownRow from './breakdown-row';
import { Block } from '@mui/icons-material';
import { CardStatus } from '@toa-lib/models/build/seasons/FeedingTheFuture';
import { useCurrentTournament } from 'src/api/use-tournament-data';

const Container = styled.div`
display: flex;
Expand Down Expand Up @@ -150,6 +159,7 @@ export const AllianceResult: FC<Props> = ({
ranks,
teams
}) => {
const tournament = useCurrentTournament();
const participants = match.participants ?? [];
const allianceParticipants = participants.filter((p) =>
alliance === 'red' ? p.station < BLUE_STATION : p.station >= BLUE_STATION
Expand All @@ -158,6 +168,13 @@ export const AllianceResult: FC<Props> = ({
() => (teams ? Object.fromEntries(teams.map((t) => [t.teamKey, t])) : {}),
[teams]
);
const isPlayoffs = tournament
? tournament.tournamentLevel > QUALIFICATION_LEVEL
: false;
const isAllianceRedCard =
allianceParticipants.filter((p) => p.cardStatus === CardStatus.RED_CARD)
.length >= 3;
const showZeroScore = isPlayoffs && isAllianceRedCard;

// try to get breakdown sheet
let breakdown: ResultsBreakdown<any>[] = [];
Expand Down Expand Up @@ -224,7 +241,11 @@ export const AllianceResult: FC<Props> = ({
<ScoreContainer alliance={alliance}>
<ScoreText>TOTAL:</ScoreText>
<ScoreText>
{alliance === 'red' ? match.redScore : match.blueScore}
{showZeroScore
? 0
: alliance === 'red'
? match.redScore
: match.blueScore}
</ScoreText>
</ScoreContainer>
</Container>
Expand Down
11 changes: 9 additions & 2 deletions front-end/src/apps/scorekeeper/hooks/use-commit-scores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ import {
patchWholeMatch,
useMatchesForTournament
} from 'src/api/use-match-data';
import { recalculateRankings } from 'src/api/use-ranking-data';
import {
recalculatePlayoffsRankings,
recalculateRankings
} from 'src/api/use-ranking-data';
import { sendCommitScores } from 'src/api/use-socket';
import { useSeasonFieldControl } from 'src/hooks/use-season-components';

Expand Down Expand Up @@ -70,7 +73,11 @@ export const useCommitScoresCallback = () => {

await patchWholeMatch(pending);
// TODO - When to calculate rankings vs. playoff rankings?
await recalculateRankings(eventKey, tournamentKey);
if (tournamentKey === 't3' || tournamentKey === 't4') {
await recalculatePlayoffsRankings(eventKey, tournamentKey);
} else {
await recalculateRankings(eventKey, tournamentKey);
}
fieldControl?.commitScoresForField?.();
sendCommitScores({ eventKey, tournamentKey, id });
setState(MatchState.RESULTS_COMMITTED);
Expand Down
18 changes: 9 additions & 9 deletions lib/models/src/seasons/FeedingTheFuture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,18 +386,18 @@ export function calculatePlayoffsRankings(
...(rankingMap.get(participant.teamKey) as SeasonRanking)
};

if (participant.cardStatus === CardStatus.RED_CARD) {
ranking.played += 1;
rankingMap.set(participant.teamKey, ranking);
continue;
}

if (participant.station < 20) {
if (
participant.station < 20 &&
participant.cardStatus <= CardStatus.YELLOW_CARD
) {
ranking.rankingScore += match.redScore;
} else if (participant.station >= 20) {
} else if (
participant.station >= 20 &&
participant.cardStatus <= CardStatus.YELLOW_CARD
) {
ranking.rankingScore += match.blueScore;
}

ranking.played += 1;
rankingMap.set(participant.teamKey, ranking);
}
}
Expand Down

0 comments on commit d43ffea

Please sign in to comment.