-
-
Notifications
You must be signed in to change notification settings - Fork 151
Expand file tree
/
Copy pathAtCoderRegularTable.tsx
More file actions
218 lines (210 loc) · 6.95 KB
/
AtCoderRegularTable.tsx
File metadata and controls
218 lines (210 loc) · 6.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
import { Row } from "reactstrap";
import React from "react";
import { BootstrapTable, TableHeaderColumn } from "react-bootstrap-table";
import { useProblemModelMap } from "../../api/APIClient";
import Contest from "../../interfaces/Contest";
import MergedProblem from "../../interfaces/MergedProblem";
import {
noneStatus,
ProblemId,
ProblemStatus,
StatusLabel,
} from "../../interfaces/Status";
import {
ColorMode,
TableColor,
statusToTableColor,
combineTableColorList,
} from "../../utils/TableColor";
import { ProblemLink } from "../../components/ProblemLink";
import { ContestLink } from "../../components/ContestLink";
import ProblemModel from "../../interfaces/ProblemModel";
import { SubmitTimespan } from "../../components/SubmitTimespan";
import { RatingInfo } from "../../utils/RatingInfo";
import { ProblemPoint } from "../../components/Problempoint";
import { classifyContest } from "../../utils/ContestClassifier";
import { ShowDifficultyMode } from "../../utils/ShowDifficultyMode";
interface Props {
contests: Contest[];
contestToProblems: Map<string, MergedProblem[]>;
hideCompletedContest: boolean;
showDifficultyMode: ShowDifficultyMode;
colorMode: ColorMode;
title: string;
statusLabelMap: Map<ProblemId, ProblemStatus>;
showPenalties: boolean;
selectedLanguages: Set<string>;
userRatingInfo: RatingInfo;
}
const getProblemHeaderAlphabet = (problem: MergedProblem, contest: Contest) => {
if (
problem.problem_index === "H" &&
classifyContest(contest).startsWith("ABC")
) {
return "H/Ex";
}
if (problem.problem_index === "Ex") {
return "H/Ex";
}
return problem.problem_index;
};
const AtCoderRegularTableSFC: React.FC<Props> = (props) => {
const { colorMode, selectedLanguages, showPenalties, userRatingInfo } = props;
const problemModels = useProblemModelMap();
interface OneContest {
contest: Contest;
id: string;
problemStatus: Map<
string,
{
problem: MergedProblem;
status: ProblemStatus;
model?: ProblemModel;
cellColor: TableColor;
}
>;
solvedAll: boolean;
rowColor: TableColor;
}
const contests: OneContest[] = props.contests
.map((contest) => {
const problems = (
props.contestToProblems.get(contest.id) ?? []
).sort((a, b) => a.id.localeCompare(b.id));
const problemStatusList = problems.map((problem) => {
const status = props.statusLabelMap.get(problem.id) ?? noneStatus();
return {
problem,
status,
model: problemModels?.get(problem.id),
cellColor: statusToTableColor({
colorMode,
status,
contest,
selectedLanguages,
}),
};
});
const problemStatus = new Map(
problemStatusList.map((status) => {
const alphabet = getProblemHeaderAlphabet(status.problem, contest);
return [alphabet, status];
})
);
const rowColor = combineTableColorList({
colorMode,
colorList: problemStatusList.map(({ cellColor }) => cellColor),
});
const solvedAll = problemStatusList.every(
({ status }) => status.label === StatusLabel.Success
);
return {
contest,
id: contest.id,
problemStatus,
solvedAll,
rowColor,
} as OneContest;
})
.filter(
({ solvedAll }: OneContest) => !props.hideCompletedContest || !solvedAll
)
.sort(
(a, b) => b.contest.start_epoch_second - a.contest.start_epoch_second
);
const headerList = props.contests
.flatMap((contest) => {
const problems = props.contestToProblems.get(contest.id) ?? [];
return problems.map((p) => getProblemHeaderAlphabet(p, contest));
})
.filter((alphabet) => alphabet.length > 0);
const header = Array.from(new Set(headerList)).sort();
return (
<Row className="my-4">
<h2>{props.title}</h2>
<BootstrapTable
data={contests}
tableContainerClass="contest-table-responsive contest-regular-table-responsive"
>
<TableHeaderColumn
isKey
dataField="id"
columnClassName={(_: string, { rowColor }: OneContest): TableColor =>
rowColor
}
dataFormat={(_, { contest }: OneContest): React.ReactElement => (
<ContestLink contest={contest} title={contest.id.toUpperCase()} />
)}
>
Contest
</TableHeaderColumn>
{header.map((c) => (
<TableHeaderColumn
dataField={c}
key={c}
className={() =>
contests.every(({ problemStatus }) => {
const current = problemStatus.get(c)?.status;
return !current || current.label === StatusLabel.Success;
})
? TableColor.Success
: TableColor.None
}
columnClassName={(_, { problemStatus }: OneContest): string => {
const problem = problemStatus.get(c);
return [
"table-problem",
!problem ? "table-problem-empty" : problem.cellColor,
]
.filter((nm) => nm)
.join(" ");
}}
dataFormat={(
_,
{ contest, problemStatus }: OneContest
): string | React.ReactElement => {
const problem = problemStatus.get(c);
const model = problem ? problem.model : undefined;
if (problem) {
const INF_POINT = 1e18;
const point = problem.problem.point ?? INF_POINT;
return (
<>
<ProblemLink
isExperimentalDifficulty={
!!model && model.is_experimental
}
showDifficultyUnavailable
showDifficultyMode={props.showDifficultyMode}
contestId={contest.id}
problemId={problem.problem.id}
problemIndex={problem.problem.problem_index}
problemName={problem.problem.name}
problemModel={model}
userRatingInfo={userRatingInfo}
/>
{props.colorMode === ColorMode.None && (
<ProblemPoint point={point} />
)}
{props.colorMode === ColorMode.ContestResult && (
<SubmitTimespan
contest={contest}
problemStatus={problem.status}
showPenalties={showPenalties}
/>
)}
</>
);
} else {
return "";
}
}}
>
{c}
</TableHeaderColumn>
))}
</BootstrapTable>
</Row>
);
};
export const AtCoderRegularTable = React.memo(AtCoderRegularTableSFC);