def test_key_is_unique(fs): contents = [ '0650000', '1-fidles|FLAG_1', '1-fidles|FLAG_1', '1-fidles|FLAG_1' ] fs.create_file('/foo', contents='\n'.join(contents)) with pytest.raises(KeyError): main('/foo', [])
def test_multiple_ansfile(fs, capsys): i1 = [ '0650000', 'foo|F1', 'bar|F4' ] i2 = [ '0650000', 'foo|F3', 'bar|F4' ] a1 = [ 'foo|F1|20', 'bar|F2|30' ] a2 = [ 'foo|F3|20', 'bar|F4|30' ] fs.create_file('/a1', contents='\n'.join(a1)) fs.create_file('/a2', contents='\n'.join(a2)) fs.create_file('/i1', contents='\n'.join(i1)) fs.create_file('/i2', contents='\n'.join(i2)) main('/i1', ['/a1', '/a2']) captured = capsys.readouterr() assert captured.out == '0650000: 50\n' main('/i2', ['/a1', '/a2']) captured = capsys.readouterr() assert captured.out == '0650000: 50\n'
def main(): if os.path.exists("config.yml"): with open("config.yml", "r", encoding="utf-8") as cfg: cy = yaml.load(cfg) if cy["status"]["urp_code"]: account = cy["user"]["account"] password = cy["user"]["password"] else: account = input("请输入你的学号:") password = input("请输入你的密码:") cy["user"]["account"] = account cy["user"]["password"] = password stu = student.Student(account, password) response_status = stu.login() if not response_status: cy["status"]["urp_code"] = 0 return 0 else: print("登录成功!") cy["status"]["urp_code"] = 1 while(True): pt = prettytable.PrettyTable(["操作类型"]) # 设置prettytable靠左对齐 pt.align = "l" pt.add_row(["1、成绩查询"]) pt.add_row(["2、一键评教"]) pt.add_row(["3、四六级查询"]) print(pt) choice = input("请按序号输入你要进行的操作,或者按其他任意键退出程序\r\n# ").strip() if choice.isdigit(): choice = int(choice) if choice == 1: score.main(stu) elif choice == 2: judge.judge_all(stu) elif choice == 3: cet.main(cy) else: print("你选择退出程序,好的,再见。") save_config(cy) return 0 else: print("你选择退出程序,好的,再见。") save_config(cy) return 0 else: print("配置文件已丢失,正在重新生成···") init_config() print("配置文件重新生成成功,请重新运行本程序进行登录")
def test_filename(): with pytest.raises(ValueError): main('', []) with pytest.raises(ValueError): main('foo.txt', []) with pytest.raises(ValueError): main('foo.', [])
def main(args): output_eval = args["output_eval"] output_score = args["output_score"] if args["algo"]: module_name = args["input"] score_args = { "module": module_name, "params": args["params"], "output": output_score, "align": args["align"] } scores_file_name = score.main(score_args) else: scores_file_name = args["input"] result = evaluate_from_file(scores_file_name) dump(output_eval, result)
bestAcc = -100.0 learnedNetworkFiles = sorted(learnedNetworkFiles) for learnedNetworkFile in learnedNetworkFiles: #-pre-process if os.path.exists("LSTM.rnnw"): os.remove("LSTM.rnnw") shutil.copy(learnedNetworkFile, "LSTM.rnnw") #-evaluate LSTMWithBOW.main([ '--dataset', 'dstc4_dev', '--dataroot', 'data', '--trackfile', 'baseline_dev.json', '--ontology', 'scripts/config/ontology_dstc4.json' ]) score.main([ '--dataset', 'dstc4_dev', '--dataroot', 'data', '--trackfile', 'baseline_dev.json', '--scorefile', 'baseline_dev.score.csv', '--ontology', 'scripts/config/ontology_dstc4.json' ]) #-write result res.write(learnedNetworkFile + ":" + "\n") for line in open("baseline_dev.score.csv", "r"): #Accuracy m1 = re.search( "all, all, 1, acc,", line ) #Only see schedule 1 (Consider all turn in evaluation) if m1 != None: m2 = re.search("([0-9]|\.)+$", line) res.write("-" + line) if bestAcc < float(m2.group(0)): bestAcc = float(m2.group(0)) bestAccNet = learnedNetworkFile
learnedNetworkFiles=glob.glob("*.rnnw") if "LSTM.rnnw" in learnedNetworkFiles: learnedNetworkFiles.remove("LSTM.rnnw") bestf1Net=None bestf1=-100.0 bestAccNet=None bestAcc=-100.0 learnedNetworkFiles=sorted(learnedNetworkFiles) for learnedNetworkFile in learnedNetworkFiles: #-pre-process if os.path.exists("LSTM.rnnw"): os.remove("LSTM.rnnw") shutil.copy(learnedNetworkFile, "LSTM.rnnw") #-evaluate LSTMWithBOW.main(['--dataset', 'dstc4_dev', '--dataroot', 'data', '--trackfile', 'baseline_dev.json', '--ontology', 'scripts/config/ontology_dstc4.json']) score.main(['--dataset', 'dstc4_dev', '--dataroot', 'data', '--trackfile', 'baseline_dev.json', '--scorefile', 'baseline_dev.score.csv', '--ontology', 'scripts/config/ontology_dstc4.json']) #-write result res.write(learnedNetworkFile+":"+"\n") for line in open("baseline_dev.score.csv","r"): #Accuracy m1=re.search("all, all, 1, acc,",line)#Only see schedule 1 (Consider all turn in evaluation) if m1 != None: m2=re.search("([0-9]|\.)+$",line) res.write("-"+line) if bestAcc < float(m2.group(0)): bestAcc=float(m2.group(0)) bestAccNet=learnedNetworkFile #L1 m1=re.search("all, all, 1, f1,",line)#Only see schedule 1 (Consider all turn in evaluation) if m1 != None: m2=re.search("([0-9]|\.)+$",line)
def score_labeled_data(main_config_fpath): '''Score ConvNet precision and accuracy on labeled data''' score.main(main_config_fpath)
def test_student_id(fs): fs.create_file('/foo', contents='06') with pytest.raises(ValueError): main('/foo', [])
def index(request): main() return render(request, "index.html")
def run_script(): loop = asyncio.new_event_loop() thread = threading.Thread(target=loop.run_until_complete(main(loop))) thread.start() thread.join()
def index(): form = MyForm() if form.validate_on_submit(): filename = resumes.save(form.resume.data) return "<h1>" + score.main(filename, form.description.data) + "</h1>" return render_template('index.html', form=form)