Skip to content

Commit f751354

Browse files
authored
Merge pull request #1135 from kenkoooo/pr/sin471/1131
fix isRatedContest()
2 parents f0cbeae + 9fb4e6f commit f751354

File tree

5 files changed

+40
-22
lines changed

5 files changed

+40
-22
lines changed

atcoder-problems-frontend/src/api/APIClient.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -198,16 +198,20 @@ export const useProblems = () => {
198198
return useSWRData(url, (url) => fetchTypedArray(url, isProblem)).data;
199199
};
200200

201-
export const useContestToProblems = () => {
201+
const useContestProblemList = () => {
202202
const url = STATIC_API_BASE_URL + "/contest-problem.json";
203-
const contestIdToProblemIdArray = useSWRData(url, (url) =>
203+
return useSWRData(url, (url) =>
204204
fetchTypedArray(
205205
url,
206206
(obj): obj is { contest_id: ContestId; problem_id: ProblemId } =>
207207
hasPropertyAsType(obj, "contest_id", isString) &&
208208
hasPropertyAsType(obj, "problem_id", isString)
209209
)
210210
);
211+
};
212+
213+
export const useContestToProblems = () => {
214+
const contestIdToProblemIdArray = useContestProblemList();
211215
const problemMap = useProblemMap();
212216
return contestIdToProblemIdArray.data?.reduce(
213217
(map, { contest_id, problem_id }) => {
@@ -224,15 +228,7 @@ export const useContestToProblems = () => {
224228
};
225229

226230
export const useContestToMergedProblems = () => {
227-
const url = STATIC_API_BASE_URL + "/contest-problem.json";
228-
const contestIdToProblemIdArray = useSWRData(url, (url) =>
229-
fetchTypedArray(
230-
url,
231-
(obj): obj is { contest_id: ContestId; problem_id: ProblemId } =>
232-
hasPropertyAsType(obj, "contest_id", isString) &&
233-
hasPropertyAsType(obj, "problem_id", isString)
234-
)
235-
);
231+
const contestIdToProblemIdArray = useContestProblemList();
236232
const { data: problemMap } = useMergedProblemMap();
237233
return contestIdToProblemIdArray.data?.reduce(
238234
(map, { contest_id, problem_id }) => {

atcoder-problems-frontend/src/pages/TablePage/ContestTable.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,10 @@ export const ContestTable: React.FC<Props> = (props) => {
115115
isExperimentalDifficulty={
116116
model ? model.is_experimental : false
117117
}
118-
showDifficultyUnavailable={isRatedContest(contest)}
118+
showDifficultyUnavailable={isRatedContest(
119+
contest,
120+
problemInfo.length
121+
)}
119122
showDifficulty={props.showDifficulty}
120123
problemId={problem.id}
121124
problemTitle={problem.title}

atcoder-problems-frontend/src/pages/UserPage/AchievementBlock/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ export const AchievementBlock: React.FC<Props> = (props) => {
7777
const ratedProblemIds = new Set(
7878
contests
7979
.flatMap((contest) => {
80-
const isRated = isRatedContest(contest);
8180
const contestProblems = contestToProblems.get(contest.id);
81+
const isRated = isRatedContest(contest, contestProblems?.length ?? 0);
8282
return isRated && contestProblems ? contestProblems : [];
8383
})
8484
.map((problem) => problem.id)

atcoder-problems-frontend/src/utils/ContestClassifier.test.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe("test function isRatedContest", () => {
1414
start_epoch_second: 1381579200,
1515
title: "AtCoder Beginner Contest 001",
1616
};
17-
expect(isRatedContest(unratedContest)).toBe(false);
17+
expect(isRatedContest(unratedContest, 4)).toBe(false);
1818
});
1919

2020
it("when is rated", () => {
@@ -25,7 +25,18 @@ describe("test function isRatedContest", () => {
2525
start_epoch_second: 1469275200,
2626
title: "AtCoder Beginner Contest 042",
2727
};
28-
expect(isRatedContest(ratedContest)).toBe(true);
28+
expect(isRatedContest(ratedContest, 4)).toBe(true);
29+
});
30+
31+
it("when is heuristic", () => {
32+
const heuristicContest: Contest = {
33+
duration_second: 6000,
34+
id: "ahc999",
35+
rate_change: "All",
36+
start_epoch_second: 1469275200,
37+
title: "AtCoder Heuristic Contest 999",
38+
};
39+
expect(isRatedContest(heuristicContest, 1)).toBe(false);
2940
});
3041
});
3142

atcoder-problems-frontend/src/utils/ContestClassifier.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@ export type ContestCategory = typeof ContestCategories[number];
2020

2121
export const AGC_001_START = 1468670400;
2222

23-
export const isRatedContest = (contest: Contest): boolean => {
23+
export const isRatedContest = (
24+
contest: Contest,
25+
problemCount: number
26+
): boolean => {
2427
return (
25-
contest.rate_change !== "-" && contest.start_epoch_second >= AGC_001_START
28+
contest.rate_change !== "-" &&
29+
contest.start_epoch_second >= AGC_001_START &&
30+
problemCount >= 2
2631
);
2732
};
2833

@@ -38,7 +43,10 @@ const classifyOtherRatedContest = (contest: Contest): ContestCategory => {
3843
return "ARC-Like";
3944
};
4045

41-
export const classifyContest = (contest: Contest): ContestCategory => {
46+
export const classifyContest = (
47+
contest: Contest,
48+
problemCount = 100 // TODO: This function can not classify a non-AHC heuristic contest with this default parameter.
49+
): ContestCategory => {
4250
if (/^abc\d{3}$/.exec(contest.id)) {
4351
return "ABC";
4452
}
@@ -48,8 +56,11 @@ export const classifyContest = (contest: Contest): ContestCategory => {
4856
if (/^agc\d{3}$/.exec(contest.id)) {
4957
return "AGC";
5058
}
59+
if (/^ahc\d{3}$/.exec(contest.id)) {
60+
return "AHC";
61+
}
5162

52-
if (isRatedContest(contest)) {
63+
if (isRatedContest(contest, problemCount)) {
5364
return classifyOtherRatedContest(contest);
5465
}
5566

@@ -63,9 +74,6 @@ export const classifyContest = (contest: Contest): ContestCategory => {
6374
return "JAG";
6475
}
6576

66-
if (/^ahc\d{3}$/.exec(contest.id)) {
67-
return "AHC";
68-
}
6977
if (
7078
/(^Chokudai Contest||^HACK TO THE FUTURE|Asprova|Heuristics Contest)/.exec(
7179
contest.title

0 commit comments

Comments
 (0)