Esempio n. 1
0
def test_test_thread(path: str,
                     thread_num: int,
                     is_save_intermediate_file: bool = False) -> None:
    # 有bug,废弃
    Log(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
    Log("开始测试", path, "的数据")
    exe = ExecuteCode(is_save_intermediate_file=is_save_intermediate_file)
    exe_res, compile_succ = [], 0
    for root, dirs, files in os.walk(path):
        exe_res, compile_succ = exe.execute_code_thread(
            PathFunc.to_linux(path), files, thread_num)
        break
    Log("编译成功数量:", compile_succ, "/", len(files))

    with open("build/execute_info", "wb") as f:
        pickle.dump(exe_res, f)

    g = GenerateAns.GenerateAns("ans.csvc", "sample_submission.csv")
    while True:
        t = g.get()
        if t is None:
            break
        g.add(1 if compare_test(exe_res[t[0]], exe_res[t[1]]) else 0)

    Log(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
Esempio n. 2
0
def test_train_in_one_dir(path: str,
                          test_num: int = -1,
                          is_save_intermediate_file=False) -> None:
    exe_res = []
    exe = ExecuteCode(is_save_intermediate_file=is_save_intermediate_file)
    Log("开始测试", path, "的数据")
    count = 0
    for root, dirs, files in os.walk(path):
        for name in files:
            if count == test_num:
                break
            count += 1
            Log("开始编译", name)
            p = PathFunc.join(PathFunc.to_linux(path), name)
            exe_res.append({"res": exe.execute_code(p), "name": name})
        break

    Log("开始比较输出")
    length = len(exe_res)
    for i in range(length):
        for j in range(i + 1, length):
            if not compare_test(exe_res[i]["res"], exe_res[j]["res"]):
                l1, l2 = exe_res[i], exe_res[j]
                print("文件", exe_res[i]["name"], "和", exe_res[j]["name"],
                      "结果不一致")
                continue
Esempio n. 3
0
def test_test(path: str, is_save_intermediate_file: bool = False) -> None:
    Log("开始测试", path, "的数据")
    exe_res, compile_succ = dict(), 0
    exe = ExecuteCode(is_save_intermediate_file=is_save_intermediate_file)
    for root, dirs, files in os.walk(path):
        total_num, cur_num = len(files), 1
        for name in files:
            Log("开始编译", name, ":[", str(cur_num), "/", str(total_num), "]")
            cur_num += 1
            p = PathFunc.join(PathFunc.to_linux(path), name)
            exe_res[name.split(".")[0]], cs = exe.execute_code(p)
            compile_succ += cs
        break
        Log("编译成功数量:", compile_succ, "/", len(files))

    with open("../build/execute_info", "wb") as f:
        pickle.dump(exe_res, f)

    with open("../build/execute_info", "rb") as f:
        exe_res = pickle.load(f)

    g = GenerateAns.GenerateAns("../ans.csv", "../sample_submission.csv")
    while True:
        t = g.get()
        if t is None:
            break
        g.add(1 if compare_test(exe_res[t[0]], exe_res[t[1]]) else 0)
def use_exe_save_and_analysis_str_and_csv(
        save_path: str, compared_csv_path: str, csv_name: str,
        model_path: str, test_dir_path: str,
        test_len: int, word_len: int, thresh_num: float
) -> None:
    """
    用lstm生成的答案的csv文件来生成
    """
    with open(save_path, "rb") as f:
        exe_res = pickle.load(f)
    predict_by_network = PredictByNetwork(model_path, test_dir_path,
                                          test_len, word_len, thresh_num)
    g = GenerateAns(csv_name, "sample_submission.csv")
    compared_csv = GenerateAns("", compared_csv_path)
    while True:
        t = g.get()
        compared_csv.get()
        if t is None:
            break
        b1 = compare_test(exe_res[t[0]], exe_res[t[1]])
        b2 = analysis_str(t[0], t[1])
        b3 = ((judge(exe_res[t[0]][0], exe_res[t[1]][0]) and exe_res[t[0]][0].result != -1)
               or (judge(exe_res[t[0]][1], exe_res[t[1]][1]) and exe_res[t[1]][0].result != -1))\
             and compared_csv.get_cur_value() == 1
        p = 1 if b1 or b2 or b3 else 0
        if not b1 and not b2:
            print("hehehe")
        g.add(p)
Esempio n. 5
0
def test_train_random_from_same_dir(dir_path: str,
                                    test_num: int,
                                    is_save_intermediate_file: bool = False):
    dir_list = os.listdir(dir_path)
    dir_list_len = len(dir_list)
    dir_file = []
    for name in dir_list:
        dir_file_list = os.listdir(os.path.join(dir_path, name))
        dir_file.append([name, len(dir_file_list), dir_file_list])

    exe = ExecuteCode(is_save_intermediate_file=is_save_intermediate_file)
    is_same_num, succ_num = 0, 0
    for _ in range(test_num):
        i = random.randint(0, dir_list_len - 1)
        j1 = random.randint(0, dir_file[i][1] - 1)
        j2 = random.randint(0, dir_file[i][1] - 1)
        Log("开始比较 ", dir_file[i][0], " 的 ", dir_file[i][2][j1], " 和 ",
            dir_file[i][2][j2])
        p1 = PathFunc.join(dir_path, dir_file[i][0], dir_file[i][2][j1])
        p2 = PathFunc.join(dir_path, dir_file[i][0], dir_file[i][2][j2])
        ret_list1, _ = exe.execute_code(p1)
        ret_list2, _ = exe.execute_code(p2)
        if not compare_test(ret_list1, ret_list2):
            GLog("文件不相同")
            for r1, r2 in zip(ret_list1, ret_list2):
                GLog(r1, r2)
            if sum([1 if x.result == 0 else 0 for x in ret_list1]) != len(ret_list1) \
                or sum([1 if x.result == 0 else 0 for x in ret_list2]) != len(ret_list2):
                print("diff")
            else:
                succ_num += 1
        else:
            is_same_num += 1
            succ_num += 1
    return is_same_num, succ_num
def use_exe_save(save_path: str, csv_name: str) -> None:
    with open(save_path, "rb") as f:
        exe_res = pickle.load(f)

    g = GenerateAns(csv_name, "sample_submission.csv")
    while True:
        t = g.get()
        if t is None:
            break
        g.add(1 if compare_test(exe_res[t[0]], exe_res[t[1]]) else 0)
def use_exe_save_and_analysis_str(save_path: str, csv_name: str) -> None:
    """
    有点点效果,提升到了0.74
    """
    with open(save_path, "rb") as f:
        exe_res = pickle.load(f)

    g = GenerateAns(csv_name, "sample_submission.csv")
    while True:
        t = g.get()
        if t is None:
            break
        g.add(1 if compare_test(exe_res[t[0]], exe_res[t[1]]) or analysis_str(t[0], t[1]) else 0)
def use_exe_save_and_analysis_str_and_xgboost(save_path: str, csv_name: str,
                                              test_index_map: str, network_result_path: str) -> None:
    with open(save_path, "rb") as f:
        exe_res = pickle.load(f)
    gcr = GetCompareResult(test_index_map, network_result_path)

    g = GenerateAns(csv_name, "sample_submission.csv")
    while True:
        t = g.get()
        if t is None:
            break
        xgboost_bool = gcr.get(t[0], t[1])
        # xgboost_bool = False
        g.add(1 if compare_test(exe_res[t[0]], exe_res[t[1]]) or analysis_str(t[0], t[1]) or xgboost_bool else 0)
def use_exe_save_and_analysis_str_input_output_loop(save_path: str, csv_name: str) -> None:
    """
    效果不佳,调出的最好成绩为0.70
    """
    with open(save_path, "rb") as f:
        exe_res = pickle.load(f)

    g = GenerateAns(csv_name, "sample_submission.csv")
    while True:
        t = g.get()
        if t is None:
            break
        g.add(1 if compare_test(exe_res[t[0]], exe_res[t[1]])
                   or analysis_str(t[0], t[1])
                   or analysis_input_output_loop_num(t[0], t[1])
              else 0)
def use_exe_save_and_analysis_str_and_network(
        save_path: str, csv_name: str,
        model_path: str, test_dir_path: str,
        test_len: int, word_len: int, thresh_num: float
) -> None:
    """
    辅助以lstm
    """
    with open(save_path, "rb") as f:
        exe_res = pickle.load(f)
    predict_by_network = PredictByNetwork(model_path, test_dir_path,
                                          test_len, word_len, thresh_num)
    g = GenerateAns(csv_name, "sample_submission.csv")
    while True:
        t = g.get()
        if t is None:
            break
        g.add(1 if compare_test(exe_res[t[0]], exe_res[t[1]])
                   or analysis_str(t[0], t[1])
                   or predict_by_network.predict(t[0], t[1])
              else 0)