#3 2nd for be

오픈
gitea.shuishan 10182100242/new-vsc:master 에서 master 로 3 commits 를 머지하려 합니다
  1. +11
    -3
      be/app.py
  2. +38
    -3
      be/my_check_logic_error.py
  3. +12
    -8
      be/mysubmit.py
  4. +35
    -9
      be/testcase.py

+ 11
- 3
be/app.py 파일 보기

@ -18,7 +18,7 @@ db = pymysql.connect(host='192.168.0.89',
user='root',
password='2020yunjisuan!',
db='shuishan',
charset='utf8')
charset='utf8mb4')
@app.route('/get-problem-items/')
@ -77,8 +77,13 @@ def get_problem_description(_id: str):
def case_test_():
pid: str = request.json.get("pid")
code: str = request.json.get("code")
pid = str(pid)
code = str(code)
with open('wulin.txt', 'w', encoding='utf-8', newline='') as f:
f.write(pid)
f.write(pid+"\n")
f.write(code + "\n")
f.close()
results = testcase.submit_handler(code, pid, 'C')
@ -108,8 +113,11 @@ def check_logic_error():
def submit():
pid: str = request.json.get("pid")
code: str = request.json.get("code")
pid = str(pid)
code = str(code)
with open('wulin2.txt', 'w', encoding='utf-8', newline='') as f:
f.write(pid)
f.write(pid + "\n")
f.write(code + "\n")
f.close()
results = mysubmit.submit_handler(code, pid, 'C')

+ 38
- 3
be/my_check_logic_error.py 파일 보기

@ -1,5 +1,6 @@
from urllib import parse
import requests
import json
# 必须submit/test之后才能checklogic error (test即一次submit)
# 从submit_id.txt中找到submit_id,填入referer
# 从data.c找到代码,编码之后,填入url
@ -34,9 +35,43 @@ def check_logic_error() :
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
response = json.loads(response.text)
# print(response)
data = response['data']
name = data['name']
prob = data['prob']
for i in range(0, len(name)):
if (prob[i] < 0.0001):
prob[i] = '0%'
elif (prob[i] > 0.0001):
prob[i] = prob[i] * 100
prob[i]: str = str(prob[i])[0:4] + '%'
for i in range(0, len(name)):
if (name[i] == "incorrect output format"): name[i] = "输出格式不正确"
if (name[i] == "incorrect loops"): name[i] = "循环不正确"
if (name[i] == "incorrect logic"): name[i] = "逻辑不正确"
if (name[i] == "incorrect branches"): name[i] = "分支选择不正确"
if (name[i] == "incorrect initialization"): name[i] = "初始化不正确"
if (name[i] == "incorrect data types"): name[i] = "数据类型不正确"
if (name[i] == "incorrect data precision"): name[i] = "数据精度不正确"
if (name[i] == "incorrect input variables"): name[i] = "输入变量不正确"
if (name[i] == "no output"): name[i] = "没有输出"
if (name[i] == "incorrect input strings"): name[i] = "输入字符串不正确"
if (name[i] == "incorrect operators"): name[i] = "运算符不正确"
print(name)
checkinfo = list(zip(name, prob))
print(checkinfo)
checkinfo_str = ""
for i in range(0, len(checkinfo)):
checkinfo_str += str(checkinfo[i]) + "\n"
checkinfo_str = checkinfo_str.replace('(', '').replace(')', '').replace(',', '').replace('\'', '')
print(checkinfo_str)
# print(name)
# print(prob)
# print(checkinfo)
with open('check_logic_error.txt', 'w', encoding='utf-8', newline='') as f: # 设置文件对象
f.write(response.text) # 将字符串写入文件中
f.write(checkinfo_str) # 将字符串写入文件中
f.close()
return response.text
return checkinfo_str

+ 12
- 8
be/mysubmit.py 파일 보기

