No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 

121 líneas
4.9 KiB

from flask import Flask
from flask import jsonify
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='192.168.0.89',
port=3306,
user='root',
password='2020yunjisuan!',
db='shuishan',
charset='utf8')
@app.route('/get-problem-items/')
def get_problem_items():
db.ping(reconnect=True)
cursor = db.cursor()
cursor.execute("select id, title from problem")
data = cursor.fetchall()
pids = []
for d in data:
pids.append({"id": d[0], "title": d[1]})
pids = sorted(pids, key=lambda x: x.__getitem__('id'), reverse=False)
for i in range(len(pids)):
pids[i]['id'] = str(pids[i]['id'])
return jsonify(pids), 200
@app.route('/get-problem-description/<_id>/')
def get_problem_description(_id: str):
db.ping(reconnect=True)
cursor = db.cursor()
cursor.execute("select title, description, input_description, output_description, samples "
"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/>' \
% des[2]
output_description = '<div><strong style="font-size:20px;color:blue;">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(" ", "&nbsp;&nbsp;").replace("\n", "<br/>&nbsp;&nbsp;&nbsp;&nbsp;")
_output = s["output"].strip().replace(" ", "&nbsp;&nbsp;").replace("\n", "<br/>&nbsp;&nbsp;&nbsp;&nbsp;")
# _input = s["input"].strip().replace(" ", "&nbsp;&nbsp;")
# _output = s["output"].strip().replace(" ", "&nbsp;&nbsp;")
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/>&nbsp;&nbsp;&nbsp;&nbsp;' + _input + '<br/>&nbsp;&nbsp;&nbsp;&nbsp;</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/>&nbsp;&nbsp;&nbsp;&nbsp;' + _output + '<br/>&nbsp;&nbsp;&nbsp;&nbsp;</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
@app.route('/case_test/', methods=['POST'])
def case_test_():
pid: str = request.json.get("pid")
code: str = request.json.get("code")
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(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
@app.route('/submit/', methods=['POST'])
def submit():
pid: str = request.json.get("pid")
code: str = request.json.get("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)
return results, 200
if __name__ == '__main__':
app.run()