Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

121 wiersze
4.9 KiB

3 lat temu
3 lat temu
3 lat temu
3 lat temu
3 lat temu
3 lat temu
3 lat temu
3 lat temu
3 lat temu
3 lat temu
  1. from flask import Flask
  2. from flask import jsonify
  3. from flask import request
  4. import json
  5. import pymysql
  6. import sys
  7. import mysubmit
  8. import testcase
  9. import my_check_logic_error
  10. sys.path.append('../')
  11. from PIPE.main import PIPEModel
  12. app = Flask(__name__)
  13. app.config['JSON_AS_ASCII'] = False
  14. db = pymysql.connect(host='192.168.0.89',
  15. port=3306,
  16. user='root',
  17. password='2020yunjisuan!',
  18. db='shuishan',
  19. charset='utf8')
  20. @app.route('/get-problem-items/')
  21. def get_problem_items():
  22. db.ping(reconnect=True)
  23. cursor = db.cursor()
  24. cursor.execute("select id, title from problem")
  25. data = cursor.fetchall()
  26. pids = []
  27. for d in data:
  28. pids.append({"id": d[0], "title": d[1]})
  29. pids = sorted(pids, key=lambda x: x.__getitem__('id'), reverse=False)
  30. for i in range(len(pids)):
  31. pids[i]['id'] = str(pids[i]['id'])
  32. return jsonify(pids), 200
  33. @app.route('/get-problem-description/<_id>/')
  34. def get_problem_description(_id: str):
  35. db.ping(reconnect=True)
  36. cursor = db.cursor()
  37. cursor.execute("select title, description, input_description, output_description, samples "
  38. "from problem where id = %d" % int(_id))
  39. des = cursor.fetchone()
  40. # print(des)
  41. title = '<div><strong style="font-size:22px;color:blue;">%s. %s</strong></div><br/>' % (_id, des[0])
  42. description = '<div><strong style="font-size:20px;color:blue;">Description</strong></div><div>%s</div><br/>' % des[1]
  43. input_description = '<div><strong style="font-size:20px;color:blue;">Input Description</strong></div><div>%s</div><br/>' \
  44. % des[2]
  45. output_description = '<div><strong style="font-size:20px;color:blue;">Output Description</strong></div><div>%s</div><br/>' \
  46. % des[3]
  47. samples = json.loads(des[-1].replace("\n", "\\n"))
  48. samples_html = ''
  49. for s in samples:
  50. _input = s["input"].strip().replace(" ", "&nbsp;&nbsp;").replace("\n", "<br/>&nbsp;&nbsp;&nbsp;&nbsp;")
  51. _output = s["output"].strip().replace(" ", "&nbsp;&nbsp;").replace("\n", "<br/>&nbsp;&nbsp;&nbsp;&nbsp;")
  52. # _input = s["input"].strip().replace(" ", "&nbsp;&nbsp;")
  53. # _output = s["output"].strip().replace(" ", "&nbsp;&nbsp;")
  54. stra = '<div>'
  55. strb = '<div style="width:100%;">'
  56. strc = '<div style="display:inline-block;width:45%;vertical-align:top;"><strong style="font-size:20px;color:blue;">Input</strong></div>'
  57. strd = '<div style="display:inline-block;width:2%;vertical-align:top;"></div>'
  58. stre = '<div style="display:inline-block;width:45%;vertical-align:top;"><strong style="font-size:20px;color:blue;">Output</strong></div>'
  59. strf = '</div><br/>'
  60. strg = '<div style="width:100%;">'
  61. 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>'
  62. stri = '<div style="display:inline-block;width:2%;height:100%;vertical-align:top;"></div>'
  63. 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>'
  64. strk = '</div>'
  65. strl = '</div><br/>'
  66. samples_html = samples_html + stra + strb + strc + strd + stre + strf + strg + strh + stri + strj + strk + strl
  67. return title + description + input_description + output_description + samples_html, 200
  68. @app.route('/case_test/', methods=['POST'])
  69. def case_test_():
  70. pid: str = request.json.get("pid")
  71. code: str = request.json.get("code")
  72. with open('wulin.txt', 'w', encoding='utf-8', newline='') as f:
  73. f.write(pid)
  74. f.close()
  75. results = testcase.submit_handler(code, pid, 'C')
  76. return results, 200
  77. @app.route('/check-logic-error/', methods=['POST'])
  78. def check_logic_error():
  79. pid: str = request.json.get("pid")
  80. code: str = request.json.get("code")
  81. # print(type(code))
  82. # model = PIPEModel()
  83. # model.load_savedModel('./PIPE/training/C2AE_model/cp-0015.ckpt')
  84. # answer = model.predict_code(code=code)
  85. # del model
  86. # with open('wulin3.txt', 'w', encoding='utf-8', newline='') as f: # 设置文件对象
  87. # f.write(answer) # 将字符串写入文件中
  88. # f.close()
  89. answer = my_check_logic_error.check_logic_error()
  90. # results = 'check_logic_error'
  91. return answer, 200
  92. @app.route('/submit/', methods=['POST'])
  93. def submit():
  94. pid: str = request.json.get("pid")
  95. code: str = request.json.get("code")
  96. with open('wulin2.txt', 'w', encoding='utf-8', newline='') as f:
  97. f.write(pid)
  98. f.close()
  99. results = mysubmit.submit_handler(code, pid, 'C')
  100. # results = check_logic_error(pid, code)
  101. return results, 200
  102. if __name__ == '__main__':
  103. app.run()