From 2f4ed55d9dd0477a80fdda692ffbfd87ff779399 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Thu, 17 Mar 2022 11:02:44 +0800 Subject: [PATCH] feat(*): remove rating --- db/app_uoj233.sql | 3 - web/app/controllers/contest_inside.php | 26 +--- web/app/controllers/contest_manage.php | 49 +----- web/app/controllers/contest_members.php | 39 +---- web/app/controllers/contest_registration.php | 4 +- web/app/controllers/index.php | 9 -- web/app/controllers/ranklist.php | 6 +- web/app/controllers/subdomain/blog/blog.php | 3 - web/app/controllers/user_info.php | 153 +------------------ web/app/libs/uoj-contest-lib.php | 100 +----------- web/app/libs/uoj-html-lib.php | 50 +----- web/app/locale/basic/en.php | 3 - web/app/locale/basic/zh-cn.php | 3 - web/app/models/HTML.php | 1 - web/app/route.php | 1 - web/app/views/page-header.php | 12 +- web/js/jquery.flot.canvas.min.js | 7 - web/js/jquery.flot.categories.min.js | 7 - web/js/jquery.flot.crosshair.min.js | 7 - web/js/jquery.flot.errorbars.min.js | 7 - web/js/jquery.flot.fillbetween.min.js | 7 - web/js/jquery.flot.image.min.js | 7 - web/js/jquery.flot.min.js | 8 - web/js/jquery.flot.navigate.min.js | 7 - web/js/jquery.flot.pie.min.js | 7 - web/js/jquery.flot.resize.min.js | 7 - web/js/jquery.flot.selection.min.js | 7 - web/js/jquery.flot.stack.min.js | 7 - web/js/jquery.flot.symbol.min.js | 7 - web/js/jquery.flot.threshold.min.js | 7 - web/js/jquery.flot.time.min.js | 7 - web/js/uoj.js | 75 +-------- 32 files changed, 29 insertions(+), 614 deletions(-) delete mode 100644 web/js/jquery.flot.canvas.min.js delete mode 100644 web/js/jquery.flot.categories.min.js delete mode 100644 web/js/jquery.flot.crosshair.min.js delete mode 100644 web/js/jquery.flot.errorbars.min.js delete mode 100644 web/js/jquery.flot.fillbetween.min.js delete mode 100644 web/js/jquery.flot.image.min.js delete mode 100644 web/js/jquery.flot.min.js delete mode 100644 web/js/jquery.flot.navigate.min.js delete mode 100644 web/js/jquery.flot.pie.min.js delete mode 100644 web/js/jquery.flot.resize.min.js delete mode 100644 web/js/jquery.flot.selection.min.js delete mode 100644 web/js/jquery.flot.stack.min.js delete mode 100644 web/js/jquery.flot.symbol.min.js delete mode 100644 web/js/jquery.flot.threshold.min.js delete mode 100644 web/js/jquery.flot.time.min.js diff --git a/db/app_uoj233.sql b/db/app_uoj233.sql index b20be87..ec27022 100644 --- a/db/app_uoj233.sql +++ b/db/app_uoj233.sql @@ -291,7 +291,6 @@ UNLOCK TABLES; /*!40101 SET character_set_client = utf8mb4 */; CREATE TABLE `contests_registrants` ( `username` varchar(20) NOT NULL, - `user_rating` int(11) NOT NULL, `contest_id` int(11) NOT NULL, `has_participated` tinyint(1) NOT NULL, `rank` int(11) NOT NULL, @@ -622,7 +621,6 @@ CREATE TABLE `user_info` ( `email` varchar(50) NOT NULL, `password` char(32) NOT NULL, `svn_password` char(10) NOT NULL, - `rating` int(11) NOT NULL DEFAULT '1500', `qq` bigint(20) NOT NULL, `sex` char(1) NOT NULL DEFAULT 'U', `ac_num` int(11) NOT NULL, @@ -632,7 +630,6 @@ CREATE TABLE `user_info` ( `remember_token` char(60) NOT NULL, `motto` varchar(200) NOT NULL, PRIMARY KEY (`username`), - KEY `rating` (`rating`,`username`), KEY `ac_num` (`ac_num`,`username`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4; /*!40101 SET character_set_client = @saved_cs_client */; diff --git a/web/app/controllers/contest_inside.php b/web/app/controllers/contest_inside.php index b705e73..0d488b0 100644 --- a/web/app/controllers/contest_inside.php +++ b/web/app/controllers/contest_inside.php @@ -120,35 +120,11 @@ global $contest; $contest_data = queryContestData($contest); calcStandings($contest, $contest_data, $score, $standings, true); - if (!isset($contest['extra_config']['unrated'])) { - $rating_k = isset($contest['extra_config']['rating_k']) ? $contest['extra_config']['rating_k'] : 400; - $ratings = calcRating($standings, $rating_k); - } else { - $ratings = array(); - for ($i = 0; $i < count($standings); $i++) { - $ratings[$i] = $standings[$i][2][1]; - } - } for ($i = 0; $i < count($standings); $i++) { $user = queryUser($standings[$i][2][0]); - $change = $ratings[$i] - $user['rating']; $user_link = getUserLink($user['username']); - if ($change != 0) { - $tail = '' . ($change > 0 ? '+' : '') . $change . ''; - $content = <<${user_link} 您好:

-

您在 {$contest['name']} 这场比赛后的Rating变化为${tail},当前Rating为 {$ratings[$i]}

-EOD; - } else { - $content = <<${user_link} 您好:

-

您在 {$contest['name']} 这场比赛后Rating没有变化。当前Rating为 {$ratings[$i]}

-EOD; - } - sendSystemMsg($user['username'], 'Rating变化通知', $content); - DB::query("update user_info set rating = {$ratings[$i]} where username = '{$standings[$i][2][0]}'"); DB::query("update contests_registrants set rank = {$standings[$i][3]} where contest_id = {$contest['id']} and username = '{$standings[$i][2][0]}'"); } DB::query("update contests set status = 'finished' where id = {$contest['id']}"); @@ -550,4 +526,4 @@ EOD; - \ No newline at end of file + diff --git a/web/app/controllers/contest_manage.php b/web/app/controllers/contest_manage.php index 1958de9..64842dc 100644 --- a/web/app/controllers/contest_manage.php +++ b/web/app/controllers/contest_manage.php @@ -116,43 +116,6 @@ ); if (isSuperUser($myUser)) { - $rating_k_form = new UOJForm('rating_k'); - $rating_k_form->addInput('rating_k', 'text', 'rating 变化上限', isset($contest['extra_config']['rating_k']) ? $contest['extra_config']['rating_k'] : 400, - function ($x) { - if (!validateUInt($x) || $x < 1 || $x > 1000) { - return '不合法的上限'; - } - return ''; - }, - null - ); - $rating_k_form->handle = function() { - global $contest; - $contest['extra_config']['rating_k'] = $_POST['rating_k']; - $esc_extra_config = json_encode($contest['extra_config']); - $esc_extra_config = DB::escape($esc_extra_config); - DB::update("update contests set extra_config = '$esc_extra_config' where id = {$contest['id']}"); - }; - $rating_k_form->runAtServer(); - - $rated_form = new UOJForm('rated'); - $rated_form->handle = function() { - global $contest; - if (isset($contest['extra_config']['unrated'])) { - unset($contest['extra_config']['unrated']); - } else { - $contest['extra_config']['unrated'] = ''; - } - $esc_extra_config = json_encode($contest['extra_config']); - $esc_extra_config = DB::escape($esc_extra_config); - DB::update("update contests set extra_config = '$esc_extra_config' where id = {$contest['id']}"); - }; - $rated_form->submit_button_config['class_str'] = 'btn btn-warning btn-block'; - $rated_form->submit_button_config['text'] = isset($contest['extra_config']['unrated']) ? '设置比赛为rated' : '设置比赛为unrated'; - $rated_form->submit_button_config['smart_confirm'] = ''; - - $rated_form->runAtServer(); - $version_form = new UOJForm('version'); $version_form->addInput('standings_version', 'text', '排名版本', $contest['extra_config']['standings_version'], function ($x) { @@ -260,16 +223,6 @@
-
-

Rating控制

-
-
- printHTML(); ?> -
-
-
- printHTML(); ?> -

版本控制

printHTML(); ?> @@ -282,4 +235,4 @@
- \ No newline at end of file + diff --git a/web/app/controllers/contest_members.php b/web/app/controllers/contest_members.php index a37934d..d4dbd1a 100644 --- a/web/app/controllers/contest_members.php +++ b/web/app/controllers/contest_members.php @@ -5,7 +5,7 @@ become404Page(); } genMoreContestInfo($contest); - + $has_contest_permission = hasContestPermission($myUser, $contest); $show_ip = $has_contest_permission; @@ -25,23 +25,6 @@ $unregister_form->runAtServer(); } - - if ($has_contest_permission) { - $pre_rating_form = new UOJForm('pre_rating'); - $pre_rating_form->handle = function() { - global $contest; - foreach (DB::selectAll("select * from contests_registrants where contest_id = {$contest['id']}") as $reg) { - $user = queryUser($reg['username']); - DB::update("update contests_registrants set user_rating = {$user['rating']} where contest_id = {$contest['id']} and username = '{$user['username']}'"); - } - }; - $pre_rating_form->submit_button_config['align'] = 'right'; - $pre_rating_form->submit_button_config['class_str'] = 'btn btn-warning'; - $pre_rating_form->submit_button_config['text'] = '重新计算参赛前的 rating'; - $pre_rating_form->submit_button_config['smart_confirm'] = ''; - - $pre_rating_form->runAtServer(); - } } ?> @@ -61,25 +44,25 @@ #'.UOJLocale::get('username').'remote_addrrating'; + $header_row = '#'.UOJLocale::get('username').'remote_addr'; $ip_owner = array(); - foreach (DB::selectAll("select * from contests_registrants where contest_id = {$contest['id']} order by user_rating asc") as $reg) { + foreach (DB::selectAll("select * from contests_registrants where contest_id = {$contest['id']} order by username desc") as $reg) { $user = queryUser($reg['username']); $ip_owner[$user['remote_addr']] = $reg['username']; } } else { - $header_row = '#'.UOJLocale::get('username').'rating'; + $header_row = '#'.UOJLocale::get('username').''; } - echoLongTable(array('*'), 'contests_registrants', "contest_id = {$contest['id']}", 'order by user_rating desc', + echoLongTable(array('*'), 'contests_registrants', "contest_id = {$contest['id']}", 'order by username desc', $header_row, function($contest, $num) { global $myUser; global $show_ip, $ip_owner; $user = queryUser($contest['username']); - $user_link = getUserLink($contest['username'], $contest['user_rating']); + $user_link = getUserLink($contest['username']); if (!$show_ip) { echo ''; } else { @@ -94,18 +77,12 @@ if ($show_ip) { echo ''.$user['remote_addr'].''; } - echo ''.$contest['user_rating'].''; echo ''; }, array('page_len' => 100, 'get_row_index' => '', - 'print_after_table' => function() { - global $pre_rating_form; - if (isset($pre_rating_form)) { - $pre_rating_form->printHTML(); - } - } + 'print_after_table' => function() {} ) ); ?> - \ No newline at end of file + diff --git a/web/app/controllers/contest_registration.php b/web/app/controllers/contest_registration.php index 99c1a16..f5a0820 100644 --- a/web/app/controllers/contest_registration.php +++ b/web/app/controllers/contest_registration.php @@ -14,7 +14,7 @@ $register_form = new UOJForm('register'); $register_form->handle = function() { global $myUser, $contest; - DB::query("insert into contests_registrants (username, user_rating, contest_id, has_participated) values ('{$myUser['username']}', {$myUser['rating']}, {$contest['id']}, 0)"); + DB::query("insert into contests_registrants (username, contest_id, has_participated) values ('{$myUser['username']}', {$contest['id']}, 0)"); updateContestPlayerNum($contest); }; $register_form->submit_button_config['class_str'] = 'btn btn-primary'; @@ -26,7 +26,7 @@

比赛规则

    -
  • 比赛报名后不算正式参赛,报名后进了比赛页面也不算参赛,看了题目才算正式参赛。如果未正式参赛则不算rating。
  • +
  • 比赛报名后不算正式参赛,报名后进了比赛页面也不算参赛,看了题目才算正式参赛
  • 比赛中途可以提交,若同一题有多次提交按最后一次不是Compile Error的提交算成绩。(其实UOJ会自动无视你所有Compile Error的提交当作没看见)
  • 比赛中途提交后,可以看到测样例的结果。(若为提交答案题则对于每个测试点,该测试点有分则该测试点为满分)
  • 比赛结束后会进行最终测试,最终测试后的排名为最终排名。
  • diff --git a/web/app/controllers/index.php b/web/app/controllers/index.php index 7f72341..93cb398 100644 --- a/web/app/controllers/index.php +++ b/web/app/controllers/index.php @@ -43,13 +43,4 @@
-
-
-

- '', 'top10' => '')) ?> -
- -
-
-
diff --git a/web/app/controllers/ranklist.php b/web/app/controllers/ranklist.php index e38ee9c..3c7a104 100644 --- a/web/app/controllers/ranklist.php +++ b/web/app/controllers/ranklist.php @@ -1,9 +1,5 @@ 100); - } else { - become404Page(); - } + become404Page(); ?> diff --git a/web/app/controllers/subdomain/blog/blog.php b/web/app/controllers/subdomain/blog/blog.php index dc32234..b0bf254 100644 --- a/web/app/controllers/subdomain/blog/blog.php +++ b/web/app/controllers/subdomain/blog/blog.php @@ -154,9 +154,6 @@ $asrc = HTML::avatar_addr($poster, 80); $replies = DB::selectAll("select id, poster, content, post_time from blogs_comments where reply_id = {$comment['id']} order by id"); - foreach ($replies as $idx => $reply) { - $replies[$idx]['poster_rating'] = queryUser($reply['poster'])['rating']; - } $replies_json = json_encode($replies); ?>
diff --git a/web/app/controllers/user_info.php b/web/app/controllers/user_info.php index 5daf415..dd4b67f 100644 --- a/web/app/controllers/user_info.php +++ b/web/app/controllers/user_info.php @@ -1,7 +1,5 @@ @@ -30,12 +28,8 @@ <?= $user['username'] ?> Avatar
-