@ -1,7 +1,7 @@
import requests
import re
import time
def submit(payload) :
def submit(payload,pid) :
url = "http://jf.shuishan.net.cn/api/submission"
payload = payload
@ -15,13 +15,13 @@ def submit(payload) :
'Chrome/88.0.4324.104 Safari/537.36',
'Content-Type': 'application/json;charset=UTF-8',
'Origin': 'http://jf.shuishan.net.cn',
'Referer': 'http://jf.shuishan.net.cn/problem/1-1',
'Referer': 'http://jf.shuishan.net.cn/problem/1-' + pid,
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.9',
'Cookie': '_ga=GA1.3.1580759526.1611565238; _gid=GA1.3.412268444.1611565238; csrftoken=6eM4EeOzqLJFt6xfkbSMQD1e89qF28Lgg5aPIbB1k7Hvu6UFVzzb2d1u5lQG37p6; sessionid=0e47tlihcjyqr3oynpx5pq9xpf7jtqml; _gat=1; sessionid=0e47tlihcjyqr3oynpx5pq9xpf7jtqml'
}
response = requests.request("POST", url, headers=headers, data=payload)
response = requests.request("POST", url, headers=headers, data=payload.encode('utf-8').decode('latin1'))
## print(response.text)
@ -44,7 +44,7 @@ def submit(payload) :
'X-CSRFToken': '6eM4EeOzqLJFt6xfkbSMQD1e89qF28Lgg5aPIbB1k7Hvu6UFVzzb2d1u5lQG37p6',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.104 Safari/537.36',
'Content-Type': 'application/json;charset=utf-8',
'Referer': 'http://jf.shuishan.net.cn/problem/1-1',
'Referer': 'http://jf.shuishan.net.cn/problem/1-' + pid,
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.9',
'Cookie': '_ga=GA1.3.1580759526.1611565238; _gid=GA1.3.412268444.1611565238; csrftoken=6eM4EeOzqLJFt6xfkbSMQD1e89qF28Lgg5aPIbB1k7Hvu6UFVzzb2d1u5lQG37p6; sessionid=0e47tlihcjyqr3oynpx5pq9xpf7jtqml; _gat=1; sessionid=0e47tlihcjyqr3oynpx5pq9xpf7jtqml'
@ -52,9 +52,11 @@ def submit(payload) :
#等待judgeserver出结果
time.sleep(0.5)
response = requests.request("GET", url, headers=headers, data=payload)
## print(response.text)
res = response.text
with open('wulin6.txt', 'w', encoding='utf-8', newline='') as f:
f.write(res)
f.close()
result_code = re.findall(r'"result": ([^"]+),',res)
error_code = re.findall(r'"error": ([^"]+),',res)
result_code = result_code[0]
@ -65,7 +67,9 @@ def submit(payload) :
if(error_code != '0' and error_code != "null"):
print("ERROR_CODE")
return "ERROR_CODE"
elif(result_code == '-2'):
print("COMPILE_ERROR")
return "COMPILE_ERROR"
elif(result_code == '0'):
print("ACCEPTED")
return "ACCEPTED"
@ -98,14 +102,14 @@ def submit_handler(code, problem_id, language_type):
file = open('data.c', mode='r', encoding='utf-8', newline='')
code = file.readlines()
file.close()
code = ''.join([i.replace(' ', r'\t').replace('"', r'\"').rstrip() + r'\n' for i in code])
code = ''.join([i.replace('\t', ' ').replace('\\', '\\\\').replace('"', r'\"').rstrip() + r'\n' for i in code])
## print(code)
# payload="{\"problem_id\":1,\"language\":\"C\",\"code\":\"# include <stdio.h>\\nint main()\\n{\\n\\tint a;\\n\\treturn 0;\\n}\"}"
# print(payload)
payload = "{\"problem_id\":" + problem_id + ",\"language\":\"" + language_type + "\",\"code\":\"" + code + "\"}"
## print(payload)
results = submit(payload)
results = submit(payload,problem_id)
return results
# 输入文件名,题号,语言种类

+ 35
- 9
be/testcase.py 파일 보기

