Skip to content

Commit

Permalink
:docs: Improve AtCoder university contest labels (#1526)
Browse files Browse the repository at this point in the history
  • Loading branch information
KATO-Hiro committed Nov 24, 2024
1 parent 5352890 commit 2b33de5
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 7 deletions.
43 changes: 41 additions & 2 deletions src/lib/utils/contest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ const AGC_LIKE: ContestPrefix = {
} as const;
const agcLikePrefixes = getContestPrefixes(AGC_LIKE);

// HACK: As of early November 2024, only UTPC is included.
// HACK: As of November 2024, UTPC, TTPC and TUPC are included.
// More university contests may be added in the future.
/**
* Maps university contest ID prefixes to their display names.
Expand Down Expand Up @@ -190,7 +190,7 @@ export function getContestPrefixes(contestPrefixes: Record<string, string>) {
}

/**
* Contest type priorities (0 = Highest, 19 = Lowest)
* Contest type priorities (0 = Highest, 20 = Lowest)
*
* Priority assignment rationale:
* - Educational contests (0-10): ABS, ABC, APG4B, etc.
Expand Down Expand Up @@ -262,7 +262,23 @@ export function getContestPriority(contestId: string): number {
*/
const regexForAxc = /^(abc|arc|agc)(\d{3})/i;

/**
* Regular expression to match AtCoder University contest identifiers.
*
* The pattern matches strings that:
* - Start with either "ut", "tt", or "tu"
* - Followed by "pc"
* - End with exactly year (four digits)
*
* Example matches:
* - "utpc2014"
* - "ttpc2022"
* - "tupc2023"
*/
const regexForAtCoderUniversity = /^(ut|tt|tu)(pc)(\d{4})/;

export const getContestNameLabel = (contestId: string) => {
// AtCoder
if (regexForAxc.exec(contestId)) {
return contestId.replace(
regexForAxc,
Expand Down Expand Up @@ -298,10 +314,15 @@ export const getContestNameLabel = (contestId: string) => {
return 'アルゴリズムと数学';
}

if (atCoderUniversityPrefixes.some((prefix) => contestId.startsWith(prefix))) {
return getAtCoderUniversityContestLabel(contestId);
}

if (contestId.startsWith('chokudai_S')) {
return contestId.replace('chokudai_S', 'Chokudai SpeedRun ');
}

// AIZU ONLINE JUDGE
if (aojCoursePrefixes.has(contestId)) {
return 'AOJ Courses';
}
Expand All @@ -317,6 +338,24 @@ export const getContestNameLabel = (contestId: string) => {
return contestId.toUpperCase();
};

/**
* Generates a formatted contest label for AtCoder University contests.
*
* This function takes a contest ID string and replaces parts of it using a regular expression
* to generate a formatted label. The label is constructed by converting the contest type and
* common part to uppercase and appending the contest year.
*
* @param contestId - The ID of the contest to format (ex: utpc2023).
* @returns The formatted contest label (ex: UTPC 2023).
*/
export function getAtCoderUniversityContestLabel(contestId: string): string {
return contestId.replace(
regexForAtCoderUniversity,
(_, contestType, common, contestYear) =>
`${(contestType + common).toUpperCase()} ${contestYear}`,
);
}

/**
* Maps PCK contest type abbreviations to their Japanese translations.
*
Expand Down
5 changes: 3 additions & 2 deletions src/test/lib/utils/test_cases/contest_name_and_task_index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createTestCase, zip } from '../../common/test_helpers';
import { getAtCoderUniversityContestLabel } from '$lib/utils/contest';

export type TestCaseForContestNameAndTaskIndex = {
contestId: string;
Expand Down Expand Up @@ -300,11 +301,11 @@ const generateUniversityTestCases = (
): { name: string; value: TestCaseForContestNameAndTaskIndex }[] => {
return zip(contestIds, taskIndices).map(([contestId, taskIndex]) => {
const testCase = createTestCaseForContestNameAndTaskIndex(
`${contestId.toUpperCase()} ${taskIndex}`,
`${getAtCoderUniversityContestLabel(contestId)} ${taskIndex}`,
)({
contestId: `${contestId}`,
taskTableIndex: taskIndex,
expected: `${contestId.toUpperCase()} - ${taskIndex}`,
expected: `${getAtCoderUniversityContestLabel(contestId)} - ${taskIndex}`,
});

return testCase;
Expand Down
6 changes: 3 additions & 3 deletions src/test/lib/utils/test_cases/contest_name_labels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ const generateUtpcTestCases = (
return years.map((year) => {
const testCase = createTestCaseForContestNameLabel(`UTPC ${year}`)({
contestId: `utpc${year}`,
expected: `UTPC${year}`,
expected: `UTPC ${year}`,
});

return testCase;
Expand All @@ -269,7 +269,7 @@ const generateTtpcTestCases = (
return years.map((year) => {
const testCase = createTestCaseForContestNameLabel(`TTPC ${year}`)({
contestId: `ttpc${year}`,
expected: `TTPC${year}`,
expected: `TTPC ${year}`,
});

return testCase;
Expand All @@ -281,7 +281,7 @@ const generateTupcTestCases = (
return years.map((year) => {
const testCase = createTestCaseForContestNameLabel(`TUPC ${year}`)({
contestId: `tupc${year}`,
expected: `TUPC${year}`,
expected: `TUPC ${year}`,
});

return testCase;
Expand Down

0 comments on commit 2b33de5

Please sign in to comment.