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

Support toph #323

Merged
merged 18 commits into from
Feb 26, 2019
Merged

Support toph #323

merged 18 commits into from
Feb 26, 2019

Conversation

kfaRabi
Copy link

@kfaRabi kfaRabi commented Feb 19, 2019

Closes #302

Add support for Toph's problem downloading (from archive/collection), login and submission(in archive/collection).

No support for test case download and submission in contest mode yet as the contest pages are being loaded dynamically using JS.

@kfaRabi kfaRabi changed the title #302 Support toph Support toph Feb 19, 2019
Copy link
Member

@kmyk kmyk left a comment

Choose a reason for hiding this comment

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

Thank you for your pull request! Your code is good!
But there are some points which can be better. Please fix these, and then I'll merge.

onlinejudge/service/toph.py Outdated Show resolved Hide resolved
onlinejudge/service/toph.py Outdated Show resolved Hide resolved
onlinejudge/service/toph.py Outdated Show resolved Hide resolved
onlinejudge/service/toph.py Outdated Show resolved Hide resolved
def from_url(cls, s: str) -> Optional['TophProblem']:
result = urllib.parse.urlparse(s)
dirname, basename = posixpath.split(utils.normpath(result.path))
if result.scheme in ('', 'http', 'https') \
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if result.scheme in ('', 'http', 'https') \
# example: https://toph.co/p/new-year-couple
if result.scheme in ('', 'http', 'https') \

return None

class TophProblem(onlinejudge.type.Problem):
def __init__(self, slug: str, kind: Optional[str] = None):
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def __init__(self, slug: str, kind: Optional[str] = None):
def __init__(self, problem_id: str, contest_id: Optional[str] = None):
if contest_id is not None:
raise NotImplementedError

This argument kind is for the problems in the contest mode, right?
When we support the contest mode, it seems that this class need to have something like contest_id since the urls of problems in contets are like https://toph.co/c/tough-dash-feb-2019/arena#!/p/set-union .
So, we should use such names from now, and mark it as not-implemented explicitly.

.gitignore Outdated Show resolved Hide resolved
@kmyk
Copy link
Member

kmyk commented Feb 19, 2019

