|
|
@ -4,16 +4,19 @@ from flask import request |
|
|
|
import json |
|
|
|
import pymysql |
|
|
|
import sys |
|
|
|
import mysubmit |
|
|
|
import testcase |
|
|
|
import my_check_logic_error |
|
|
|
sys.path.append('../') |
|
|
|
from PIPE.main import PIPEModel |
|
|
|
|
|
|
|
|
|
|
|
app = Flask(__name__) |
|
|
|
app.config['JSON_AS_ASCII'] = False |
|
|
|
db = pymysql.connect(host='127.0.0.1', |
|
|
|
db = pymysql.connect(host='192.168.0.89', |
|
|
|
port=3306, |
|
|
|
user='shuishan', |
|
|
|
password='Shuishan@2020', |
|
|
|
user='root', |
|
|
|
password='2020yunjisuan!', |
|
|
|
db='shuishan', |
|
|
|
charset='utf8') |
|
|
|
|
|
|
@ -41,54 +44,58 @@ def get_problem_description(_id: str): |
|
|
|
"from problem where id = %d" % int(_id)) |
|
|
|
des = cursor.fetchone() |
|
|
|
# print(des) |
|
|
|
title = '<div><strong style="font-size:22px;color:blue;">%s. %s</strong></div><br/>' % (_id, des[0]) |
|
|
|
description = '<div><strong style="font-size:20px;color:blue;">Description</strong></div><div>%s</div><br/>' % des[1] |
|
|
|
input_description = '<div><strong style="font-size:20px;color:blue;">Input Description</strong></div><div>%s</div><br/>' \ |
|
|
|
title = '<div><strong style="font-size:22px">%s. %s</strong></div><br/>' % (_id, des[0]) |
|
|
|
description = '<div><strong style="font-size:20px">Description</strong></div><div>%s</div><br/>' % des[1] |
|
|
|
input_description = '<div><strong style="font-size:20px">Input Description</strong></div><div>%s</div><br/>' \ |
|
|
|
% des[2] |
|
|
|
output_description = '<div><strong style="font-size:20px;color:blue;">Output Description</strong></div><div>%s</div><br/>' \ |
|
|
|
output_description = '<div><strong style="font-size:20px">Output Description</strong></div><div>%s</div><br/>' \ |
|
|
|
% des[3] |
|
|
|
samples = json.loads(des[-1].replace("\n", "\\n")) |
|
|
|
samples_html = '' |
|
|
|
for s in samples: |
|
|
|
_input = s["input"].strip().replace(" ", " ").replace("\n", "<br/> ") |
|
|
|
_output = s["output"].strip().replace(" ", " ").replace("\n", "<br/> ") |
|
|
|
# _input = s["input"].strip().replace(" ", " ") |
|
|
|
# _output = s["output"].strip().replace(" ", " ") |
|
|
|
stra = '<div>' |
|
|
|
strb = '<div style="width:100%;">' |
|
|
|
strc = '<div style="display:inline-block;width:45%;vertical-align:top;"><strong style="font-size:20px;color:blue;">Input</strong></div>' |
|
|
|
strd = '<div style="display:inline-block;width:2%;vertical-align:top;"></div>' |
|
|
|
stre = '<div style="display:inline-block;width:45%;vertical-align:top;"><strong style="font-size:20px;color:blue;">Output</strong></div>' |
|
|
|
strf = '</div><br/>' |
|
|
|
strg = '<div style="width:100%;">' |
|
|
|
strh = '<div style="display:inline-block;width:45%;height:100%;vertical-align:top;border:0.5px solid;border-radius:5px;"><br/> ' + _input + '<br/> </div>' |
|
|
|
stri = '<div style="display:inline-block;width:2%;height:100%;vertical-align:top;"></div>' |
|
|
|
strj = '<div style="display:inline-block;width:45%;height:100%;vertical-align:top;border:0.5px solid;border-radius:5px;"><br/> ' + _output + '<br/> </div>' |
|
|
|
strk = '</div>' |
|
|
|
strl = '</div><br/>' |
|
|
|
samples_html = samples_html + stra + strb + strc + strd + stre + strf + strg + strh + stri + strj + strk + strl |
|
|
|
return title + description + input_description + output_description + samples_html, 200 |
|
|
|
_input = s["input"].strip().replace(" ", " ").replace("\n", "<br/>") |
|
|
|
_output = s["output"].strip().replace(" ", " ").replace("\n", "<br/>") |
|
|
|
str1 = '<div>' |
|
|
|
str2 = '<div style="display:inline-block;width:45%;vertical-align:top;">' |
|
|
|
str3 = '<div><strong style="font-size:20px">Input</strong></div><br/>' |
|
|
|
str4 = '<div>' + _input + '</div>' |
|
|
|
str5 = '</div>' |
|
|
|
str6 = '<div style="display:inline-block;width:45%;vertical-align:top;">' |
|
|
|
str7 = '<div><strong style="font-size:20px">Output</strong></div><br/>' |
|
|
|
str8 = '<div>' + _output + '</div>' |
|
|
|
str9 = '</div>' |
|
|
|
str0 = '</div><br/>' |
|
|
|
samples_html = samples_html + str1 + str2 + str3 + str4 + str5 + str6 + str7 + str8 + str9 + str0 |
|
|
|
return title + description + input_description + output_description + samples_html, 200 |
|
|
|
|
|
|
|
|
|
|
|
@app.route('/case_test/', methods=['POST']) |
|
|
|
def case_test_(): |
|
|
|
pid: str = request.json.get("pid") |
|
|
|
code: str = request.json.get("code") |
|
|
|
print(pid) |
|
|
|
print(code) |
|
|
|
return 'pass', 200 |
|
|
|
with open('wulin.txt', 'w', encoding='utf-8', newline='') as f: |
|
|
|
f.write(pid) |
|
|
|
f.close() |
|
|
|
results = testcase.submit_handler(code, pid, 'C') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return results, 200 |
|
|
|
|
|
|
|
|
|
|
|
@app.route('/check-logic-error/', methods=['POST']) |
|
|
|
def check_logic_error(): |
|
|
|
pid: str = request.json.get("pid") |
|
|
|
code: str = request.json.get("code") |
|
|
|
print(pid) |
|
|
|
print(code) |
|
|
|
model = PIPEModel() |
|
|
|
model.load_savedModel() |
|
|
|
answer = model.predict_code(code=code) |
|
|
|
del model |
|
|
|
# print(type(code)) |
|
|
|
# model = PIPEModel() |
|
|
|
# model.load_savedModel('./PIPE/training/C2AE_model/cp-0015.ckpt') |
|
|
|
# answer = model.predict_code(code=code) |
|
|
|
# del model |
|
|
|
# with open('wulin3.txt', 'w', encoding='utf-8', newline='') as f: # 设置文件对象 |
|
|
|
# f.write(answer) # 将字符串写入文件中 |
|
|
|
# f.close() |
|
|
|
answer = my_check_logic_error.check_logic_error() |
|
|
|
# results = 'check_logic_error' |
|
|
|
return answer, 200 |
|
|
|
|
|
|
@ -97,12 +104,14 @@ def check_logic_error(): |
|
|
|
def submit(): |
|
|
|
pid: str = request.json.get("pid") |
|
|
|
code: str = request.json.get("code") |
|
|
|
print(pid) |
|
|
|
print(code) |
|
|
|
with open('wulin2.txt', 'w', encoding='utf-8', newline='') as f: |
|
|
|
f.write(pid) |
|
|
|
f.close() |
|
|
|
results = mysubmit.submit_handler(code, pid, 'C') |
|
|
|
|
|
|
|
# results = check_logic_error(pid, code) |
|
|
|
results = 'submit' |
|
|
|
return results, 200 |
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|
app.run() |
|
|
|
app.run(host='0.0.0.0') |