示例#1
0
def Submit(user, pd, pro, F):
    "user, password, problem, file(all Entry), return state list"
    user = get_entry_info(user)
    pd = get_entry_info(pd)
    pro = get_entry_info(pro)
    F = get_entry_info(F)

    # print(user, pd, pro, F)

    log_para = {"Password": pd, "User": user}
    src = get_code(F)
    if src == "can not find the file":
        return "can not find the file"
    submit_para = {
        'PID': pro,
        "language": "3",  #c++ 1 G++ 3
        "Source": src
    }
    with open(".\\language.txt", "r") as F:
        submit_para["language"] = int(F.readline())
    sta_list = main.log_submit(log_para, submit_para)
    if sta_list == main.SubmitError:
        print(main.SubmitError)

    # for each_sta in sta_list:
    #     print(each_sta[0], ": ", each_sta[1])
    # return
    return sta_list
def submit(s: requests.Session, CID, pro_name_list, user, pd, e_pro, e_file):
    "post请求出错,换selenium模拟"
    pro = str(e_pro.get())
    F = str(e_file.get())

    url = "http://noj.cn/practise.asp"
    driver = webdriver.Ie(executable_path='.\IEDriverServer.exe')
    driver.get(url)
    sel = driver.find_element_by_name("CID")
    Select(sel).select_by_value(str(CID))
    settext(user)
    driver.find_element_by_xpath("//input[@name='User']").send_keys(
        Keys.CONTROL, 'v')
    # elem_user = driver.find_element_by_xpath("//input[@name='User']")
    # elem_user.send_keys(user)
    settext(pd)
    driver.find_element_by_xpath("//input[@name='Password']").send_keys(
        Keys.CONTROL, 'v')
    elem_pd = driver.find_element_by_xpath("//input[@name='Password']")
    # elem_pd.send_keys(pd)
    elem_pd.send_keys(Keys.ENTER)

    name = ''
    for each in pro_name_list:
        if each[0] == pro:
            name = each[2]
            break
    xpath_para = "//*[text()=" + "'" + name + "'" + "]"
    driver.find_element_by_xpath(xpath_para).send_keys(Keys.ENTER)
    driver.find_element_by_xpath("//input[@value='提交']").send_keys(Keys.ENTER)
    sel = driver.find_element_by_name("language")
    lan = ""
    with open(".\language.txt", "r") as t_file:
        lan = int(t_file.readline())
    lan = str(lan)
    Select(sel).select_by_value(lan)
    src = get_code(F)
    settext(src)
    driver.find_element_by_name("Source").send_keys(Keys.CONTROL, 'v')
    # src = "3esdgdssgfsdfsdf"
    #慢
    # driver.find_element_by_name("Source").send_keys(src)
    # js = 'document.getElementById("Source").value="'+str(src)+'"'
    # driver.execute_script(js)

    driver.find_element_by_name("SB").send_keys(Keys.ENTER)

    try:
        dialog_box = driver.switch_to.alert
        dialog_box.accept()
        dialog_box = driver.switch_to.alert
        dialog_box.accept()
        #get state
    except selenium.common.exceptions.NoAlertPresentException:
        pass
    finally:
        driver.close()
        sta_list = get_submit_sta(user)
        show(sta_list)
    ''' 
示例#3
0
def producer(q, dblock):
    """循环扫描数据库,将任务添加到队列"""
    # print("start")
    while True:
        if q.full():
            q.join()
        dblock.acquire()
        data = run_sql('select * from submission where message is NULL')
        # print(data)
        time.sleep(0.5)  # 延时1秒,防止因速度太快不能获取代码
        dblock.release()
        for i in data:
            id, language, content, message, user_id, question_id = i
            dblock.acquire()
            # print('1 put')
            ret = get_code(id, question_id, language, content)
            dblock.release()
            # print(ret)
            if ret is False:
                # 防止因速度太快不能获取代码
                # print('2 put')
                time.sleep(1)
                dblock.acquire()
                ret = get_code(id, question_id, language, content)
                dblock.release()
            if ret is False:
                dblock.acquire()
                # 标记题目写入处理的结果信息
                run_sql(
                    "update submission set message = 'unknown error' where id = %s"
                    % id)
                dblock.release()
                clean_work_dir(id)
                continue
            run_sql("update submission set message = 'success' where id = %s" %
                    id)
            task = {
                "id": id,
                "user_id": user_id,
                "question_id": question_id,
                "content": content,
                "language": language,
            }
            q.put(task)
        time.sleep(0.5)
示例#4
0
def producer(q, dblock):
    """循环扫描数据库,将任务添加到队列"""
    # print('start produce')
    while True:
        if q.full():
            q.join()
        dblock.acquire()
        data = get_message()
        # print('-----')
        # print(data)
        # print('-----')
        time.sleep(0.5)  # 延时1秒,防止因速度太快不能获取代码
        dblock.release()
        for i in data:
            id, language, content, message, user_id, question_id = i
            dblock.acquire()
            ret = get_code(id, question_id, language, content)
            dblock.release()
            if ret is False:
                # 防止因速度太快不能获取代码
                time.sleep(1)
                dblock.acquire()
                ret = get_code(id, question_id, language, content)
                dblock.release()
            if ret is False:
                dblock.acquire()
                # 标记题目写入处理的结果信息'unknown error'写入数据库
                # run_sql("update submission set message = 'unknown error' where id = %s" % id)
                update_message(id, 'unknown error')
                dblock.release()
                clean_work_dir(id)
                continue
            # 标记题目写入处理的结果信息'success'写入数据库
            # run_sql("update submission set message = 'success' where id = %s" % id)
            update_message(id, "'The problem is being dealt with...'")
            # print('upmes2suc')
            task = {
                "id": id,
                "user_id": user_id,
                "question_id": question_id,
                "content": content,
                "language": language,
            }
            q.put(task)
        time.sleep(3)
示例#5
0
def put_task_into_queue():
    '''循环扫描数据库,将任务添加到队列'''
    while True:
        protect.q.join()  # 阻塞程序,直到队列里面的任务全部完成
        sql = "select submit_id, problem_id, user_id, contest_id, `language` from django_web_submitproblem where result = 0"
        data = db.run_sql(sql)
        time.sleep(0.5)  # 延时0.5秒,防止因速度太快不能获取代码
        for i in data:
            submit_id, problem_id, user_id, contest_id, language = i
            protect.dblock.acquire()
            ret = get_code.get_code(submit_id, problem_id, language)
            protect.dblock.release()
            if ret is False:  # 生成文件失败 再次尝试
                # 防止因速度太快不能获取代码
                logging.error("首次生成文件失败 by %s" %
                              threading.current_thread().name)
                time.sleep(0.5)
                protect.dblock.acquire()
                ret = get_code.get_code(submit_id, problem_id, language)
                protect.dblock.release()
            if ret is False:  # 生成文件依旧失败
                protect.dblock.acquire()
                logging.error("再次生成文件失败 by %s " %
                              threading.current_thread().name)
                update_solution_status(
                    submit_id, DBData.result_code["System Error"])  # 设置结果为系统错误
                protect.dblock.release()
                deal_data.clean_work_dir(submit_id)  # 清理get_code函数所产生的文件夹及文件
                continue
            logging.info("生成文件成功 by %s " % threading.current_thread().name)
            task = {  # 生成判题任务
                "submit_id": submit_id,
                "problem_id": problem_id,
                "contest_id": contest_id,
                "user_id": user_id,
                "language": language,
            }
            protect.q.put(task)  # 将判题任务添加到判题队列中
            protect.dblock.acquire()
            update_solution_status(submit_id,
                                   DBData.result_code["Judging"])  # 状态结果改成正在判题
            protect.dblock.release()
        time.sleep(0.5)
示例#6
0
def get_code_decode(data_format="channels_last"):
    """
    获取单条图形验证码流和验证码信息,用于测试模型
    :param data_format:     字符串,为‘channels_first’或‘channels_last’,代表图像的通道维位置
                            默认为‘channels_last’,数据应该组织为(128, 128, 3)
    :return:                图像numpy array和标签
    """
    res = get_code()
    img = Image.open(BytesIO(res.content))
    img_array = np.array(img)
    img_array = np.reshape(img_array, (1, 1, 60, 120))
    if data_format == "channels_last":
        img_array = img_array.transpose((0, 2, 3, 1))
    return img_array, res.headers["code"]
示例#7
0
def get_batch_code(batch_size=32, data_format="channels_last"):
    """
    获取指定批次的图像张量和标签张量,用于按批次训练模型
    :param batch_size:      批次大小
    :param data_format:     字符串,为‘channels_first’或‘channels_last’,代表图像的通道维位置
                            默认为‘channels_last’,数据应该组织为(128, 128, 3)
    :return:                形如(batch_size, 60, 120, 1)的图像张量和(batch_size, 40)的标签张量
    """
    x_list = []
    y_list = []
    for batch in range(batch_size):
        res = get_code()
        img = Image.open(BytesIO(res.content))
        label_array = num_encoder(res.headers["code"])
        img_array = np.array(img)
        img_array = np.reshape(img_array, (1, 60, 120))
        if data_format == "channels_last":
            img_array = img_array.transpose((1, 2, 0))
        x_list.append(img_array)
        y_list.append(label_array)
    return np.array(x_list), np.array(y_list)
import csv
from get_code import get_code
from pygal.style import RotateStyle as RS

fert_1_1960 = {}
fert_2_1960 = {}
fert_3_1960 = {}
fert_1_2018 = {}
fert_2_2018 = {}
fert_3_2018 = {}

with open('archives/fertility.csv') as f:
    fert_data = csv.reader(f)
    for i in fert_data:
        country = i[0]
        code = get_code(country)
        if code:
            if i[4]:
                f_60 = float(i[4])
                if f_60 < 3:
                    fert_1_1960[code] = f_60
                elif f_60 < 6:
                    fert_2_1960[code] = f_60
                else:
                    fert_3_1960[code] = f_60
            if i[61]:
                f_18 = float(i[61])
                if f_18 < 2:
                    fert_1_2018[code] = f_18
                elif f_18 < 3:
                    fert_2_2018[code] = f_18