@ -1,7 +1,7 @@
import requests
import re
import time
def submit(payload) :
def submit(payload,pid) :
url = "http://jf.shuishan.net.cn/api/submission"
payload = payload
@ -15,17 +15,21 @@ def submit(payload) :
'Chrome/88.0.4324.104 Safari/537.36',
'Content-Type': 'application/json;charset=UTF-8',
'Origin': 'http://jf.shuishan.net.cn',
'Referer': 'http://jf.shuishan.net.cn/problem/1-1',
'Referer': 'http://jf.shuishan.net.cn/problem/1-'+pid,
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.9',
'Cookie': '_ga=GA1.3.1580759526.1611565238; _gid=GA1.3.412268444.1611565238; csrftoken=6eM4EeOzqLJFt6xfkbSMQD1e89qF28Lgg5aPIbB1k7Hvu6UFVzzb2d1u5lQG37p6; sessionid=0e47tlihcjyqr3oynpx5pq9xpf7jtqml; _gat=1; sessionid=0e47tlihcjyqr3oynpx5pq9xpf7jtqml'
}
response = requests.request("POST", url, headers=headers, data=payload)
response = requests.request("POST", url, headers=headers, data=payload.encode('utf-8').decode('latin1'))
## print(response.text)
res = response.text
with open('wulin3.txt', 'w', encoding='utf-8', newline='') as f:
f.write(res)
f.close()
submit_id = re.findall(r'"submission_id": "([^"]+)"',res)
submit_id = submit_id[0]
@ -45,7 +49,7 @@ def submit(payload) :
'X-CSRFToken': '6eM4EeOzqLJFt6xfkbSMQD1e89qF28Lgg5aPIbB1k7Hvu6UFVzzb2d1u5lQG37p6',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.104 Safari/537.36',
'Content-Type': 'application/json;charset=utf-8',
'Referer': 'http://jf.shuishan.net.cn/problem/1-1',
'Referer': 'http://jf.shuishan.net.cn/problem/1-'+pid,
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.9',
'Cookie': '_ga=GA1.3.1580759526.1611565238; _gid=GA1.3.412268444.1611565238; csrftoken=6eM4EeOzqLJFt6xfkbSMQD1e89qF28Lgg5aPIbB1k7Hvu6UFVzzb2d1u5lQG37p6; sessionid=0e47tlihcjyqr3oynpx5pq9xpf7jtqml; _gat=1; sessionid=0e47tlihcjyqr3oynpx5pq9xpf7jtqml'
@ -53,12 +57,16 @@ def submit(payload) :
#等待judgeserver出结果
time.sleep(0.5)
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
# print(response.text)
res = response.text
with open('wulin5.txt', 'w', encoding='utf-8', newline='') as f:
f.write(res)
f.close()
result_code = re.findall(r'"result": ([^"]+),',res)
error_code = re.findall(r'"error": ([^"]+),',res)
result_code = result_code[1]
result_code_compile = result_code[0]
if (len(result_code) >= 2) :
result_code = result_code[1]
error_code = error_code[0]
print(result_code)
print(error_code)
@ -67,6 +75,13 @@ def submit(payload) :
print("ERROR_CODE")
return "ERROR_CODE"
if (result_code_compile == '-2') :
print("COMPILE_ERROR")
return "COMPILE_ERROR"
if(error_code != '0' and error_code != "null"):
print("ERROR_CODE")
return "ERROR_CODE"
elif(result_code == '0'):
print("SUCCESS")
return "SUCCESS"
@ -99,14 +114,25 @@ def submit_handler(code, problem_id, language_type):
file = open('data.c', mode='r', encoding='utf-8', newline='')
code = file.readlines()
file.close()
code = ''.join([i.replace(' ', r'\t').replace('"', r'\"').rstrip() + r'\n' for i in code])
code = ''.join([i.replace("\t"," ").replace('\\', '\\\\').replace('"', r'\"').rstrip() + r'\n' for i in code])
## print(code)
# payload="{\"problem_id\":1,\"language\":\"C\",\"code\":\"# include <stdio.h>\\nint main()\\n{\\n\\tint a;\\n\\treturn 0;\\n}\"}"
# print(payload)
payload = "{\"problem_id\":" + problem_id + ",\"language\":\"" + language_type + "\",\"code\":\"" + code + "\"}"
## print(payload)
with open('wulin4.txt', 'w', encoding='utf-8', newline='') as f:
f.write(payload)
f.close()
results = submit(payload)
# with open('wulin4.txt', 'r', encoding='utf-8', newline='') as f:
# payload=f.read()
#f.close()
#payload = payload.replace("\t","").replace(" ","")
#with open('wulin4.txt', 'w', encoding='utf-8', newline='') as f:
# f.write(payload)
#f.close()
results = submit(payload,problem_id)
return results
# 输入文件名,题号,语言种类

불러오는 중...
취소
저장