Skip to content

Commit

Permalink
Fix for scoreboard
Browse files Browse the repository at this point in the history
  • Loading branch information
irdkwmnsb committed Apr 16, 2024
1 parent 20bd12f commit ac99508
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ export const ContestantInfo = ({ teamId, roundBR= true, className = null }) => {
const contestInfo = useAppSelector((state) => state.contestInfo.info);
const scoreboardData = useAppSelector((state) => state.scoreboard[SCOREBOARD_TYPES.normal].ids[teamId]);
const awards = useAppSelector((state) => state.scoreboard[SCOREBOARD_TYPES.normal].idAwards[teamId]);
const rank = useAppSelector((state) => state.scoreboard[SCOREBOARD_TYPES.normal].rankById[teamId]);
const medal = awards?.find((award) => award.type == Award.Type.medal) as Award.medal;
const teamData = useAppSelector((state) => state.contestInfo.info?.teamsId[teamId]);
const formatPenalty = useFormatPenalty();
return <ContestantInfoWrap round={roundBR} className={className}>
<ContestantInfoLabel rank={scoreboardData?.rank} medal={medal?.medalColor}/>
<ContestantInfoLabel rank={rank} medal={medal?.medalColor}/>
<ContestantInfoTeamNameLabel text={teamData?.shortName ?? "??"}/>
<ContestantInfoScoreLabel align={"right"}
text={scoreboardData === null ? "??" : formatScore(scoreboardData?.totalScore ?? 0.0, 1)}/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { VerticalSubmissionRow } from "./SubmissionRow";
import styled from "styled-components";
import c from "../../../config";
import { useAppSelector } from "@/redux/hooks";
import { LegacyScoreboardRow } from "@shared/api";

type ContestantViewVerticalWrapProps = {
top: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,12 +298,13 @@ export const QueueRow = ({ runInfo,
const teamData = useAppSelector((state) => state.contestInfo.info?.teamsId[runInfo.teamId]);
const probData = useAppSelector((state) => state.contestInfo.info?.problemsId[runInfo.problemId]);
const awards = useAppSelector((state) => state.scoreboard[SCOREBOARD_TYPES.normal].idAwards[runInfo.teamId]);
const rank = useAppSelector((state) => state.scoreboard[SCOREBOARD_TYPES.normal].rankById[runInfo.teamId]);
const medal = awards?.find((award) => award.type == Award.Type.medal) as Award.medal;
const isFTSRun = runInfo?.result?.type === "ICPC" && runInfo.result.isFirstToSolveRun || runInfo?.result?.type === "IOI" && runInfo.result.isFirstBestRun;
return <StyledQueueRow
// flashing={flashing}
>
<QueueRankLabel rank={scoreboardData?.rank} medal={medal?.medalColor}/>
<QueueRankLabel rank={rank} medal={medal?.medalColor}/>
<QueueTeamNameLabel text={teamData?.shortName ?? "??"}/>
<QueueScoreLabel align={"right"}
text={scoreboardData === null ? "??" : formatScore(scoreboardData?.totalScore ?? 0.0, 1)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import _ from "lodash";
import PropTypes from "prop-types";
import React, { useEffect, useState } from "react";
import styled from "styled-components";
Expand All @@ -10,8 +9,7 @@ import { ShrinkingBox } from "../../atoms/ShrinkingBox";
import { formatScore, useFormatPenalty, useNeedPenalty } from "@/services/displayUtils";
import { useElementSize } from "usehooks-ts";
import { useAppSelector } from "@/redux/hooks";
import { Award, LegacyScoreboardRow, OptimismLevel, ScoreboardSettings } from "@shared/api";
import { ScoreboardData } from "@/redux/contest/scoreboard";
import { Award, OptimismLevel, ScoreboardSettings } from "@shared/api";
import { SCOREBOARD_TYPES } from "@/consts";


Expand Down Expand Up @@ -127,12 +125,13 @@ export const ScoreboardRow = ({ teamId,
const scoreboardData = useAppSelector((state) => state.scoreboard[optimismLevel].ids[teamId]);
const contestData = useAppSelector((state) => state.contestInfo.info);
const teamData = useAppSelector((state) => state.contestInfo.info?.teamsId[teamId]);
const awards = useAppSelector((state) => state.scoreboard[SCOREBOARD_TYPES.normal].idAwards[teamId]);
const awards: Award[] = useAppSelector((state) => state.scoreboard[SCOREBOARD_TYPES.normal].idAwards[teamId]);
const rank = useAppSelector((state) => state.scoreboard[SCOREBOARD_TYPES.normal].rankById[teamId]);
const medal = awards?.find((award) => award.type == Award.Type.medal) as Award.medal;
const needPenalty = useNeedPenalty();
const formatPenalty = useFormatPenalty();
return <ScoreboardRowWrap nProblems={contestData?.problems?.length ?? 1} needPenalty={needPenalty}>
<ScoreboardRankLabel rank={scoreboardData?.rank} medal={medal?.medalColor}/>
<ScoreboardRankLabel rank={rank} medal={medal?.medalColor}/>
<ScoreboardRowName align={c.SCOREBOARD_CELL_TEAMNANE_ALIGN} text={teamData?.shortName ?? "??"}/>
<ShrinkingBox align={c.SCOREBOARD_CELL_POINTS_ALIGN}
text={scoreboardData === null ? "??" : formatScore(scoreboardData?.totalScore ?? 0.0, 1)}/>
Expand Down
4 changes: 4 additions & 0 deletions src/frontend/overlay/src/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export const WEBSOCKETS = {
...WEBSOCKETS_OVERRIDE
};

/**
* @deprecated
* Use enum from api.ts
*/
export const SCOREBOARD_TYPES = Object.freeze({
normal: "normal",
optimistic: "optimistic",
Expand Down
10 changes: 4 additions & 6 deletions src/frontend/overlay/src/redux/contest/scoreboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { Award, OptimismLevel, ScoreboardDiff, ScoreboardRow, TeamId } from "@sh
import { createSlice, PayloadAction } from "@reduxjs/toolkit";

export type ScoreboardData = {
ids: Record<TeamId, ScoreboardRow & {rank: number}>, // maybe stable?
ids: Record<TeamId, ScoreboardRow>, // maybe stable?
idAwards: Record<TeamId, undefined | Exclude<Award, "teams">[]>,
order: TeamId[],
orderById: Record<TeamId, number>,
rankById: Record<TeamId, number>,
ranks: number[],
awards: Award[]
};
Expand Down Expand Up @@ -34,16 +35,13 @@ const scoreboardSlice = createSlice({
state[optimism].awards = diff.awards;
state[optimism].order = diff.order;
state[optimism].ranks = diff.ranks;
const rankMap = Object.fromEntries(_.zip(diff.order, diff.ranks));
for (const [id, newData] of Object.entries(diff.rows)) {
state[optimism].ids[id] = {
...newData,
rank: rankMap[id]
};
state[optimism].ids[id] = newData;
}
state[optimism].orderById = Object.fromEntries(
diff.order.map((teamId, index) => [teamId, index])
);
state[optimism].rankById = Object.fromEntries(_.zip(diff.order, diff.ranks));
state[optimism].idAwards = {};
for (const award of diff.awards) {
for (const teamId of award.teams) {
Expand Down
1 change: 0 additions & 1 deletion src/frontend/overlay/src/services/ws/ws.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import _ from "lodash";
import { SCOREBOARD_TYPES } from "../../consts";
import { pushLog } from "../../redux/debug";
import { handleMessage as contestInfoHandler } from "./contestInfo";
import { handleMessage as mainScreenHandler } from "./mainScreen";
Expand Down

0 comments on commit ac99508

Please sign in to comment.