Skip to content

Commit ffb6e17

Browse files
committed
fix isRatedContest()
1 parent d9216a0 commit ffb6e17

File tree

5 files changed

+38
-26
lines changed

5 files changed

+38
-26
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: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,14 @@ export type ContestCategory = typeof ContestCategories[number];
2020

2121
export const AGC_001_START = 1468670400;
2222

23-
const isAhc = (contestId: string): boolean => {
24-
return Boolean(/^ahc\d{3}$/.exec(contestId));
25-
};
26-
27-
export const isRatedContest = (contest: Contest): boolean => {
23+
export const isRatedContest = (
24+
contest: Contest,
25+
problemCount: number
26+
): boolean => {
2827
return (
2928
contest.rate_change !== "-" &&
3029
contest.start_epoch_second >= AGC_001_START &&
31-
!isAhc(contest.id)
30+
problemCount >= 2
3231
);
3332
};
3433

@@ -44,7 +43,10 @@ const classifyOtherRatedContest = (contest: Contest): ContestCategory => {
4443
return "ARC-Like";
4544
};
4645

47-
export const classifyContest = (contest: Contest): ContestCategory => {
46+
export const classifyContest = (
47+
contest: Contest,
48+
problemCount = 100
49+
): ContestCategory => {
4850
if (/^abc\d{3}$/.exec(contest.id)) {
4951
return "ABC";
5052
}
@@ -54,8 +56,11 @@ export const classifyContest = (contest: Contest): ContestCategory => {
5456
if (/^agc\d{3}$/.exec(contest.id)) {
5557
return "AGC";
5658
}
59+
if (/^ahc\d{3}$/.exec(contest.id)) {
60+
return "AHC";
61+
}
5762

58-
if (isRatedContest(contest)) {
63+
if (isRatedContest(contest, problemCount)) {
5964
return classifyOtherRatedContest(contest);
6065
}
6166

@@ -69,9 +74,6 @@ export const classifyContest = (contest: Contest): ContestCategory => {
6974
return "JAG";
7075
}
7176

72-
if (isAhc(contest.id)) {
73-
return "AHC";
74-
}
7577
if (
7678
/(^Chokudai Contest||^HACK TO THE FUTURE|Asprova|Heuristics Contest)/.exec(
7779
contest.title

0 commit comments

Comments
 (0)