Commit f3ba4ba7 authored by Kento HASEGAWA's avatar Kento HASEGAWA
Browse files

Add support for adc2019 official tools

parent 9d989358
Loading
Loading
Loading
Loading
+3 −0
Changes for .gitmodules: 3 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -13,3 +13,6 @@
[submodule "solvers/nszw"]
	path = solvers/nszw
	url = git@togawa-gitlab:adc2019/nszw-solver.git
[submodule "adc2019"]
	path = adc2019
	url = https://github.com/dasadc/adc2019.git
+2 −0
Changes for Makefile: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -2,3 +2,5 @@
.PHONY: clean
clean:
	rm -rf ./solutions/*
	rm -rf ./solvers/hsgw/P*.txt
	rm -rf ./solvers/kwmr/A*.txt
Changes for adc2019: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
Subproject commit a40846560bf682e7a6165ae50216c7bb49dccd26
+26 −31
Changes for roles/host.py: 26 added lines, 31 removed lines.
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ import requests

from utils import Problem, GroupPart
import utils.adcclilib as adccli
# import adc2019.client.adcclient

class Host(object):

@@ -212,47 +213,41 @@ class Host(object):
            solution_id = params['solution']
            return self.get_viewer_data(problem_key, solution_id)
        elif cmd == 'adccli/login':
            with open('path-to-adccli-login', 'r') as fp:
                d = json.load(fp)
            r = adccli.login(d['url'], d['username'], d['password'])
            res = {'message': r}
            return json.dumps(res)
            r = adccli.login(self.config['adccli']['url'], self.config['adccli']['username'], self.config['adccli']['password'])
            return {'status': r}
        elif cmd == 'adccli/logout':
            r = adccli.logout()
            res = {'message': r}
            return json.dumps(res)
            return {'status': r}
        elif cmd == 'adccli/whoami':
            with open('path-to-adccli-login', 'r') as fp:
                d = json.load(fp)
            r = adccli.whoami()
            res = {'message': r, 'status': r == d['username']}
            return json.dumps(res)
            return {'message': r, 'status': r == self.config['adccli']}
        elif cmd == 'adccli/download-problem':
            out_abspath = os.path.abspath(self.config['problem_path'])
            r = adccli.get_q_all(out_abspath)
            self._load_problems(self.config['problem_path'])
            res = {'message': r}
            return json.dumps(res)
            return {'status': r}
        elif cmd == 'adccli/upload-solution':
            qname = params['problem']
            if not "best_json" in questions[qname]:
                res = {'message': "Required to 'save' before submission"}
            problem_key = params['problem']
            problem = self.problems[problem_key]
            if problem.best_solution_key is None:
                res = {'status': "Required to 'save' before submission"}
            else:
                out_path = "{}/{}".format(self.config['solution_path'], "submit")
                # qnumber = qname.replace("NL_Q", "").replace(".txt", "")
                # ans_file_path = "{}/T01_A{}.txt".format(out_path, qnumber)
                # ans_file_abspath = os.path.abspath(ans_file_path)

                # r = adccli.put_a(qnumber, ans_file_abspath)
                # mes = r + "\n"

                # json_name = questions[qname]['best_json']
                # data = questions[qname]['answers'][json_name]
                # r = adccli.put_a_info(qnumber, data['cputime'], "0", "Test")
                # mes += r
                mes = ''
                res = {'message': mes}
            return json.dumps(res)
                solution_path = f"{self.config['solution_path']}/{problem_key}/submit/{problem_key}.txt"
                qnumber = problem_key.replace("NL_Q", "").replace(".txt", "")

                solution_abspath = os.path.abspath(solution_path)

                r = adccli.put_a(qnumber, solution_abspath)
                mes = r + "\n"

                best_solution_key = problem.best_solution_key
                best_solution = problem.get_solution(best_solution_key)
                cputime = f'{best_solution.elapsed_time:.3f}'
                info_mes = f'Solver: {best_solution.worker}, RID: {best_solution.request_id}'
                r = adccli.put_a_info(qnumber, cputime, "0", info_mes)
                mes += r
                res = {'status': mes}
            return res
        else:
            return None

+25 −4
Changes for static/js/adc2019.js: 25 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -41,6 +41,10 @@ class StatusView {
                _this.fire('refresh');
            });

            _this.container.find('.submit-button').click(()=>{
                _this.save_solution();
            });

            _this.container.find('#chk-solver-all').prop('checked', false);
            
            _this.container.find('#chk-solver-all').on('change', (e) => {
@@ -145,6 +149,23 @@ class StatusView {
        });
    }
    
    // アップロード
    upload_solution(){
        var _this = this;
        
        $.ajax({
            type: "POST",
            dataType: "json",
            url: "/api/adccli/upload-solution",
            data: JSON.stringify({
                "problem": _this.problem_key
            }),
            contentType: 'application/json'
        }).done((d) => {
            alert(d);
        });
    }

    update_status_view(){
        var _this = this;
        $.ajax({
@@ -227,18 +248,18 @@ class StatusView {
            });

            $("#adccli-login-button").click(function(){
                button_action_with_ajax($(this), "/adccli-login");
                button_action_with_ajax($(this), "/api/adccli/login");
            });
            $("#adccli-logout-button").click(function(){
                button_action_with_ajax($(this), "/adccli-logout");
                button_action_with_ajax($(this), "/api/adccli/logout");
            });
            $("#adccli-get-all-q").click(function(){
                button_action_with_ajax($(this), "/adccli-get-all-q");
                button_action_with_ajax($(this), "/api/adccli/download-problem");
            });

            $.ajax({
                type: "GET",
                url: "/adccli-whoami",
                url: "/api/adccli/whoami",
                dataType: "json",
            }).done((data)=>{
                if(data['status'])
Loading