Skip to content

Commit 41b90c3

Browse files
Merge pull request kyuridenamida#15 from asi1024/travis
Travis
2 parents d581057 + d1c6ada commit 41b90c3

13 files changed

+92
-61
lines changed

.travis.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
language: python
2+
3+
python:
4+
- "3.3"
5+
- "3.4"
6+
- "3.5"
7+
- "3.6"
8+
9+
install:
10+
- pip install bs4
11+
- pip install flake8 autopep8
12+
13+
script:
14+
- flake8 --ignore=E501
15+
- autopep8 -r . --diff | tee check_autopep8
16+
- test ! -s check_autopep8
17+
- python AtCoderClient.py arc050 --without-login
18+
19+
notifications:
20+
email: false

AtCoderClient.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#!/usr/bin/python3
22

3-
import sys
3+
from multiprocessing import Pool, cpu_count
44
import os
5+
from time import sleep
56

6-
sys.path.append(".")
7-
sys.path.append("core")
8-
from AtCoder import AtCoder
7+
from core.AtCoder import AtCoder
8+
from core.FormatPredictor import format_predictor
99

1010
try:
1111
import AccountInformation
@@ -14,10 +14,6 @@ class AccountInformation:
1414
username = None
1515
password = None
1616

17-
import FormatPredictor
18-
from multiprocessing import Pool, Process, cpu_count
19-
from time import sleep
20-
2117
atcoder = None
2218

2319

@@ -36,7 +32,7 @@ def prepare_procedure(argv):
3632

3733
# 入力形式を解析
3834
try:
39-
result = FormatPredictor.format_predictor(information, samples)
35+
result = format_predictor(information, samples)
4036
if result is None:
4137
raise Exception
4238
except Exception:

benchmark/overall_test.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@
22
# -*- coding: utf-8 -*-
33
import sys
44

5-
sys.path.append("../core")
6-
sys.path.append("..")
7-
from AtCoder import AtCoder
8-
import AccountInformation
9-
import FormatAnalyzer
10-
import FormatPredictor
5+
from core.AtCoder import AtCoder
6+
import core.FormatPredictor as FP
117

128

13-
class NoPatternFoundError(Exception): pass
9+
class NoPatternFoundError(Exception):
10+
pass
1411

1512

1613
if __name__ == "__main__":
@@ -26,7 +23,7 @@ class NoPatternFoundError(Exception): pass
2623
for k, v in plist.items():
2724
try:
2825
informat, samples = atcoder.get_all(v)
29-
result = FormatPredictor.format_predictor(informat, samples)
26+
result = FP.format_predictor(informat, samples)
3027
if result:
3128
pass
3229
else:
@@ -41,4 +38,5 @@ class NoPatternFoundError(Exception): pass
4138
error = str(type(e))[1:-1]
4239

4340
print("|[%s(%s)](%s)|%s|%s|" % (cid, k, v, result_md, error))
44-
print("|[%s(%s)](%s)|%s|%s|" % (cid, k, v, result_md, error), file=sys.stderr)
41+
print("|[%s(%s)](%s)|%s|%s|" %
42+
(cid, k, v, result_md, error), file=sys.stderr)

core/AtCoder.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from utils import normalized, pure_japanese_text
1+
from core.utils import normalized, pure_japanese_text
22
import getpass
33
import re
44
import urllib.request
@@ -89,7 +89,8 @@ def detection_algorithm1():
8989
h3tag = tag.find('h3')
9090
if h3tag is None:
9191
continue
92-
section_title = pure_japanese_text(tag.find('h3').get_text()) # 何かいくつかの問題のh3タグ内に変な特殊文字が混じっていてやばい
92+
# 何かいくつかの問題のh3タグ内に変な特殊文字が混じっていてやばい
93+
section_title = pure_japanese_text(tag.find('h3').get_text())
9394

