From 4bdd8258af7770a898b17f91a996c6aab7e6cc8a Mon Sep 17 00:00:00 2001 From: Kimiyuki Onaka Date: Tue, 12 Mar 2019 15:10:54 +0900 Subject: [PATCH 1/3] #359: remove code-statistics subcommand --- .../command/code_statistics.py | 47 ------------------- onlinejudge/_implementation/main.py | 8 ---- readme.md | 1 - tests/command_code_statistics.py | 24 ---------- 4 files changed, 80 deletions(-) delete mode 100644 onlinejudge/_implementation/command/code_statistics.py delete mode 100644 tests/command_code_statistics.py diff --git a/onlinejudge/_implementation/command/code_statistics.py b/onlinejudge/_implementation/command/code_statistics.py deleted file mode 100644 index 996b946a..00000000 --- a/onlinejudge/_implementation/command/code_statistics.py +++ /dev/null @@ -1,47 +0,0 @@ -# Python Version: 3.x -import contextlib -import os -import os.path -import string -import subprocess -from typing import * - -import onlinejudge -import onlinejudge._implementation.logging as log -import onlinejudge._implementation.utils as utils - -if TYPE_CHECKING: - import argparse - - -def get_char_class(c: int) -> str: - assert 0 <= c < 256 - if chr(c) in string.ascii_letters + string.digits: - return 'alnum' - elif chr(c) in ' \t\n': - return 'whitespace' - elif 32 < c < 127: - return 'symbol' - else: - return 'binary' - - -def get_statistics(s: bytes) -> Dict[str, int]: - stat = { - 'binary': 0, - 'alnum': 0, - 'symbol': 0, - 'whitespace': 0, - } - for c in s: - stat[get_char_class(c)] += 1 - return stat - - -def code_statistics(args: 'argparse.Namespace') -> None: - with open(args.file, 'rb') as fh: - code = fh.read() - stat = get_statistics(code) - stat['size'] = len(code) - for key in ('size', 'binary', 'alnum', 'symbol', 'whitespace'): - log.info('%s = %d', key, stat[key]) diff --git a/onlinejudge/_implementation/main.py b/onlinejudge/_implementation/main.py index 5b95fd90..af2a3856 100644 --- a/onlinejudge/_implementation/main.py +++ b/onlinejudge/_implementation/main.py @@ -10,7 +10,6 @@ import onlinejudge.__about__ as version import onlinejudge._implementation.logging as log import onlinejudge._implementation.utils as utils -from onlinejudge._implementation.command.code_statistics import code_statistics from onlinejudge._implementation.command.download import download from onlinejudge._implementation.command.generate_output import generate_output from onlinejudge._implementation.command.get_standings import get_standings @@ -230,11 +229,6 @@ def get_parser() -> argparse.ArgumentParser: subparser.add_argument('-c', '--command', default='./a.out', help='your solution to be tested. (default: "./a.out")') subparser.add_argument('judge', help='judge program using standard I/O') - # code statistics - subparser = subparsers.add_parser('code-statistics', aliases=['c/s'], help='print the code statistics used in Anarchy Golf', formatter_class=argparse.RawTextHelpFormatter, epilog='''\ -''') - subparser.add_argument('file') - # get standings subparser = subparsers.add_parser('get-standings', help='get and print the standings', formatter_class=argparse.RawTextHelpFormatter, epilog='''\ supported services: @@ -268,8 +262,6 @@ def run_program(args: argparse.Namespace, parser: argparse.ArgumentParser) -> No generate_output(args) elif args.subcommand in ['split-input', 's/i']: split_input(args) - elif args.subcommand in ['code-statistics', 'c/s']: - code_statistics(args) elif args.subcommand == 'get-standings': get_standings(args) else: diff --git a/readme.md b/readme.md index 6ab29c64..fb82fce8 100644 --- a/readme.md +++ b/readme.md @@ -52,7 +52,6 @@ Tools for online judge services. Downloading sample cases, Testing/Submitting yo - Test your solution for reactive problem - Generate output files from input and reference implementation - Split an input file with many cases to files -- Print the code statistics used in Anarchy Golf ## How to install diff --git a/tests/command_code_statistics.py b/tests/command_code_statistics.py deleted file mode 100644 index 4810d183..00000000 --- a/tests/command_code_statistics.py +++ /dev/null @@ -1,24 +0,0 @@ -import unittest - -from onlinejudge._implementation.command.code_statistics import get_statistics - - -class CodeStatisticsTest(unittest.TestCase): - def test_get_statistics_1(self): - # http://golf.shinh.org/reveal.rb?Turn+a+1d+array+into+a+5d+array/mitchs+%28cheat%29_1465127634&bf - code = b'''<-],<[->>[.<]>>>.,+]\x00 ;\x01e\x0b''' - stat = get_statistics(code) - self.assertEqual(stat['binary'], 3) - self.assertEqual(stat['alnum'], 1) - self.assertEqual(stat['symbol'], 21) - - def test_get_statistics_2(self): - # http://golf.shinh.org/reveal.rb?DozzFizzBuzz/%2520_1434433980 - code = b'''\ -\x01oiuea1.>g1+00p25*,>:00g\\2g%#v_:6%1g,:5%1v -DFBMPQ@_^#`"c"g $_^#`"\x18": +1<,,"zz" ,g0+< -\x02\x03\x05\x07\x0b\x0d\x11\x13\x17\x1d\x1f%)+/5;=CGIOSYa''' - stat = get_statistics(code) - self.assertEqual(stat['binary'], 13) - self.assertEqual(stat['alnum'], 46) - self.assertEqual(stat['symbol'], 46) From 4934c54e51ac3178771a9d47a8f01d879d22046f Mon Sep 17 00:00:00 2001 From: Kimiyuki Onaka Date: Tue, 12 Mar 2019 15:14:53 +0900 Subject: [PATCH 2/3] #359: mark some subcommands experimental --- onlinejudge/_implementation/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/onlinejudge/_implementation/main.py b/onlinejudge/_implementation/main.py index af2a3856..fa6dbb56 100644 --- a/onlinejudge/_implementation/main.py +++ b/onlinejudge/_implementation/main.py @@ -164,7 +164,7 @@ def get_parser() -> argparse.ArgumentParser: subparser.add_argument('--ignore-backup', action='store_true', help='ignore backup files and hidden files (i.e. files like "*~", "\\#*\\#" and ".*") (default)') # split input - subparser = subparsers.add_parser('split-input', aliases=['s/i'], help='split a input file which contains many cases, using your implementation', formatter_class=argparse.RawTextHelpFormatter, epilog='''\ + subparser = subparsers.add_parser('split-input', help='split a input file which contains many cases, using your implementation (experimental)', formatter_class=argparse.RawTextHelpFormatter, epilog='''\ format string for --output: %i index @@ -230,7 +230,7 @@ def get_parser() -> argparse.ArgumentParser: subparser.add_argument('judge', help='judge program using standard I/O') # get standings - subparser = subparsers.add_parser('get-standings', help='get and print the standings', formatter_class=argparse.RawTextHelpFormatter, epilog='''\ + subparser = subparsers.add_parser('get-standings', help='get and print the standings (experimental)', formatter_class=argparse.RawTextHelpFormatter, epilog='''\ supported services: Topcoder (Marathon Match) ''') @@ -260,7 +260,7 @@ def run_program(args: argparse.Namespace, parser: argparse.ArgumentParser) -> No test_reactive(args) elif args.subcommand in ['generate-output', 'g/o']: generate_output(args) - elif args.subcommand in ['split-input', 's/i']: + elif args.subcommand in 'split-input': split_input(args) elif args.subcommand == 'get-standings': get_standings(args) From 750831b8fe3faa11bc30a60212774a7c4becbad4 Mon Sep 17 00:00:00 2001 From: fukatani Date: Wed, 13 Mar 2019 17:46:23 +0900 Subject: [PATCH 3/3] replace a wrong `in` with `==` as suggested Co-Authored-By: kmyk --- onlinejudge/_implementation/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/onlinejudge/_implementation/main.py b/onlinejudge/_implementation/main.py index fa6dbb56..1c266ef3 100644 --- a/onlinejudge/_implementation/main.py +++ b/onlinejudge/_implementation/main.py @@ -260,7 +260,7 @@ def run_program(args: argparse.Namespace, parser: argparse.ArgumentParser) -> No test_reactive(args) elif args.subcommand in ['generate-output', 'g/o']: generate_output(args) - elif args.subcommand in 'split-input': + elif args.subcommand == 'split-input': split_input(args) elif args.subcommand == 'get-standings': get_standings(args)