-
Notifications
You must be signed in to change notification settings - Fork 94
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
#403: add a feature to download MatchOverview of Topcoder Marathon Match #406
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
12b21c5
NONE: add tests/service_topcoder.py
kmyk 900fbc6
#403: add a method for module=ViewOverview of Topcoder Marathon Match
kmyk 454442d
#403: add a method for module=IndividualResultsFeed of Topcoder Marat…
kmyk 1b68404
#403: add a method for module=ViewSystemTest of Topcoder Marathon Match
kmyk cbc1035
#406: refactor TopcoderLongContestProblem.download_individual_results…
kmyk 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 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 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,87 @@ | ||
import os | ||
import unittest | ||
|
||
import onlinejudge._implementation.utils as utils | ||
from onlinejudge.service.topcoder import TopcoderLongContestProblem, TopcoderService | ||
|
||
|
||
class TopcoderSerivceTest(unittest.TestCase): | ||
def test_from_url(self): | ||
self.assertIsInstance(TopcoderService.from_url('https://community.topcoder.com/'), TopcoderService) | ||
self.assertIsNone(TopcoderService.from_url('https://atcoder.jp/')) | ||
|
||
|
||
class TopcoderLongConrestProblemTest(unittest.TestCase): | ||
def test_from_url(self): | ||
self.assertEqual(TopcoderLongContestProblem.from_url('https://community.topcoder.com/longcontest/?module=ViewProblemStatement&rd=17092&pm=14853').rd, 17092) | ||
self.assertEqual(TopcoderLongContestProblem.from_url('https://community.topcoder.com/longcontest/?module=ViewProblemStatement&rd=17092&pm=14853').pm, 14853) | ||
|
||
def test_download_overview(self): | ||
problem = TopcoderLongContestProblem.from_url('https://community.topcoder.com/longcontest/?module=ViewProblemStatement&rd=17143&pm=14889') | ||
overview = problem.download_overview() | ||
self.assertEqual(len(overview), 282) | ||
self.assertEqual(overview[4].rank, 5) | ||
self.assertEqual(overview[4].handle, 'hakomo') | ||
self.assertEqual(overview[4].provisional_rank, 6) | ||
self.assertAlmostEqual(overview[4].provisional_score, 812366.55) | ||
self.assertAlmostEqual(overview[4].final_score, 791163.70) | ||
self.assertEqual(overview[4].language, 'C++') | ||
self.assertEqual(overview[4].cr, 22924522) | ||
|
||
def test_download_individual_results_feed(self): | ||
problem = TopcoderLongContestProblem.from_url('https://community.topcoder.com/longcontest/?module=ViewProblemStatement&rd=17143&pm=14889') | ||
cr = 22924522 | ||
feed = problem.download_individual_results_feed(cr) | ||
self.assertEqual(feed.round_id, problem.rd) | ||
self.assertEqual(feed.coder_id, cr) | ||
self.assertEqual(feed.handle, 'hakomo') | ||
self.assertEqual(feed.submissions[0].number, 1) | ||
self.assertAlmostEqual(feed.submissions[0].score, 816622.81) | ||
self.assertEqual(feed.submissions[0].language, 'C++') | ||
self.assertEqual(feed.submissions[0].time, '04/22/2018 09:56:48') | ||
self.assertEqual(feed.testcases[0].test_case_id, 33800773) | ||
self.assertAlmostEqual(feed.testcases[0].score, 1.0) | ||
self.assertEqual(feed.testcases[0].processing_time, 164) | ||
self.assertEqual(feed.testcases[0].fatal_error_ind, 0) | ||
self.assertEqual(len(feed.submissions), 5) | ||
self.assertEqual(len(feed.testcases), 2000) | ||
|
||
@unittest.skipIf('CI' in os.environ, 'login is required') | ||
def test_download_system_test(self): | ||
with utils.with_cookiejar(utils.get_default_session()): | ||
url = 'https://community.topcoder.com/longcontest/?module=ViewProblemStatement&rd=17143&pm=14889' | ||
tid = 33800773 | ||
problem = TopcoderLongContestProblem.from_url(url) | ||
self.assertEqual(problem.download_system_test(tid), 'seed = 1919427468645\nH = 85\nW = 88\nC = 2\n') | ||
|
||
with utils.with_cookiejar(utils.get_default_session()): | ||
url = 'https://community.topcoder.com/longcontest/?module=ViewProblemStatement&rd=17092&pm=14853' | ||
tid = 33796324 | ||
problem = TopcoderLongContestProblem.from_url(url) | ||
self.assertEqual(problem.download_system_test(tid), """\ | ||
Seed = 2917103922548 | ||
|
||
Coins: 5372 | ||
Max Time: 2988 | ||
Note Time: 5 | ||
Num Machines: 3 | ||
|
||
Machine 0... | ||
Wheel 0: ACEEDEDBDGBADCDFGD | ||
Wheel 1: GGFEFBFDFFDEECFEAG | ||
Wheel 2: EFCCCAADBDGEGBDCDD | ||
Expected payout rate: 1.5775034293552812 | ||
|
||
Machine 1... | ||
Wheel 0: CDFFDEEEAGGGGGFGGBEFCCFFFD | ||
Wheel 1: EDCGBGFBBCCGGFGDFBFECGGEFC | ||
Wheel 2: GEDECEGFDCGDGGCDDCEDGBGEBG | ||
Expected payout rate: 0.7345243513882568 | ||
|
||
Machine 2... | ||
Wheel 0: ABEEDDDCGBG | ||
Wheel 1: EDEEDADGEAF | ||
Wheel 2: EBEGEFEGEBF | ||
Expected payout rate: 0.6160781367392938 | ||
|
||
""") |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
この(or '')ってなんでしょう?int('')だと例外発生します。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mypy を黙らせるための処理です。例外はむしろ発生するのが適切です。
ちょっと上で次のようにコメントしてるのと同じものです。
選択肢はいくつかありますが、まず
# type: ignore
を付けると行全体が無効化されてしまうのでだめ、次には長すぎてこれもだめ。
次のような関数を定義することもできますが、
これを定義するのと次のようにコメントで示すのはあまり差がないと思ったのですが、そうではなかったですか?
https://github.com/kmyk/online-judge-tools/blob/1b68404eb89cc0b7d80cd1ce1f19f7348cf0187d/onlinejudge/service/topcoder.py#L311