Commit d13f18bf authored by Kento HASEGAWA's avatar Kento HASEGAWA

Use 'problem' instead of 'question', 'solution' instead of 'answer', and...

Use 'problem' instead of 'question', 'solution' instead of 'answer', and 'part' instead of 'template'
parent 79ed74b1
...@@ -2,10 +2,10 @@ ...@@ -2,10 +2,10 @@
# Project-specific files # Project-specific files
/conf.json /conf.json
/questions/* /problems/*
!/questions/.gitkeep !/problems/.gitkeep
/answers/* /solutions/*
!/answers/.gitkeep !/solutions/.gitkeep
# Byte-compiled / optimized / DLL files # Byte-compiled / optimized / DLL files
......
...@@ -16,16 +16,16 @@ def webui_index(): ...@@ -16,16 +16,16 @@ def webui_index():
# return adc2019system.role.role # return adc2019system.role.role
return render_template('index.html') return render_template('index.html')
@webui.route('/template/questions') @webui.route('/part/problems')
def webui_template_questions(): def webui_part_problems():
if (adc2019system.role is not None) and (adc2019system.role.type == 'host'): if (adc2019system.role is not None) and (adc2019system.role.type == 'host'):
questions = adc2019system.role.get_questions() problems = adc2019system.role.get_problems()
return render_template('part_questions.html', questions=questions) return render_template('part_problems.html', problems=problems)
else: else:
return abort(404) return abort(404)
@webui.route('/template/system-summary') @webui.route('/part/system-summary')
def webui_template_workers(): def webui_parte_workers():
if (adc2019system.role is not None) and (adc2019system.role.type == 'host'): if (adc2019system.role is not None) and (adc2019system.role.type == 'host'):
workers = adc2019system.role.get_workers() workers = adc2019system.role.get_workers()
return render_template('part_system_summary.html', workers=workers) return render_template('part_system_summary.html', workers=workers)
...@@ -41,18 +41,18 @@ def webui_part_request_status(request_id=None): ...@@ -41,18 +41,18 @@ def webui_part_request_status(request_id=None):
else: else:
return abort(404) return abort(404)
@webui.route('/template/question/<name>') @webui.route('/part/problem/<name>')
def webui_template_question_status(name=None): def webui_partem_status(name=None):
if name is None: if name is None:
return abort(404) return abort(404)
if (adc2019system.role is not None) and (adc2019system.role.type == 'host'): if (adc2019system.role is not None) and (adc2019system.role.type == 'host'):
question = adc2019system.role.get_question(name) problem = adc2019system.role.get_problem(name)
if question is None: if problem is None:
return abort(404) return abort(404)
else: else:
return render_template('part_question_status.html', question=question) return render_template('part_problem_status.html', problem=problem)
else: else:
return abort(404) return abort(404)
......
...@@ -5,7 +5,7 @@ import threading ...@@ -5,7 +5,7 @@ import threading
import time import time
import requests import requests
from utils import Question from utils import Problem
class Host(object): class Host(object):
...@@ -13,29 +13,29 @@ class Host(object): ...@@ -13,29 +13,29 @@ class Host(object):
self.type = 'host' self.type = 'host'
self.config = config self.config = config
self.questions = dict() self.problems = dict()
self.worker_manager = None self.worker_manager = None
self.request = dict() self.request = dict()
self.processing_request = None self.processing_request = None
self._load_questions(config['question_path']) self._load_problems(config['problem_path'])
self._setup_workers() self._setup_workers()
def __repr__(self): def __repr__(self):
return "Host" return "Host"
def _load_questions(self, path): def _load_problems(self, path):
questions_path = glob.glob(path) problems_path = glob.glob(path)
questions_path = sorted(questions_path) problems_path = sorted(problems_path)
for v in questions_path: for v in problems_path:
question = Question(v) problem = Problem(v)
_key = question.name _key = problem.name
self.questions[_key] = question self.problems[_key] = problem
def _setup_workers(self): def _setup_workers(self):
...@@ -46,13 +46,13 @@ class Host(object): ...@@ -46,13 +46,13 @@ class Host(object):
def get_workers(self): def get_workers(self):
return self.worker_manager.get_workers() return self.worker_manager.get_workers()
def distribute_question(self, question_key): def distribute_problem(self, problem_key):
question = self.get_question(question_key) problem = self.get_problem(problem_key)
if question is None: if problem is None:
return {'status': 'key error'} return {'status': 'key error'}
else: else:
request = Request(self.worker_manager, question.get_dict()) request = Request(self.worker_manager, problem.get_dict())
request_id = request.get_id() request_id = request.get_id()
self.request[request_id] = request self.request[request_id] = request
...@@ -63,12 +63,12 @@ class Host(object): ...@@ -63,12 +63,12 @@ class Host(object):
'timeout': request.timeout 'timeout': request.timeout
} }
def get_questions(self): def get_problems(self):
return self.questions return self.problems
def get_question(self, _key): def get_problem(self, _key):
if _key in self.questions: if _key in self.problems:
return self.questions[_key] return self.problems[_key]
else: else:
return None return None
...@@ -80,10 +80,10 @@ class Host(object): ...@@ -80,10 +80,10 @@ class Host(object):
else: else:
print(f'W: Unknown request_id: {request_id}') print(f'W: Unknown request_id: {request_id}')
question_key = solution['question'] problem_key = solution['problem']
if question_key in self.questions: if problem_key in self.problems:
self.questions[question_key].put_solution(solution) self.problems[problem_key].put_solution(solution)
return {'status': 'registered'} return {'status': 'registered'}
else: else:
return {'status': 'error'} return {'status': 'error'}
...@@ -98,11 +98,11 @@ class Host(object): ...@@ -98,11 +98,11 @@ class Host(object):
if cmd == 'role': if cmd == 'role':
# サーバの役割確認 # サーバの役割確認
return {'role': self.type} return {'role': self.type}
elif cmd == 'question/solve': elif cmd == 'problem/solve':
# params['question']に指定された問題をworkerに配信 # params['problem']に指定された問題をworkerに配信
question_key = params['question'] problem_key = params['problem']
return self.distribute_question(question_key) return self.distribute_problem(problem_key)
elif cmd == 'question/solution': elif cmd == 'problem/solution':
self.store_solution(params) self.store_solution(params)
return {'status': 'received'} return {'status': 'received'}
elif cmd == 'request/status': elif cmd == 'request/status':
...@@ -223,9 +223,9 @@ class Request(object): ...@@ -223,9 +223,9 @@ class Request(object):
if self.broadcast_time is None: if self.broadcast_time is None:
progress = 0, progress = 0,
else: else:
progress_question = response_count / worker_count * 100 progress_problem = response_count / worker_count * 100
progress_time = (time.time() - self.broadcast_time) / self.timeout * 100 progress_time = (time.time() - self.broadcast_time) / self.timeout * 100
progress = min(100, max(progress_question, progress_time)) progress = min(100, max(progress_problem, progress_time))
worker_list = self.worker_manager.get_workers().keys() worker_list = self.worker_manager.get_workers().keys()
worker_status = dict() worker_status = dict()
......
...@@ -64,11 +64,11 @@ class Solver(object): ...@@ -64,11 +64,11 @@ class Solver(object):
def submit_solution(self, params, solution): def submit_solution(self, params, solution):
data = { data = {
'request_id': params['request_id'], 'request_id': params['request_id'],
'question': params['name'], 'problem': params['name'],
'worker': self.address 'worker': self.address
} }
data.update(solution) data.update(solution)
self.post('question/solution', data) self.post('problem/solution', data)
def start_solver(self, params): def start_solver(self, params):
......
...@@ -15,30 +15,30 @@ body{ ...@@ -15,30 +15,30 @@ body{
background-color: rgba(0, 0, 50, .5); background-color: rgba(0, 0, 50, .5);
} }
#question-list-container{ #problem-list-container{
height: calc(100vh - 50px); height: calc(100vh - 50px);
overflow-y: scroll; overflow-y: scroll;
overflow-x: hidden; overflow-x: hidden;
} }
#question-list-container th.large-cell, #problem-list-container th.large-cell,
#question-list-container td.large-cell{ #problem-list-container td.large-cell{
width: 24%; width: 24%;
} }
#question-list-container th.small-cell, #problem-list-container th.small-cell,
#question-list-container td.small-cell{ #problem-list-container td.small-cell{
width: 14%; width: 14%;
} }
#question-list-container tr.question-row, #problem-list-container tr.problem-row,
#question-list-container tr.question-row td{ #problem-list-container tr.problem-row td{
cursor: pointer; cursor: pointer;
} }
#question-list-container tr.question-row.q-selected{ #problem-list-container tr.problem-row.q-selected{
background-color: rgba(200, 100, 100, .3); background-color: rgba(200, 100, 100, .3);
} }
#question-list-container tr.question-row:hover{ #problem-list-container tr.problem-row:hover{
background-color: rgba(200, 100, 100, .15); background-color: rgba(200, 100, 100, .15);
} }
...@@ -56,7 +56,7 @@ body{ ...@@ -56,7 +56,7 @@ body{
width: 20%; width: 20%;
} }
#question-control-pane h3{ #problem-control-pane h3{
display: inline-block; display: inline-block;
} }
......
...@@ -4,21 +4,21 @@ class StatusView { ...@@ -4,21 +4,21 @@ class StatusView {
constructor(selector) { constructor(selector) {
this.container = $(selector); this.container = $(selector);
this.question_key = null; this.problem_key = null;
this.request_refresh_timer = null; this.request_refresh_timer = null;
} }
// 問題詳細画面を表示 // 問題詳細画面を表示
show_question(question_key = null){ show_problem(problem_key = null){
var _this = this; var _this = this;
if(question_key != null){ if(problem_key != null){
this.question_key = question_key; this.problem_key = problem_key;
} }
$.ajax({ $.ajax({
type: 'GET', type: 'GET',
dataType: 'html', dataType: 'html',
url: '/template/question/' + _this.question_key url: '/part/problem/' + _this.problem_key
}).done((d) => { }).done((d) => {
_this.container.empty(); _this.container.empty();
_this.container.html(d); _this.container.html(d);
...@@ -36,9 +36,9 @@ class StatusView { ...@@ -36,9 +36,9 @@ class StatusView {
$.ajax({ $.ajax({
type: "POST", type: "POST",
dataType: "json", dataType: "json",
url: "/api/question/solve", url: "/api/problem/solve",
data: JSON.stringify({ data: JSON.stringify({
"question": _this.question_key "problem": _this.problem_key
}), }),
contentType: 'application/json' contentType: 'application/json'
}).done((d) => { }).done((d) => {
...@@ -48,7 +48,7 @@ class StatusView { ...@@ -48,7 +48,7 @@ class StatusView {
_this.container.find('#solver-processing-modal').modal('show'); _this.container.find('#solver-processing-modal').modal('show');
_this.container.find('#solver-processing-modal').on('hidden.bs.modal', function(e){ _this.container.find('#solver-processing-modal').on('hidden.bs.modal', function(e){
_this.show_question(); _this.show_problem();
}) })
_this.get_request_status(request_id, timeout); _this.get_request_status(request_id, timeout);
...@@ -57,20 +57,6 @@ class StatusView { ...@@ -57,20 +57,6 @@ class StatusView {
get_request_status(request_id, timeout){ get_request_status(request_id, timeout){
var _this = this; var _this = this;
// $.ajax({
// type: 'POST',
// dataType: 'json',
// url: '/api/request/status',
// data: JSON.stringify({
// 'request_id': request_id
// }),
// contentType: 'application/json'
// }).done((d) => {
// if(d['status'] != 'done'){
// _this.request_refresh_timer = setTimeout(_this.get_request_status(request_id, timeout), 1000);
// }
// console.log(d);
// });
$.ajax({ $.ajax({
type: 'GET', type: 'GET',
dataType: 'html', dataType: 'html',
...@@ -83,7 +69,7 @@ class StatusView { ...@@ -83,7 +69,7 @@ class StatusView {
console.log(status); console.log(status);
if(status == 'done'){ if(status == 'done'){
_this.request_refresh_timer = null; _this.request_refresh_timer = null;
// _this.show_question(); // _this.show_problem();
}else{ }else{
_this.request_refresh_timer = setTimeout(_this.get_request_status(request_id, timeout), 1000); _this.request_refresh_timer = setTimeout(_this.get_request_status(request_id, timeout), 1000);
} }
...@@ -97,7 +83,7 @@ class StatusView { ...@@ -97,7 +83,7 @@ class StatusView {
$.ajax({ $.ajax({
type: "GET", type: "GET",
dataType: "html", dataType: "html",
url: "/template/system-summary" url: "/part/system-summary"
}).done((d) => { }).done((d) => {
_this.container.empty(); _this.container.empty();
_this.container.html(d); _this.container.html(d);
...@@ -143,28 +129,28 @@ $(function(){ ...@@ -143,28 +129,28 @@ $(function(){
const status_view = new StatusView('#status-container'); const status_view = new StatusView('#status-container');
var refresh_questions = function(){ var refresh_problems = function(){
$.ajax({ $.ajax({
type: "GET", type: "GET",
dataType: "html", dataType: "html",
url: "/template/questions" url: "/part/problems"
}).done((d) => { }).done((d) => {
$("#question-list-container").empty(); $("#problem-list-container").empty();
$("#question-list-container").html(d); $("#problem-list-container").html(d);
$(".question-row td").click(function(){ $(".problem-row td").click(function(){
var $tr = $(this).parent("tr.question-row"); var $tr = $(this).parent("tr.problem-row");
$(".question-row").removeClass("q-selected"); $(".problem-row").removeClass("q-selected");
$tr.addClass("q-selected"); $tr.addClass("q-selected");
var qname = $tr.data("qname"); var qname = $tr.data("qname");
// show_question_status(qname); // show_problem_status(qname);
location.hash = "#" + qname; location.hash = "#" + qname;
return false; return false;
}); });
var hash = location.hash.replace("#", ""); var hash = location.hash.replace("#", "");
if(hash != ""){ if(hash != ""){
$(".question-row[data-qname='" + hash + "']").addClass("q-selected"); $(".problem-row[data-qname='" + hash + "']").addClass("q-selected");
} }
}); });
} }
...@@ -174,11 +160,11 @@ $(function(){ ...@@ -174,11 +160,11 @@ $(function(){
if(hash == ""){ if(hash == ""){
status_view.show_system(); status_view.show_system();
}else{ }else{
status_view.show_question(hash); status_view.show_problem(hash);
} }
}).trigger('hashchange'); }).trigger('hashchange');
refresh_questions(); refresh_problems();
}); });
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
<div class="col-5" id="content-left"> <div class="col-5" id="content-left">
<h3>問題一覧</h3>&nbsp; <h3>問題一覧</h3>&nbsp;
<span><a href="/#" id="view-server-status-button">システム状況</a></span> <span><a href="/#" id="view-server-status-button">システム状況</a></span>
<div id="question-list-container"> <div id="problem-list-container">
<p>Loading...</p> <p>Loading...</p>
</div> </div>
</div> </div>
......
<div> <div>
<!-- <div class="col-4"> --> <!-- <div class="col-4"> -->
<h3> 【{{question.name}}】</h3> <h3> 【{{problem.name}}】</h3>
{#% # if localmode %#} {#% # if localmode %#}
<p> <p>
<button class="btn btn-primary btn-lg start-button" type="button" data-qname="{{question.name}}">Start</button> <button class="btn btn-primary btn-lg start-button" type="button" data-qname="{{problem.name}}">Start</button>
<button class="btn btn-danger btn-lg stop-button" type="button" data-qname="all">Stop</button> <button class="btn btn-danger btn-lg stop-button" type="button" data-qname="all">Stop</button>
<button class="btn btn-info btn-lg save-button" type="button" data-qname="{{question.name}}">Save</button> <button class="btn btn-info btn-lg save-button" type="button" data-qname="{{problem.name}}">Save</button>
<button class="btn btn-success btn-lg submit-button" type="button" data-qname="{{question.name}}">Up</button> <button class="btn btn-success btn-lg submit-button" type="button" data-qname="{{problem.name}}">Up</button>
</p> </p>
{#% else %#} {#% else %#}
<!-- [View Only] --> <!-- [View Only] -->
...@@ -21,11 +21,11 @@ ...@@ -21,11 +21,11 @@
<th>Client</th> <th>Client</th>
<th>Score</th> <th>Score</th>
</tr> </tr>
{% for k, v in question.get_solutions().items() %} {% for k, v in problem.get_solutions().items() %}
{#% if (qdata.best_json == k) and (v.answer != "") %#} {#% if (qdata.best_json == k) and (v.answer != "") %#}
<!-- <tr class="answer-detail-row submit-answer" data-json="{#{k}#}" data-qname="{#{qname}#}"> --> <!-- <tr class="answer-detail-row submit-answer" data-json="{#{k}#}" data-qname="{#{qname}#}"> -->
{#% else %#} {#% else %#}
<tr class="solution-detail-row" data-json="{{k}}" data-qname="{{question.name}}"> <tr class="solution-detail-row" data-json="{{k}}" data-qname="{{problem.name}}">
{#% endif %#} {#% endif %#}
<td>{{v.timestamp_str}}</td> <td>{{v.timestamp_str}}</td>
<td>{{v.worker}}</td> <td>{{v.worker}}</td>
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
<div class="modal-dialog modal-dialog-centered modal-lg" role="document"> <div class="modal-dialog modal-dialog-centered modal-lg" role="document">
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <div class="modal-header">
<h5 class="modal-title" id="solver-processing-modal-title">{{question.name}}</h5> <h5 class="modal-title" id="solver-processing-modal-title">{{problem.name}}</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close"> <button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span> <span aria-hidden="true">&times;</span>
</button> </button>
......
<table class="table table-bordered table-hover" id="question-table"> <table class="table table-bordered table-hover" id="problem-table">
<thead> <thead>
<tr> <tr>
<th class="large-cell">File Name</th> <th class="large-cell">File Name</th>
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% for k, v in questions.items() %} {% for k, v in problems.items() %}
<tr class="question-row" data-qname="{{v.name}}"> <tr class="problem-row" data-qname="{{v.name}}">
<td class="large-cell">{{v.name}}</td> <td class="large-cell">{{v.name}}</td>
<td class="small-cell">{{v.size_str}}</td> <td class="small-cell">{{v.size_str}}</td>
<td class="small-cell">{{v.block_num}}</td> <td class="small-cell">{{v.block_num}}</td>
......
from .data import Question from .data import Problem
...@@ -3,7 +3,7 @@ import os ...@@ -3,7 +3,7 @@ import os
import time import time
import uuid import uuid
class Question(object): class Problem(object):
def __init__(self, path): def __init__(self, path):
...@@ -14,13 +14,13 @@ class Question(object): ...@@ -14,13 +14,13 @@ class Question(object):
self.status = 'Ready' self.status = 'Ready'
self.solutions = dict() self.solutions = dict()
self._load_question(path) self._load_problem(path)
@property @property
def size_str(self): def size_str(self):
return f'{self.size[0]}X{self.size[1]}' return f'{self.size[0]}X{self.size[1]}'
def _load_question(self, path): def _load_problem(self, path):
with open(path, 'r') as fp: with open(path, 'r') as fp:
q_lines = fp.readlines() q_lines = fp.readlines()
...@@ -64,7 +64,7 @@ class Solution(object): ...@@ -64,7 +64,7 @@ class Solution(object):
def __init__(self, data): def __init__(self, data):
self.question = data['question'] self.problem = data['problem']
self.request_id = data['request_id'] self.request_id = data['request_id']
self.worker = data['worker'] self.worker = data['worker']
self.elapsed_time = data['elapsed_time'] self.elapsed_time = data['elapsed_time']
......
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