9495
if section_title.startswith("入力例"):
9596
input_tags.append(tag.find('pre'))
@@ -144,7 +145,8 @@ def get_all_contestids(self):
144145
previous_list = []
145146
page_num = 1
146147
while True:
147-
req = self.opener.open("https://atcoder.jp/contest/archive?p={}&lang=ja".format(page_num))
148+
req = self.opener.open(
149+
"https://atcoder.jp/contest/archive?p={}&lang=ja".format(page_num))
148150
soup = BeautifulSoup(req, "html.parser")
149151
text = str(soup)
150152
url_re = re.compile(

core/Calculator.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ def parse_to_calc_node(formula):
178178
raise CalcParseError
179179
return res
180180

181+
181182
if __name__ == '__main__':
182183

183184
print(CalcNode("N-1-1+1000*N*N").evaluate({"N": 10}))

core/FormatAnalyzer.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import copy
2-
from Calculator import CalcNode
2+
from core.Calculator import CalcNode
33
from collections import OrderedDict
4-
from utils import is_int, is_float, fixed_variable_name
5-
import re
4+
from core.utils import is_int, is_float, fixed_variable_name
65

76

87
class TypesUnmatchedError(Exception):
@@ -38,8 +37,8 @@ def reflesh_min(self, v):
3837
def reflesh_max(self, v):
3938
if v.isdigit():
4039
if self.max_index is None or (
41-
self.max_index.get_all_varnames() == [] and self.max_index.evaluate() < CalcNode(
42-
v).evaluate()):
40+
self.max_index.get_all_varnames() == [] and self.max_index.evaluate() < CalcNode(
41+
v).evaluate()):
4342
self.max_index = CalcNode(v)
4443
else:
4544
self.max_index = CalcNode(v)

core/FormatPredictor.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import FormatAnalyzer
2-
import FormatTokenizer
3-
from utils import is_ascii, is_noise
4-
from utils import fixed_variable_name, divide_consecutive_vars, normalize_index
1+
from core.FormatAnalyzer import format_analyse
2+
from core.FormatTokenizer import get_all_format_probabilities
3+
from core.utils import is_ascii, is_noise
4+
from core.utils import divide_consecutive_vars, normalize_index
55

66

77
class FormatPredictResult:
@@ -19,11 +19,11 @@ def format_predictor(format, samples):
1919

2020
tokens = [x for x in format.split(
2121
" ") if x != "" and is_ascii(x) and not is_noise(x)]
22-
tokenize_result = FormatTokenizer.get_all_format_probabilities(tokens)
22+
tokenize_result = get_all_format_probabilities(tokens)
2323

2424
for to_1d_flag in [False, True]:
2525
for candidate_format in tokenize_result:
26-
rootnode, varinfo = FormatAnalyzer.format_analyse(
26+
rootnode, varinfo = format_analyse(
2727
candidate_format, to_1d_flag)
2828
try:
2929
current_dic = {}

core/FormatTokenizer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import copy
2-
from Calculator import CalcNode, CalcParseError
2+
from core.Calculator import CalcNode, CalcParseError
33

4-
from utils import fixed_variable_name
4+
from core.utils import fixed_variable_name
55

66

77
def deviding_pattern(text, variables):
@@ -42,7 +42,7 @@ def is_description(index):
4242
flag = False
4343
try:
4444
for subvar in CalcNode(index).get_all_varnames():
45-
if not subvar in variables:
45+
if subvar not in variables:
4646
flag = False
4747
except CalcParseError:
4848
flag = False

core/TemplateEngine.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
import string, re
1+
import string
2+
import re
3+
4+
25
def substitute(s, reps):
36
# http://stackoverflow.com/questions/36739667/python-templates-for-generating-python-code-with-proper-multiline-indentation
47
t = string.Template(s)
58
i = 0
69
cr = {} # prepare to iterate through the pattern string
710
while True:
811
# search for next replaceable token and its prefix
9-
m =re.search(r'^(.*?)\$\{(.*?)\}', s[i:], re.MULTILINE)
12+
m = re.search(r'^(.*?)\$\{(.*?)\}', s[i:], re.MULTILINE)
1013

11-
if m is None: break # no more : finished
14+
if m is None:
15+
break # no more : finished
1216
# the list is joined using the prefix if it contains only blanks
1317
sep = ('\n' + m.group(1)) if m.group(1).strip() == '' else '\n'
1418

@@ -20,7 +24,7 @@ def substitute(s, reps):
2024
def render(s, **args):
2125
new_args = {}
2226

23-
for k,v in args.items():
27+
for k, v in args.items():
2428
new_args[k] = v if isinstance(v, list) else [v]
2529

26-
return substitute(s,new_args)
30+
return substitute(s, new_args)

core/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def is_japanese(ch):
99
name = unicodedata.name(ch)
1010
if "CJK UNIFIED" in name or "HIRAGANA" in name or "KATAKANA" in name:
1111
return True
12-
except:
12+
except ValueError:
1313
pass
1414
return False
1515

0 commit comments

Comments
 (0)