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