def main(): global ttf_font, font_size, unit import argparse parser = argparse.ArgumentParser(description='NumberLink check and drawing tool') parser.add_argument('-f', '--font', default=ttf_font, help='TrueType font file (default: %(default)s)') parser.add_argument('--font-size', metavar='N', type=int, default=font_size, help='font size (default: %(default)s)') parser.add_argument('--unit', metavar='N', type=int, default=unit, help='unit square size (default: %(default)s)') parser.add_argument('--test', action='store_true', help='test GIF output') parser.add_argument('qfile', metavar='Q-FILE', help='input file (Q-file)') parser.add_argument('afile', metavar='A-FILE', help='target file (A-file)') args = parser.parse_args() ttf_font = args.font font_size = args.font_size unit = args.unit setup_font(ttf_font) if args.test: test() qfile = args.qfile afile = args.afile print(qfile, afile) nlc = NLCheck() q = nlc.read_input_file(qfile) a = nlc.read_target_file(afile) #print("q=",q) #print("a=",a) #a = nlc.clean_a(q, a) # 回答をチェックする nlc.verbose = True judges = nlc.check( q, a ) print("judges = ", judges) # 描画する images = draw(q, a, nlc) bfile = os.path.basename(qfile) bfile = os.path.splitext(bfile)[0] # 拡張子をトル for num, img in enumerate(images): ifile = "%s.%d.gif" % (bfile, num+1) # 層の番号は1から始まる img.save(ifile, 'gif') print(ifile) if 1 < len(images): merge_images(images).save(bfile+'.gif', 'gif')
def main(): qfile, afile = sys.argv[1:] afile = sys.argv[2] print qfile, afile nlc = NLCheck() q = nlc.read_input_file(qfile) a = nlc.read_target_file(afile) #print "q=",q #print "a=",a #a = nlc.clean_a(q, a) # 回答をチェックする nlc.verbose = True judges = nlc.check(q, a) print "judges = ", judges # 描画する images = draw(q, a, nlc) bfile = basename(qfile) bfile = re.sub("\.txt", "", bfile) num = 0 for img in images: ifile = "%s.%d.gif" % (bfile, num) img.writeGif(ifile) print ifile num += 1
def main(): qfile, afile = sys.argv[1:] afile = sys.argv[2] print qfile,afile nlc = NLCheck() q = nlc.read_input_file(qfile) a = nlc.read_target_file(afile) #print "q=",q #print "a=",a #a = nlc.clean_a(q, a) # 回答をチェックする nlc.verbose = True judges = nlc.check( q, a ) print "judges = ", judges # 描画する images = draw(q,a,nlc) bfile = basename(qfile) bfile = re.sub("\.txt", "", bfile) num = 0 for img in images: ifile = "%s.%d.gif" % (bfile, num) img.writeGif(ifile) print ifile num += 1
def solve(num): global project_dir o = NLCheck() output_info = info['output_info'][num] via_to_line = get_via_to_line(info, num) adata = 'SIZE %dX%dX%d\r\n' % info['size'] fail = False cwd = os.getcwd() #--------------------------------------- os.chdir(project_dir) for layer, info2 in sorted(output_info.items()): if layer[0] != 'L' or not layer[1:].isdigit(): continue qfile = info2['ofile'] afile = exec_solver(qfile) #print layer, qfile, afile input_data = o.read_input_file(qfile) target_data = o.read_target_file(afile) target_data2 = o.clean_a(input_data, target_data) judges = o.check(input_data, target_data2) best = best_target(judges) print "judges = ", judges print "best = ", best #print "best target_data = ", target_data2[best[0]] ilayer = int(layer[1:]) # 1,2,… via_linenum = get_via_linenum_mat(info, ilayer, via_to_line) adata += 'LAYER %d\r\n' % ilayer if best[0] is None: fail = True break else: bd = target_data2[best[0]] adata += generate_A_data(bd, info2['map_line_num'], via_linenum) if 0: root, ext = os.path.splitext(afile) gfile = root + '.gif' gif = o.graphic_gif(input_data, [bd], gfile) print "gif = ", gif os.chdir(cwd) #--------------------------------------- if fail: output_info['judges'] = None return None else: # afile: 2016年版ルールの回答ファイルの名前 root, ext = os.path.splitext(os.path.basename(info['convert_q'])) afile = root + ('.%d.A.txt' % num) afile2 = os.path.join(project_dir, afile) with open(afile2, 'w') as fp: fp.write(adata) # 2016年版ルールで回答チェック input_data = o.read_input_file(info['convert_q']) target_data = o.read_target_str(adata) judges = o.check(input_data, target_data) print "afile = ", afile print "judges = ", judges output_info['afile'] = afile output_info['judges'] = judges if judges[0][0]: # 正解が出た gfile = root + ('.%d.A.gif' % num) gfile2 = os.path.join(project_dir, gfile) gif = o.graphic_gif(input_data, target_data, gfile2) print "gif = ", gif return afile
# Aファイルを読み込んで、空白マスの割合を計算する # # # 実行例 ./space.py ../../ADC2015_QA/A/*txt import os, sys, re sys.path.insert(1, '../server') from nlcheck import NLCheck nlc = NLCheck() pat = re.compile('(.*)_A([0-9]+)\.txt') print "user,A,area,zeros,rate" for file in sys.argv[1:]: res = nlc.read_target_file(file) for i in res: y, x = i.shape area = y * x nzeros = len(i[i == 0]) # 値が0の個数 rate = float(nzeros) / (float(area)) f1 = os.path.basename(file) m = pat.match(f1) user = '******' anum = '?' if m is not None: user = m.group(1) anum = m.group(2) print "%s,%d,%d,%d,%f" % (user, int(anum), area, nzeros, rate)
# Aファイルを読み込んで、空白マスの割合を計算する # # # 実行例 ./space.py ../../ADC2015_QA/A/*txt import os, sys, re sys.path.insert(1, '../server') from nlcheck import NLCheck nlc = NLCheck() pat = re.compile('(.*)_A([0-9]+)\.txt') print "user,A,area,zeros,rate" for file in sys.argv[1:]: res = nlc.read_target_file(file) for i in res: y,x = i.shape area = y*x nzeros = len(i[i==0]) # 値が0の個数 rate = float(nzeros) / (float(area)) f1 = os.path.basename(file) m = pat.match(f1) user = '******' anum = '?' if m is not None: user = m.group(1) anum = m.group(2) print "%s,%d,%d,%d,%f" % (user, int(anum), area, nzeros, rate)