From e522538d989d7965d448ff5cdd6f6d8d15d4c0bb Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Tue, 17 Jan 2023 20:50:15 +0800 Subject: [PATCH 1/4] feat: server time in a new line --- web/app/views/page-footer.php | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/web/app/views/page-footer.php b/web/app/views/page-footer.php index 5d806ce..8d1b32e 100644 --- a/web/app/views/page-footer.php +++ b/web/app/views/page-footer.php @@ -13,25 +13,29 @@ if (!isset($ShowPageFooter)) { From 469fc99ca70f0e06855061d72568a37ef819c73c Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Wed, 18 Jan 2023 09:29:43 +0800 Subject: [PATCH 2/4] refactor(contest): not rejudge submissions after contest --- web/app/controllers/contest_inside.php | 4 +- web/app/controllers/contest_manage.php | 4 +- web/app/models/UOJContest.php | 175 ++++++++++++++++--------- 3 files changed, 117 insertions(+), 66 deletions(-) diff --git a/web/app/controllers/contest_inside.php b/web/app/controllers/contest_inside.php index 3b47fe4..210bd23 100644 --- a/web/app/controllers/contest_inside.php +++ b/web/app/controllers/contest_inside.php @@ -54,10 +54,10 @@ if ($is_manager) { isset($tabs_info[$cur_tab]) || UOJResponse::page404(); if (UOJContest::cur()->userCanStartFinalTest(Auth::user())) { - if (CONTEST_PENDING_FINAL_TEST <= $contest['cur_progress']) { + if (CONTEST_PENDING_FINAL_TEST == $contest['cur_progress']) { $start_test_form = new UOJBs4Form('start_test'); $start_test_form->handle = function () { - UOJContest::finalTest(); + UOJContest::cur()->finalTest(); }; $start_test_form->submit_button_config['class_str'] = 'btn btn-danger d-block w-100'; $start_test_form->submit_button_config['smart_confirm'] = ''; diff --git a/web/app/controllers/contest_manage.php b/web/app/controllers/contest_manage.php index 5ef3f81..0ab7f2a 100644 --- a/web/app/controllers/contest_manage.php +++ b/web/app/controllers/contest_manage.php @@ -596,11 +596,11 @@ EOD); EOD, function ($row) { - $problem = UOJProblem::query($row['problem_id']); + $problem = UOJContestProblem::query($row['problem_id'], UOJContest::cur()); echo ''; echo '', $row['problem_id'], ''; echo '', $problem->getLink(['with' => 'none']), ''; - echo '', isset($contest['extra_config']["problem_{$problem->info['id']}"]) ? $contest['extra_config']["problem_{$problem->info['id']}"] : 'default', ''; + echo '', $problem->getJudgeTypeInContest(), ''; echo ''; echo '
info['id'], ' 从比赛中移除吗?")\'>'; echo ''; diff --git a/web/app/models/UOJContest.php b/web/app/models/UOJContest.php index e7496d9..c9c8d2c 100644 --- a/web/app/models/UOJContest.php +++ b/web/app/models/UOJContest.php @@ -53,65 +53,6 @@ class UOJContest { return isSuperUser($user) || UOJUser::checkPermission($user, 'contests.create'); } - public static function finalTest() { - $contest = self::info(); - - $res = DB::selectAll([ - "select id, problem_id, content, submitter, hide_score_to_others from submissions", - "where", ["contest_id" => $contest['id']] - ]); - foreach ($res as $submission) { - $content = json_decode($submission['content'], true); - if (isset($content['final_test_config'])) { - $content['config'] = $content['final_test_config']; - unset($content['final_test_config']); - } - if (isset($content['first_test_config'])) { - unset($content['first_test_config']); - } - UOJSubmission::rejudgeById($submission['id'], [ - 'reason_text' => HTML::stripTags($contest['name']) . ' 最终测试', - 'reason_url' => HTML::url(UOJContest::cur()->getUri()), - 'set_q' => [ - "content" => json_encode($content) - ] - ]); - } - - // warning: check if this command works well when the database is not MySQL - DB::update([ - "update submissions", - "set", [ - "score = hidden_score", - "hidden_score = NULL", - "hide_score_to_others = 0" - ], "where", [ - "contest_id" => $contest['id'], - "hide_score_to_others" => 1 - ] - ]); - - $updated = []; - foreach ($res as $submission) { - $submitter = $submission['submitter']; - $pid = $submission['problem_id']; - if (isset($updated[$submitter]) && isset($updated[$submitter][$pid])) { - continue; - } - updateBestACSubmissions($submitter, $pid); - if (!isset($updated[$submitter])) { - $updated[$submitter] = []; - } - $updated[$submitter][$pid] = true; - } - - DB::update([ - "update contests", - "set", ["status" => 'testing'], - "where", ["id" => $contest['id']] - ]); - } - public static function announceOfficialResults() { // time config set_time_limit(0); @@ -246,11 +187,121 @@ class UOJContest { $label = '开始最终测试'; } - if ($this->progress() >= CONTEST_TESTING) { - $label = '重新' . $label; + return $label; + } + + public function finalTest() { + ignore_user_abort(true); + set_time_limit(0); + + DB::update([ + "update contests", + "set", ["status" => 'testing'], + "where", ["id" => $this->info['id']] + ]); + + if (DB::affected_rows() !== 1) { + // 已经有其他人开始评测了,不进行任何操作 + return; } - return $label; + $res = DB::selectAll([ + "select id, problem_id, content, result, submitter, hide_score_to_others from submissions", + "where", ["contest_id" => $this->info['id']] + ]); + foreach ($res as $submission) { + $content = json_decode($submission['content'], true); + + if (isset($content['final_test_config'])) { + $content['config'] = $content['final_test_config']; + unset($content['final_test_config']); + } + + if (isset($content['first_test_config'])) { + unset($content['first_test_config']); + } + + $q = [ + 'content' => json_encode($content), + ]; + + $problem_judge_type = $this->info['extra_config']["problem_{$submission['problem_id']}"] ?: $this->defaultProblemJudgeType(); + $result = json_decode($submission['result'], true); + + switch ($problem_judge_type) { + case 'sample': + if (isset($result['final_result']) && $result['final_result']['status'] == 'Judged') { + $q += [ + 'result' => json_encode($result['final_result']), + 'score' => $result['final_result']['score'], + 'used_time' => $result['final_result']['time'], + 'used_memory' => $result['final_result']['memory'], + 'judge_time' => $this->info['end_time_str'], + 'status' => 'Judged', + ]; + + if ($submission['hide_score_to_others']) { + $q['hidden_score'] = $q['score']; + $q['score'] = null; + } + } + + break; + + case 'no-details': + case 'full': + if ($result['status'] == 'Judged') { + $q += [ + 'result' => $submission['result'], + 'score' => $result['score'], + 'used_time' => $result['time'], + 'used_memory' => $result['memory'], + 'judge_time' => $this->info['end_time_str'], + 'status' => 'Judged', + ]; + + if ($submission['hide_score_to_others']) { + $q['hidden_score'] = $q['score']; + $q['score'] = null; + } + } + + break; + } + + UOJSubmission::rejudgeById($submission['id'], [ + 'reason_text' => HTML::stripTags($this->info['name']) . ' 最终测试', + 'reason_url' => HTML::url(UOJContest::cur()->getUri()), + 'set_q' => $q, + ]); + } + + // warning: check if this command works well when the database is not MySQL + DB::update([ + "update submissions", + "set", [ + "score = hidden_score", + "hidden_score = NULL", + "hide_score_to_others = 0" + ], "where", [ + "contest_id" => $this->info['id'], + "hide_score_to_others" => 1 + ] + ]); + + $updated = []; + foreach ($res as $submission) { + $submitter = $submission['submitter']; + $pid = $submission['problem_id']; + if (isset($updated[$submitter]) && isset($updated[$submitter][$pid])) { + continue; + } + updateBestACSubmissions($submitter, $pid); + if (!isset($updated[$submitter])) { + $updated[$submitter] = []; + } + $updated[$submitter][$pid] = true; + } } public function queryJudgeProgress() { From 8bf8f6c710308a279b012542cd33c6cf6c2e02f9 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Thu, 19 Jan 2023 12:11:26 +0800 Subject: [PATCH 3/4] feat(problem/manage): difficulty_form style --- web/app/controllers/problem_statement_manage.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/web/app/controllers/problem_statement_manage.php b/web/app/controllers/problem_statement_manage.php index 3aa2e63..9a4aa09 100644 --- a/web/app/controllers/problem_statement_manage.php +++ b/web/app/controllers/problem_statement_manage.php @@ -65,9 +65,12 @@ $problem_editor->runAtServer(); $difficulty_form = new UOJForm('difficulty'); $difficulty_form->addSelect('difficulty', [ + 'div_class' => 'flex-grow-1', 'options' => [-1 => '暂无评定'] + array_combine(UOJProblem::$difficulty, UOJProblem::$difficulty), 'default_value' => UOJProblem::info('difficulty'), ]); +$difficulty_form->config['form']['class'] = 'd-flex'; +$difficulty_form->config['submit_container']['class'] = 'ms-2'; $difficulty_form->handle = function () { DB::update([ "update problems", From dd1d1150ff07cf78778348fb8f57e5dd474dbcce Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Thu, 19 Jan 2023 12:37:36 +0800 Subject: [PATCH 4/4] feat(problem/manage): move view_type_form, solution_view_type_form --- web/app/controllers/problem_data_manage.php | 101 ---------------- .../controllers/problem_statement_manage.php | 111 ++++++++++++++++++ 2 files changed, 111 insertions(+), 101 deletions(-) diff --git a/web/app/controllers/problem_data_manage.php b/web/app/controllers/problem_data_manage.php index 75bd106..6197d18 100644 --- a/web/app/controllers/problem_data_manage.php +++ b/web/app/controllers/problem_data_manage.php @@ -466,93 +466,6 @@ $rejudgege97_form->submit_button_config['class_str'] = 'btn btn-danger d-block w $rejudgege97_form->submit_button_config['text'] = '重测 >=97 的程序'; $rejudgege97_form->submit_button_config['smart_confirm'] = ''; -$view_type_form = new UOJBs4Form('view_type'); -$view_type_form->addVSelect( - 'view_content_type', - array( - 'NONE' => '禁止', - 'ALL_AFTER_AC' => 'AC后', - 'ALL' => '所有人' - ), - '查看提交文件:', - $problem_extra_config['view_content_type'] -); -$view_type_form->addVSelect( - 'view_all_details_type', - array( - 'NONE' => '禁止', - 'SELF' => '仅自己', - 'ALL_AFTER_AC' => 'AC后', - 'ALL' => '所有人' - ), - '查看全部详细信息:', - $problem_extra_config['view_all_details_type'] -); -$view_type_form->addVSelect( - 'view_details_type', - array( - 'NONE' => '禁止', - 'SELF' => '仅自己', - 'ALL_AFTER_AC' => 'AC后', - 'ALL' => '所有人' - ), - '查看测试点详细信息:', - $problem_extra_config['view_details_type'] -); -$view_type_form->handle = function () { - global $problem, $problem_extra_config; - - $config = $problem_extra_config; - $config['view_content_type'] = $_POST['view_content_type']; - $config['view_all_details_type'] = $_POST['view_all_details_type']; - $config['view_details_type'] = $_POST['view_details_type']; - $esc_config = json_encode($config); - - DB::update([ - "update problems", - "set", ["extra_config" => $esc_config], - "where", ["id" => $problem['id']] - ]); -}; -$view_type_form->submit_button_config['class_str'] = 'btn btn-warning d-block w-100 mt-2'; - -$solution_view_type_form = new UOJBs4Form('solution_view_type'); -$solution_view_type_form->addVSelect( - 'view_solution_type', - array( - 'NONE' => '禁止', - 'ALL_AFTER_AC' => 'AC后', - 'ALL' => '所有人' - ), - '查看题解:', - $problem_extra_config['view_solution_type'] -); -$solution_view_type_form->addVSelect( - 'submit_solution_type', - array( - 'NONE' => '禁止', - 'ALL_AFTER_AC' => 'AC后', - 'ALL' => '所有人' - ), - '提交题解:', - $problem_extra_config['submit_solution_type'] -); -$solution_view_type_form->handle = function () { - global $problem, $problem_extra_config; - - $config = $problem_extra_config; - $config['view_solution_type'] = $_POST['view_solution_type']; - $config['submit_solution_type'] = $_POST['submit_solution_type']; - $esc_config = json_encode($config); - - DB::update([ - "update problems", - "set", ["extra_config" => $esc_config], - "where", ["id" => $problem['id']] - ]); -}; -$solution_view_type_form->submit_button_config['class_str'] = 'btn btn-warning d-block w-100 mt-2'; - if ($problem['hackable']) { $test_std_form = new UOJBs4Form('test_std'); $test_std_form->handle = function () use ($problem, $data_disp) { @@ -618,8 +531,6 @@ if ($problem['hackable']) { } $hackable_form->runAtServer(); -$view_type_form->runAtServer(); -$solution_view_type_form->runAtServer(); $data_form->runAtServer(); $clear_data_form->runAtServer(); $rejudge_form->runAtServer(); @@ -753,18 +664,6 @@ $info_form->runAtServer(); printHTML() ?> -
- - -
-
- - -
printHTML(); ?>
diff --git a/web/app/controllers/problem_statement_manage.php b/web/app/controllers/problem_statement_manage.php index 9a4aa09..4bfbc1a 100644 --- a/web/app/controllers/problem_statement_manage.php +++ b/web/app/controllers/problem_statement_manage.php @@ -83,6 +83,99 @@ $difficulty_form->handle = function () { ]); }; $difficulty_form->runAtServer(); + +$view_type_form = new UOJForm('view_type'); +$view_type_form->addSelect('view_content_type', [ + 'div_class' => 'row align-items-center g-0', + 'label_class' => 'form-label col-auto m-0 flex-grow-1', + 'select_class' => 'col-auto form-select w-auto', + 'label' => '查看提交文件', + 'options' => [ + 'NONE' => '禁止', + 'ALL_AFTER_AC' => 'AC 后', + 'ALL' => '所有人', + ], + 'default_value' => $problem_extra_config['view_content_type'], +]); +$view_type_form->addSelect('view_all_details_type', [ + 'div_class' => 'row align-items-center g-0 mt-3', + 'label_class' => 'form-label col-auto m-0 flex-grow-1', + 'select_class' => 'col-auto form-select w-auto', + 'label' => '查看全部详细信息', + 'options' => [ + 'NONE' => '禁止', + 'SELF' => '仅自己', + 'ALL_AFTER_AC' => 'AC 后', + 'ALL' => '所有人' + ], + 'default_value' => $problem_extra_config['view_all_details_type'], +]); +$view_type_form->addSelect('view_details_type', [ + 'div_class' => 'row align-items-center g-0 mt-3', + 'label_class' => 'form-label col-auto m-0 flex-grow-1', + 'select_class' => 'col-auto form-select w-auto', + 'label' => '查看测试点详细信息', + 'options' => [ + 'NONE' => '禁止', + 'SELF' => '仅自己', + 'ALL_AFTER_AC' => 'AC 后', + 'ALL' => '所有人', + ], + 'default_value' => $problem_extra_config['view_details_type'], +]); +$view_type_form->handle = function () { + $config = UOJProblem::cur()->getExtraConfig(); + $config['view_content_type'] = $_POST['view_content_type']; + $config['view_all_details_type'] = $_POST['view_all_details_type']; + $config['view_details_type'] = $_POST['view_details_type']; + $esc_config = json_encode($config); + + DB::update([ + "update problems", + "set", ["extra_config" => $esc_config], + "where", ["id" => UOJProblem::info('id')] + ]); +}; +$view_type_form->runAtServer(); + +$solution_view_type_form = new UOJForm('solution_view_type'); +$solution_view_type_form->addSelect('view_solution_type', [ + 'div_class' => 'row align-items-center g-0', + 'label_class' => 'form-label col-auto m-0 flex-grow-1', + 'select_class' => 'col-auto form-select w-auto', + 'label' => '查看题解', + 'options' => [ + 'NONE' => '禁止', + 'ALL_AFTER_AC' => 'AC 后', + 'ALL' => '所有人', + ], + 'default_value' => $problem_extra_config['view_solution_type'], +]); +$solution_view_type_form->addSelect('submit_solution_type', [ + 'div_class' => 'row align-items-center g-0 mt-3', + 'label_class' => 'form-label col-auto m-0 flex-grow-1', + 'select_class' => 'col-auto form-select w-auto', + 'label' => '提交题解', + 'options' => [ + 'NONE' => '禁止', + 'ALL_AFTER_AC' => 'AC 后', + 'ALL' => '所有人', + ], + 'default_value' => $problem_extra_config['submit_solution_type'], +]); +$solution_view_type_form->handle = function () { + $config = UOJProblem::cur()->getExtraConfig(); + $config['view_solution_type'] = $_POST['view_solution_type']; + $config['submit_solution_type'] = $_POST['submit_solution_type']; + $esc_config = json_encode($config); + + DB::update([ + "update problems", + "set", ["extra_config" => $esc_config], + "where", ["id" => UOJProblem::info('id')] + ]); +}; +$solution_view_type_form->runAtServer(); ?> @@ -264,6 +357,24 @@ $difficulty_form->runAtServer(); printHTML() ?> + +
+
+ 提交记录可视权限 +
+
+ printHTML() ?> +
+
+ +
+
+ 题解可视权限 +
+
+ printHTML() ?> +
+