+

-
-

-

-

@@ -77,10 +71,6 @@
-
-

-
-
-
diff --git a/web/app/libs/uoj-contest-lib.php b/web/app/libs/uoj-contest-lib.php index bac6f04..a15f90d 100644 --- a/web/app/libs/uoj-contest-lib.php +++ b/web/app/libs/uoj-contest-lib.php @@ -5,99 +5,6 @@ define("CONTEST_PENDING_FINAL_TEST", 2); define("CONTEST_TESTING", 10); define("CONTEST_FINISHED", 20); -function calcRating($standings, $K = 400) { - $DELTA = 500; - - $n = count($standings); - - $rating = array(); - for ($i = 0; $i < $n; ++$i) { - $rating[$i] = $standings[$i][2][1]; - } - - $rank = array(); - $foot = array(); - for ($i = 0; $i < $n; ) { - $j = $i; - while ($j + 1 < $n && $standings[$j + 1][3] == $standings[$j][3]) { - ++$j; - } - $our_rk = 0.5 * (($i + 1) + ($j + 1)); - while ($i <= $j) { - $rank[$i] = $our_rk; - $foot[$i] = $n - $rank[$i]; - $i++; - } - } - - $weight = array(); - for ($i = 0; $i < $n; ++$i) { - $weight[$i] = pow(7, $rating[$i] / $DELTA); - } - $exp = array_fill(0, $n, 0); - for ($i = 0; $i < $n; ++$i) { - for ($j = 0; $j < $n; ++$j) { - if ($j != $i) { - $exp[$i] += $weight[$i] / ($weight[$i] + $weight[$j]); - } - } - } - - $new_rating = array(); - for ($i = 0; $i < $n; $i++) { - $new_rating[$i] = $rating[$i]; - $new_rating[$i] += ceil($K * ($foot[$i] - $exp[$i]) / ($n - 1)); - } - - for ($i = $n - 1; $i >= 0; $i--) { - if ($i + 1 < $n && $standings[$i][3] != $standings[$i + 1][3]) { - break; - } - if ($new_rating[$i] > $rating[$i]) { - $new_rating[$i] = $rating[$i]; - } - } - - for ($i = 0; $i < $n; $i++) { - if ($new_rating[$i] < 0) { - $new_rating[$i] = 0; - } - } - - return $new_rating; -} - -function calcRatingSelfTest() { - $tests = [ - [[1500, 1], [1500, 1]], - [[1500, 1], [1600, 1]], - [[1500, 1], [1600, 2], [1600, 2]], - [[1500, 1], [200, 2], [100, 2]], - [[1500, 1], [100, 2], [200, 2]], - [[1500, 1], [100, 2], [200, 3]], - [[1500, 1], [200, 2], [100, 3]], - [[1500, 1], [3000, 2], [1500, 3]], - [[1500, 1], [3000, 2], [1500, 3], [1500, 3]], - [[1500, 1], [1500, 2], [1500, 3], [3000, 4]], - [[1500, 1], [1500, 2], [10, 3], [1, 4]] - ]; - foreach ($tests as $test_num => $test) { - print "test #{$test_num}\n"; - - $standings = array(); - $n = count($test); - for ($i = 0; $i < $n; $i++) { - $standings[] = [0, 0, [(string)$i, $test[$i][0]], $test[$i][1]]; - } - $new_rating = calcRating($standings); - - for ($i = 0; $i < $n; $i++) { - printf("%3d: %4d -> %4d delta: %+4d\n", $test[$i][1], $test[$i][0], $new_rating[$i], $new_rating[$i] - $test[$i][0]); - } - print "\n"; - } -} - function genMoreContestInfo(&$contest) { $contest['start_time_str'] = $contest['start_time']; $contest['start_time'] = new DateTime($contest['start_time']); @@ -130,7 +37,7 @@ function updateContestPlayerNum($contest) { // problems: pos => id // data : id, submit_time, submitter, problem_pos, score -// people : username, user_rating +// people : username function queryContestData($contest, $config = array()) { mergeConfig($config, [ 'pre_final' => false @@ -175,9 +82,8 @@ function queryContestData($contest, $config = array()) { } $people = []; - $result = DB::query("select username, user_rating from contests_registrants where contest_id = {$contest['id']} and has_participated = 1"); + $result = DB::query("select username from contests_registrants where contest_id = {$contest['id']} and has_participated = 1"); while ($row = DB::fetch($result, MYSQLI_NUM)) { - $row[1] = (int)$row[1]; $people[] = $row; } @@ -202,7 +108,7 @@ function calcStandings($contest, $contest_data, &$score, &$standings, $update_co $score[$submission[2]][$submission[3]] = array($submission[4], $penalty, $submission[0]); } - // standings: rank => score, penalty, [username, user_rating], virtual_rank + // standings: rank => score, penalty, [username], virtual_rank $standings = array(); foreach ($contest_data['people'] as $person) { $cur = array(0, 0, $person); diff --git a/web/app/libs/uoj-html-lib.php b/web/app/libs/uoj-html-lib.php index c9c2280..68438ef 100644 --- a/web/app/libs/uoj-html-lib.php +++ b/web/app/libs/uoj-html-lib.php @@ -11,7 +11,7 @@ function uojHandleAtSign($str, $uri) { return $matches[0]; } else { $referrers[$user['username']] = ''; - return '@'.$user['username'].''; + return '@'.$user['username'].''; } } }, $str); @@ -74,12 +74,9 @@ function become403Page() { becomeMsgPage('
403

禁止入内! T_T

', '403'); } -function getUserLink($username, $rating = null) { +function getUserLink($username) { if (validateUsername($username) && ($user = queryUser($username))) { - if ($rating == null) { - $rating = $user['rating']; - } - return ''.$username.''; + return ''.$username.''; } else { $esc_username = HTML::escape($username); return ''.$esc_username.''; @@ -1030,44 +1027,3 @@ function echoUOJPageHeader($page_title, $extra_config = array()) { function echoUOJPageFooter($config = array()) { uojIncludeView('page-footer', $config); } - -function echoRanklist($config = array()) { - $header_row = ''; - $header_row .= ''; - $header_row .= '#'; - $header_row .= ''.UOJLocale::get('username').''; - $header_row .= ''.UOJLocale::get('motto').''; - $header_row .= ''.UOJLocale::get('rating').''; - $header_row .= ''; - - $users = array(); - $print_row = function($user, $now_cnt) use (&$users) { - if (!$users) { - $rank = DB::selectCount("select count(*) from user_info where rating > {$user['rating']}") + 1; - } elseif ($user['rating'] == $users[count($users) - 1]['rating']) { - $rank = $users[count($users) - 1]['rank']; - } else { - $rank = $now_cnt; - } - - $user['rank'] = $rank; - - echo ''; - echo '' . $user['rank'] . ''; - echo '' . getUserLink($user['username']) . ''; - echo '' . HTML::escape($user['motto']) . ''; - echo '' . $user['rating'] . ''; - echo ''; - - $users[] = $user; - }; - $col_names = array('username', 'rating', 'motto'); - $tail = 'order by rating desc, username asc'; - - if (isset($config['top10'])) { - $tail .= ' limit 10'; - } - - $config['get_row_index'] = ''; - echoLongTable($col_names, 'user_info', '1', $tail, $header_row, $print_row, $config); -} diff --git a/web/app/locale/basic/en.php b/web/app/locale/basic/en.php index 3c6b5f7..d25f823 100644 --- a/web/app/locale/basic/en.php +++ b/web/app/locale/basic/en.php @@ -17,7 +17,6 @@ return [ 'all the announcements' => 'All the Announcements……', 'help' => 'Help', 'search' => 'Search', - 'top rated' => 'Top rated', 'username' => 'Username', 'password' => 'Password', 'new password' => 'New password', @@ -26,7 +25,6 @@ return [ 'QQ' => 'QQ', 'sex' => 'Sex', 'motto' => 'Motto', - 'rating' => 'Rating', 'view all' => 'View all', 'appraisal' => 'Appraisal', 'submit' => 'Submit', @@ -46,7 +44,6 @@ return [ 'visit his blog' => function($name) { return "Visit $name's blog"; }, - 'rating changes' => 'Rating changes', 'accepted problems' => 'Accepted problems', 'n problems in total' => function($n) { return "$n ".($n <= 1 ? 'problem' : 'problems'); diff --git a/web/app/locale/basic/zh-cn.php b/web/app/locale/basic/zh-cn.php index aa992f0..837d78e 100644 --- a/web/app/locale/basic/zh-cn.php +++ b/web/app/locale/basic/zh-cn.php @@ -17,7 +17,6 @@ return [ 'all the announcements' => '所有公告……', 'help' => '帮助', 'search' => '搜索', - 'top rated' => '比赛排行榜', 'username' => '用户名', 'password' => '密码', 'new password' => '新密码', @@ -26,7 +25,6 @@ return [ 'QQ' => 'QQ', 'sex' => '性别', 'motto' => '格言', - 'rating' => 'Rating', 'view all' => '查看全部', 'appraisal' => '评价', 'submit' => '提交', @@ -46,7 +44,6 @@ return [ 'visit his blog' => function($name) { return "访问 $name 的博客"; }, - 'rating changes' => 'Rating 变化', 'accepted problems' => 'AC 过的题目', 'n problems in total' => function($n) { return "共 $n 道题"; diff --git a/web/app/models/HTML.php b/web/app/models/HTML.php index 509e08c..e3fda9f 100644 --- a/web/app/models/HTML.php +++ b/web/app/models/HTML.php @@ -152,7 +152,6 @@ class HTML { //$config->set('HTML.Doctype', 'HTML 4.01 Transitional'); $config->set('Cache.DefinitionImpl', null); $def = $config->getHTMLDefinition(true); - $def->addAttribute('span', 'data-rating', 'Number'); $def->addElement('section', 'Block', 'Flow', 'Common'); $def->addElement('nav', 'Block', 'Flow', 'Common'); diff --git a/web/app/route.php b/web/app/route.php index e406692..06fdb99 100644 --- a/web/app/route.php +++ b/web/app/route.php @@ -48,7 +48,6 @@ Route::group([ Route::any('/announcements', '/announcements.php'); Route::any('/faq', '/faq.php'); - Route::any('/ranklist', '/ranklist.php?type=rating'); Route::any('/captcha', '/captcha.php'); Route::any('/login', '/login.php'); diff --git a/web/app/views/page-header.php b/web/app/views/page-header.php index 11d1ea1..79d2d99 100644 --- a/web/app/views/page-header.php +++ b/web/app/views/page-header.php @@ -166,16 +166,6 @@ - - - - - - - - @@ -242,7 +232,7 @@