Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
display login user score at the top of the virtual contest table
  • Loading branch information
parsely1231 committed Jul 5, 2020
1 parent 719405c commit e374932
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ interface OuterProps {
readonly start: number;
readonly end: number;
readonly enableAutoRefresh: boolean;
readonly atCoderUserId: string;
}

interface InnerProps extends OuterProps {
Expand Down Expand Up @@ -266,8 +267,107 @@ function compareProblem<T extends { id: string; order: number | null }>(
return a.id.localeCompare(b.id);
}

interface ContestTableRowProps {
userId: string;
index: number;
problems: {
item: VirtualContestItem;
title?: string | undefined;
contestId?: string | undefined;
}[];
bestSubmissions: BestSubmissionEntry[];
items: {
id: string;
point: number | null;
order: number | null;
contestId: string | undefined;
title: string | undefined;
}[];
showProblems: boolean;
start: number;
showEstimatedPerformances: boolean;
estimatedPerformances: {
performance: number;
userId: string;
}[];
}

const ContestTableRow: React.FC<ContestTableRowProps> = ({
userId,
index,
problems,
bestSubmissions,
items,
showProblems,
start,
showEstimatedPerformances,
estimatedPerformances,
}) => {
const totalResult = calcTotalResult(
userId,
problems.map((p) => p.item),
bestSubmissions
);
return (
<tr>
<th>{index + 1}</th>
<th>{userId}</th>
{!showProblems
? null
: items.sort(compareProblem).map((problem) => {
const info = bestSubmissions.find(
(e) => e.userId === userId && e.problemId === problem.id
)?.bestSubmissionInfo;
if (!info) {
return (
<td key={problem.id} style={{ textAlign: "center" }}>
-
</td>
);
}
const best = info.bestSubmission;
const trials =
info.trialsBeforeBest +
(isAccepted(info.bestSubmission.result) ? 0 : 1);
const point =
problem.point !== null
? isAccepted(best.result)
? problem.point
: 0
: best.point;
return (
<td key={problem.id}>
<ScoreCell
trials={trials}
maxPoint={point}
time={best.epoch_second - start}
/>
</td>
);
})}
<td>
<ScoreCell
trials={totalResult.trialsBeforeBest}
maxPoint={totalResult.point}
time={totalResult.lastBestSubmissionTime - start}
/>
</td>
{showEstimatedPerformances ? (
<td>
<EstimatedPerformance
estimatedPerformance={
estimatedPerformances.find((e) => e.userId === userId)
?.performance
}
/>
</td>
) : null}
</tr>
);
};

const InnerContestTable: React.FC<InnerProps> = (props) => {
const { showProblems, problems, users, start, end } = props;
const { showProblems, problems, users, start, end, atCoderUserId } = props;
const problemModels = props.problemModels.fulfilled
? props.problemModels.value
: ImmutableMap<ProblemId, ProblemModel>();
Expand All @@ -293,6 +393,11 @@ const InnerContestTable: React.FC<InnerProps> = (props) => {
problems.map((p) => p.item),
bestSubmissions
);

const loginUserIndex = sortedUserIds.findIndex(
(userId) => userId === atCoderUserId
);

const estimatedPerformances = props.enableEstimatedPerformances
? getEstimatedPerformances(
users,
Expand Down Expand Up @@ -343,68 +448,33 @@ const InnerContestTable: React.FC<InnerProps> = (props) => {
</tr>
</thead>
<tbody>
{loginUserIndex >= 0 ? (
<ContestTableRow
userId={atCoderUserId}
index={loginUserIndex}
problems={problems}
bestSubmissions={bestSubmissions}
items={items}
showProblems={showProblems}
start={start}
showEstimatedPerformances={showEstimatedPerformances}
estimatedPerformances={estimatedPerformances}
/>
) : null}
{sortedUserIds.map((userId, i) => {
const totalResult = calcTotalResult(
userId,
problems.map((p) => p.item),

bestSubmissions
);
return (
<tr key={i}>
<th>{i + 1}</th>
<th>{userId}</th>
{!showProblems
? null
: items.sort(compareProblem).map((problem) => {
const info = bestSubmissions.find(
(e) => e.userId === userId && e.problemId === problem.id
)?.bestSubmissionInfo;
if (!info) {
return (
<td key={problem.id} style={{ textAlign: "center" }}>
-
</td>
);
}
const best = info.bestSubmission;
const trials =
info.trialsBeforeBest +
(isAccepted(info.bestSubmission.result) ? 0 : 1);
const point =
problem.point !== null
? isAccepted(best.result)
? problem.point
: 0
: best.point;
return (
<td key={problem.id}>
<ScoreCell
trials={trials}
maxPoint={point}
time={best.epoch_second - start}
/>
</td>
);
})}
<td>
<ScoreCell
trials={totalResult.trialsBeforeBest}
maxPoint={totalResult.point}
time={totalResult.lastBestSubmissionTime - start}
/>
</td>
{showEstimatedPerformances ? (
<td>
<EstimatedPerformance
estimatedPerformance={
estimatedPerformances.find((e) => e.userId === userId)
?.performance
}
/>
</td>
) : null}
</tr>
<ContestTableRow
key={userId}
userId={userId}
index={i}
problems={problems}
bestSubmissions={bestSubmissions}
items={items}
showProblems={showProblems}
start={start}
showEstimatedPerformances={showEstimatedPerformances}
estimatedPerformances={estimatedPerformances}
/>
);
})}
</tbody>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ const InnerShowContest: React.FC<InnerProps> = (props) => {
start={start}
end={end}
enableAutoRefresh={autoRefreshEnabled}
atCoderUserId={atCoderUserId}
/>
)}
</Col>
Expand Down

0 comments on commit e374932

Please sign in to comment.