-
-
Notifications
You must be signed in to change notification settings - Fork 10
🎨 Show tasks by contest types (#1644) #1800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| import type { TaskResults, TaskResult } from '$lib/types/task'; | ||
| import { ContestType } from '$lib/types/contest'; | ||
|
|
||
| import { classifyContest } from '$lib/utils/contest'; | ||
|
|
||
| export const taskResultsForABCLatest20 = (taskResults: TaskResults) => { | ||
| return new TaskResultsForABCLatest20(taskResults); | ||
| }; | ||
|
|
||
| export const taskResultsFromABC319Onwards = (taskResults: TaskResults) => { | ||
| return new TaskResultsFromABC319Onwards(taskResults); | ||
| }; | ||
|
|
||
| // Note: | ||
| // Before and from ABC212 onwards, the number and tendency of tasks are very different. | ||
| export const taskResultsFromABC212ToABC318 = (taskResults: TaskResults) => { | ||
| return new TaskResultsFromABC212ToABC318(taskResults); | ||
| }; | ||
|
|
||
| export abstract class TaskResultsFilter { | ||
| protected taskResults: TaskResults; | ||
|
|
||
| constructor(taskResults: TaskResults) { | ||
| this.taskResults = taskResults; | ||
| } | ||
|
|
||
| /** | ||
| * Filter the taskResults using setCondition(). | ||
| * | ||
| * @returns {TaskResults} The results of the filtered taskResults. | ||
| */ | ||
| run(): TaskResults { | ||
| return this.taskResults.filter(this.setCondition()); | ||
| } | ||
|
|
||
| /** | ||
| * This is an abstract method that must be implemented by any subclass. | ||
| * It is intended to set a condition that will be used to filter task results. | ||
| * | ||
| * @abstract | ||
| * @protected | ||
| * @returns {(taskResult: TaskResult) => boolean} A function that takes a TaskResult | ||
| * and returns a boolean indicating whether the task result meets the condition. | ||
| */ | ||
| protected abstract setCondition(): (taskResult: TaskResult) => boolean; | ||
| } | ||
|
|
||
| // ABC Latest 20 rounds | ||
| class TaskResultsForABCLatest20 extends TaskResultsFilter { | ||
| run(): TaskResults { | ||
| const CONTEST_ROUND_COUNT = 20; | ||
|
|
||
| const taskResultsOnlyABC = this.taskResults.filter(this.setCondition()); | ||
| const latest20ContestIds = Array.from( | ||
| new Set(taskResultsOnlyABC.map((taskResult: TaskResult) => taskResult.contest_id)), | ||
| ) | ||
| .sort() | ||
| .reverse() | ||
| .slice(0, CONTEST_ROUND_COUNT); | ||
|
|
||
| return taskResultsOnlyABC.filter((taskResult: TaskResult) => | ||
| latest20ContestIds.includes(taskResult.contest_id), | ||
| ); | ||
| } | ||
|
|
||
| // Note: Narrow down taskResults in advance to reduce time to display. | ||
| protected setCondition(): (taskResult: TaskResult) => boolean { | ||
| return (taskResult: TaskResult) => classifyContest(taskResult.contest_id) === ContestType.ABC; | ||
| } | ||
| } | ||
|
|
||
| // ABC319 〜 (2023/09/09 〜 ) | ||
| // 7 tasks per contest | ||
| class TaskResultsFromABC319Onwards extends TaskResultsFilter { | ||
| protected setCondition(): (taskResult: TaskResult) => boolean { | ||
| return (taskResult: TaskResult) => | ||
| taskResult.contest_id >= 'abc319' && taskResult.contest_id <= 'abc999'; | ||
| } | ||
| } | ||
|
|
||
| // ABC212 〜 ABC318 (2021/07/31 〜 2023/09/02) | ||
| // 8 tasks per contest | ||
| class TaskResultsFromABC212ToABC318 extends TaskResultsFilter { | ||
| protected setCondition(): (taskResult: TaskResult) => boolean { | ||
| return (taskResult: TaskResult) => | ||
| taskResult.contest_id >= 'abc212' && taskResult.contest_id <= 'abc318'; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.