Commit 98831a73 authored by Kento HASEGAWA's avatar Kento HASEGAWA

Merge branch 'comm-server' into comm

parents ed903e2f 1f74c9c0
...@@ -32,7 +32,7 @@ app_args = {} ...@@ -32,7 +32,7 @@ app_args = {}
questions = None questions = None
clients = None clients = None
current_seed = 1 current_seed = 1
wsq = None wsq = {}
def load_questions(): def load_questions():
global app_args global app_args
...@@ -117,9 +117,8 @@ def update_answer_list(qname): ...@@ -117,9 +117,8 @@ def update_answer_list(qname):
if answer_log['solved'] == "True": if answer_log['solved'] == "True":
is_solved = True is_solved = True
if questions[qname]['answer'] == answer_log['answer']:
if questions[qname]['answer'] == answer_log['answer']: questions[qname]['best_json'] = json_name
questions[qname]['best_json'] = json_name
if (questions[qname]['last_req'] == float(answer_log['req_id'])): if (questions[qname]['last_req'] == float(answer_log['req_id'])):
if answer_log['solver'] in questions[qname]['solver']: if answer_log['solver'] in questions[qname]['solver']:
...@@ -213,7 +212,9 @@ def post(): ...@@ -213,7 +212,9 @@ def post():
with open(save_file_path, "w") as fp: with open(save_file_path, "w") as fp:
json.dump(dat, fp, indent=4) json.dump(dat, fp, indent=4)
wsq.put(dat) for k, v in wsq.items():
if v is not None:
v.put(dat)
res = {"status": "OK"} res = {"status": "OK"}
...@@ -346,8 +347,12 @@ def save_best_solution(): ...@@ -346,8 +347,12 @@ def save_best_solution():
_best_json = "" _best_json = ""
for k, v in questions[qname]['answers'].items(): for k, v in questions[qname]['answers'].items():
if v['nlcheck'] > _best_score: try:
_best_socer = v['nlcheck'] _score = float(v['nlcheck'])
except:
_score = -1
if _score > _best_score:
_best_score = _score
_best_json = k _best_json = k
if _best_json != "": if _best_json != "":
...@@ -355,12 +360,14 @@ def save_best_solution(): ...@@ -355,12 +360,14 @@ def save_best_solution():
if not os.path.isdir(out_path): if not os.path.isdir(out_path):
os.makedirs(out_path) os.makedirs(out_path)
print("Saved answer for {}: {}".format(qname, _best_json))
qnumber = qname.replace("NL_Q", "").replace(".txt", "") qnumber = qname.replace("NL_Q", "").replace(".txt", "")
out_file_path = "{}/T01_A{}.txt".format(out_path, qnumber) out_file_path = "{}/T01_A{}.txt".format(out_path, qnumber)
with open(out_file_path, 'w') as fp: with open(out_file_path, 'w') as fp:
fp.write(questions[qname]['answers'][_best_json]['answer']) fp.write(questions[qname]['answers'][_best_json]['answer'])
questions[_name]["status"] = "Saved" questions[qname]["status"] = "Saved"
questions[qname]['best_json'] = _best_json questions[qname]['best_json'] = _best_json
res = {"status": "OK"} res = {"status": "OK"}
...@@ -600,14 +607,15 @@ def ws(): ...@@ -600,14 +607,15 @@ def ws():
if request.environ.get('wsgi.websocket'): if request.environ.get('wsgi.websocket'):
ws = request.environ['wsgi.websocket'] ws = request.environ['wsgi.websocket']
ws_id = time.time()
wsq[ws_id] = Queue()
while True: while True:
if wsq is None: data = wsq[ws_id].get()
time.sleep(1) str_data = json.dumps(data)
continue ws.send(str_data)
else:
data = wsq.get() wsq[ws_id] = None
str_data = json.dumps(data)
ws.send(str_data)
@app.route("/") @app.route("/")
def index(): def index():
...@@ -653,9 +661,6 @@ def init_system(): ...@@ -653,9 +661,6 @@ def init_system():
if questions is None: if questions is None:
load_questions() load_questions()
if wsq is None:
wsq = Queue()
if __name__ == "__main__": if __name__ == "__main__":
parser = argparse.ArgumentParser(description="PYNQ control panel.") parser = argparse.ArgumentParser(description="PYNQ control panel.")
......
...@@ -209,6 +209,7 @@ $(function(){ ...@@ -209,6 +209,7 @@ $(function(){
data: {qname: qname} data: {qname: qname}
}).done((data) => { }).done((data) => {
alert(data['status']); alert(data['status']);
location.reload();
}); });
}); });
$("#client-control-pane").find(".submit-button").eq(0).click(function(){ $("#client-control-pane").find(".submit-button").eq(0).click(function(){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment