Skip to content
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

Add omegup online judge #22

Merged
merged 6 commits into from Aug 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions app/src/Config/Config.ts
Expand Up @@ -54,7 +54,8 @@ export default class Config {
debugCommand: "g++ -std=gnu++17 -DDEBUG -Wshadow -Wall",
aliases: {
codeforces: "54",
atcoder: "4003"
atcoder: "4003",
omegaup: "cpp17-gcc"
Comment on lines +57 to +58
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default cpp aliases for each supported online judge in Config

}
},
py: {
Expand All @@ -63,7 +64,8 @@ export default class Config {
debugCommand: "python3 -O",
aliases: {
codeforces: "31",
atcoder: "4006"
atcoder: "4006",
omegaup: "py3"
Comment on lines +67 to +68
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default python aliases for each supported online judge in Config

}
}
};
Expand Down
1 change: 1 addition & 0 deletions app/src/Config/Types/LangAliases.ts
@@ -1,4 +1,5 @@
export type LangAliases = {
codeforces?: string;
atcoder?: string;
omegaup?: string;
};
45 changes: 45 additions & 0 deletions app/src/Submit/OnlineJudgeFactory/OmegaUp.ts
@@ -0,0 +1,45 @@
/*
cpbooster "Competitive Programming Booster"
Copyright (C) 2020 Sergio G. Sanchez V.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import { Page } from "playwright-chromium";
import OnlineJudge, { OnlineJudgeName } from "./OnlineJudge";

export default class Codeforces extends OnlineJudge {
readonly onlineJudgeName = OnlineJudgeName.omegaup;
readonly loginUrl = "https://omegaup.com/login/";
readonly blockedResourcesOnSubmit: Set<string> = new Set(["image", "font"]);
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sometimes we don't need to load "javascript" or "stylesheets" or images etc, by not loading them (blocking them) we can submit files faster. blockedResourcesOnSubmit is used to know which resources are not needed. See Codeforces.ts and AtCoder.ts for more examples.


async isLoggedIn(page: Page): Promise<boolean> {
const querySelector = "a[href*=logout]";
return (await page.$(querySelector)) !== null;
}
Comment on lines +27 to +30
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

usually this pattern works for most sites to detect if a user is logged in or not, so probably you would be just copying and pasting this.


async uploadFile(filePath: string, page: Page, langAlias: string): Promise<boolean> {
try {
await page.click("a[href*=new-run]");
const inputFile = await page.$("input[type=file]");
if (inputFile) await inputFile.setInputFiles(filePath);
await page.selectOption("select", { value: langAlias });
await page.click('button[type=submit][class="btn btn-primary"]');
return true;
} catch (e) {
console.log(e);
return false;
}
}
}
Comment on lines +32 to +45
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic to manipulate DOM/HTML elements in order to submit a source code file to the corresponding website

5 changes: 4 additions & 1 deletion app/src/Submit/OnlineJudgeFactory/OnlineJudge.ts
Expand Up @@ -27,7 +27,8 @@ import open from "open";

export enum OnlineJudgeName {
codeforces = "codeforces",
atcoder = "atcoder"
atcoder = "atcoder",
omegaup = "omegaup"
}
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

every online judge name should be declared in this enum, and use this one, instead of raw strings


export default abstract class OnlineJudge {
Expand Down Expand Up @@ -125,6 +126,8 @@ export default abstract class OnlineJudge {
return langAliases?.codeforces;
case OnlineJudgeName.atcoder:
return langAliases?.atcoder;
case OnlineJudgeName.omegaup:
return langAliases?.omegaup;
Comment on lines +129 to +130
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gets the language alias from the config depending on the OnlineJudge

default:
return undefined;
}
Expand Down
3 changes: 3 additions & 0 deletions app/src/Submit/OnlineJudgeFactory/OnlineJudgeFactory.ts
Expand Up @@ -19,6 +19,7 @@
import { exit } from "process";
import AtCoder from "./AtCoder";
import Codeforces from "./Codeforces";
import OmegaUp from "./OmegaUp";
import OnlineJudge from "./OnlineJudge";

export default class OnlineJudgeFactory {
Expand All @@ -28,6 +29,8 @@ export default class OnlineJudgeFactory {
return new Codeforces();
} else if (url.includes("atcoder")) {
return new AtCoder();
} else if (url.includes("omegaup")) {
return new OmegaUp();
} else {
console.log("Online Judge not supported");
exit(0);
Expand Down