wow, I forgot to mention some things.

  1. Please use the code formatters and the type checker. They are isort, yapf and mypy. We check them using the continuous integration, so the red cross mark and the message All checks have failed appear. How to run these commands is written here https://github.com/kmyk/online-judge-tools/blob/master/CONTRIBUTING.md#formatter. (I need to apologize that I didn't emphasize this and I didn't translate this to English when the guide which you asked me.)

  2. (this is important, but you need not do this in this pull request) Please write tests. You should make tests/command_download_toph.py and edit tests/command_submit.py and tests/command_login.py. Tests are very important to write programs without bugs. Especially, this program are going to be broken automatically, since Toph may be updated. Therefore we also need to be monitoring bugs which will happen in the future. (by the way, I didn't say this too, sorry.)

  3. (not so important) Please add the name of Toph to the message showed by --help.

for example, the one for the download subcommand is like below:

$ oj download --help
usage: oj download [-h] [-f FORMAT] [-d DIRECTORY] [--overwrite] [-n] [-a]
                   [-s] [--json]
                   url

positional arguments:
  url

optional arguments:
  -h, --help            show this help message and exit
  -f FORMAT, --format FORMAT
                        a format string to specify paths of cases (defaut: "sample-%i.%e" if not --system)
  -d DIRECTORY, --directory DIRECTORY
                        a directory name for test cases (default: test/)
  --overwrite
  -n, --dry-run         don't write to files
  -a, --system          download system testcases
  -s, --silent
  --json

supported services:
  Anarchy Golf
  Aizu Online Judge
  AtCoder
  Codeforces
  yukicoder
  CS Academy
  HackerRank
  PKU JudgeOnline
  Kattis

...

This is in onlinejudge/implementaion/main.py.

https://github.com/kmyk/online-judge-tools/blob/dfe74cc4095265f7e107db649ac123190ba6a08b/onlinejudge/implementation/main.py#L41-L51

@kmyk
Copy link
Member

kmyk commented Feb 19, 2019

@kfaRabi by the way, the commits say you use two email addresses, and one of them is not associated with your GitHub account. Are you okay? If you want, you can fix this with something like git filter-branch --env-filter "........." origin/master and force pushing.

@kfaRabi
Copy link
Author

kfaRabi commented Feb 19, 2019

@kmyk Thank you so much for taking the time to review the code and write suggestion + feedback. I am going to change everything as per your instructions soon. And, about the 2 emails, I actually work on GitLab. My initial commits were on GitLab, and once I was done, I committed here in GitHub. For this reason, you are probably seeing 2 emails.

Kazi Fozle Azim Rabi and others added 2 commits February 19, 2019 14:04
Resolve "Add support for Toph problem archive"

Closes online-judge-tools#2

See merge request toph/online-judge-tools!4
@kmyk kmyk added this to the v0.1.55 milestone Feb 20, 2019
Kazi Rabi added 3 commits February 25, 2019 14:29
@kfaRabi
Copy link
Author

kfaRabi commented Feb 25, 2019

@kmyk I have fixed a few things and added some tests. Could you kindly have a look at it now?

subprocess.check_call([ojtools, 's', '-l', '58482c1804469e2585024324', '-y', '--no-open', url, 'a.py'], stdout=sys.stdout, stderr=sys.stderr)

@unittest.skipIf('CI' in os.environ, 'login is required')
def test_call_submit_add_them_up(self):
Copy link
Member

Choose a reason for hiding this comment

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

(not so important) It becomes better that this test case should submit C++ code, instead of Python code.

This tool guesses language ids (e.g. 584859c204469e2585024499 55b4af33421aa95e80000001 ...) from language names (e.g. C++14 C++11 C++ Python 3 PyPy 3 ...). The language names are different for each services and the guessing sometimes fails, so this case should also test this for C++.

return None

class TophProblem(onlinejudge.type.Problem):
def __init__(self, problem_id: str, kind: Optional[str] = None, contest_id: Optional[str] = None):
Copy link
Member

Choose a reason for hiding this comment

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

The variable kind seems to be not necessary for now (contest_id is None implies it is problem, and not None does contest).

I think that adding this variable is unnecessary generalization, and removing this is simple and better, but we should add this if there is another existing mode or a plan to add a new mode.
@kfaRabi Do you know another mode or a plan?

Copy link
Author

Choose a reason for hiding this comment

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

You are right. We do not need this as Toph does not plan to add any other mode soon.

kmyk added a commit that referenced this pull request Feb 25, 2019
There was:

$ mypy oj onlinejudge setup.py tests
onlinejudge/service/toph.py:151: error: Invalid index type "Optional[str]" for "Dict[str, str]"; expected type "str"
@kmyk
Copy link
Member

kmyk commented Feb 25, 2019

@kfaRabi Thank you for fixing and adding tests.
CI failes yet and there are some additional comments, it is almost mergeable now.
Especially, the comments are just comments and I can merge this without fixing about it.

For CI, please cherry-pick adb59e2 and fd54382, then it will pass and I can/will merge this.

@kmyk
Copy link
Member

kmyk commented Feb 25, 2019

@kfaRabi (and @hjr265) by the way, there are 3 questions:

  • Some commits have the name of @hjr265 as the commiter, but all of them are merge commits. Can I say "@kfaRabi implements this feature"? or both? (this is a question to update CHANGELOG.md)
  • Should I tell Toph to the Japanese community for competitive programming? It sounds good, but there is possibility that it increase the load of the site, and the top of standings of contests are filled with Japanese.
  • (about modes of Toph problems, one written as a review comment)


def get_url(self) -> str:
# TODO: Check for contest_id to return the appropriate URL when support for contest is added
return f'https://toph.co/p/{self.problem_id}'
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return f'https://toph.co/p/{self.problem_id}'
return 'https://toph.co/p/{}'.format(self.problem_id)

f-string is useful and you should use it if possible, however, we need to support Python 3.5, and unfortunately Python 3.5 doesn't support f-strings.

@hjr265
Copy link
Contributor

hjr265 commented Feb 26, 2019

@kmyk Regarding your questions:

  • This feature is being entirely implemented by @kfaRabi. My merge commits are there as we followed the workflow of our team like we do for all Toph related projects. Please feel free to credit him only for this contribution.

  • "top of standings of contests are filled with Japanese"... We would love to welcome the Japanese community to Toph. Please feel free to let them know. 🙂

Thank you for working with us closely as we implement this pull request.

@kmyk
Copy link
Member

kmyk commented Feb 26, 2019

@hjr265 Thank you for answering. I'll let the community know Toph.

kmyk added 2 commits February 26, 2019 15:09
$ mypy oj onlinejudge setup.py tests
onlinejudge/service/toph.py:151: error: Invalid index type "Optional[str]" for "Dict[str, str]"; expected type "str"
@kmyk
Copy link
Member

kmyk commented Feb 26, 2019

CI succeeded 🎉 (once it failed, but it was for instability of tests)

@kmyk kmyk merged commit e5d4136 into online-judge-tools:master Feb 26, 2019
@kmyk
Copy link
Member

kmyk commented Feb 26, 2019

@kfaRabi I have merged your code. Thank you for your good work!

@kfaRabi
Copy link
Author

kfaRabi commented Feb 26, 2019

@kmyk Thanks to you and @hjr265 for constant support and guidelines.

@kmyk
Copy link
Member

kmyk commented Feb 26, 2019

I bumped version to 0.1.55. Now you can get the one which supports Toph with pip3 install -U online-judge-tools

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants