소스 검색

Miscellaneous update regarding contests & ratings

ryp 4 주 전
부모
커밋
f55b735292

BIN
app/controllers/.cloud.php.swo


BIN
app/controllers/.cloud.php.swp


BIN
app/controllers/.problem_set.php.swo


BIN
app/controllers/.submission.php.swp


BIN
app/controllers/.user_msg.php.swo


+ 1 - 1
app/controllers/contest_inside.php

@@ -148,7 +148,7 @@ EOD;
 EOD;
 					}
 					sendSystemMsg($user['username'], 'Rating变化通知', $content);
-					DB::query("update user_info set rating = {$ratings[$i]} where username = '{$standings[$i][2][0]}'");
+					DB::query("update user_info set rating = {$ratings[$i]}, rating_rd = {$rating_rd[$i]}, rating_vol = {$rating_vols[$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']}");

+ 3 - 2
app/controllers/index.php

@@ -1,7 +1,7 @@
 <?php
 $blogs = DB::selectAll("select blogs.id, title, poster, post_time from important_blogs, blogs where is_hidden = 0 and important_blogs.blog_id = blogs.id order by level desc, important_blogs.blog_id desc limit 8");
 $activateusers = DB::selectAll("select submitter, count(*) as cnt from submissions where datediff(now(), submit_time) <= 30 group by submitter order by cnt desc limit 12;");
-$topusers = DB::selectAll("select username, rating, rating_rd, qq, motto from user_info order by rating desc, username asc limit 12;");
+$topusers = DB::selectAll("select u.username, u.rating, u.rating_rd, u.rating_vol, u.motto, u.qq, count(*) cnt from user_info u inner join contests_registrants c on u.username = c.username inner join contests s on s.id = c.contest_id where datediff(now(), s.start_time) <= 180 group by c.username having cnt >= 3 order by rating desc, username asc limit 12;");
 $hotusers = DB::selectAll("select username, rating, rating_rd, rating_vol, qq, motto from user_info order by rating_vol desc, username asc limit 12;");
 $topblogs = DB::selectAll("select id from blogs order by zan desc limit 10;");
 $songs_data = htmlspecialchars(json_encode(DB::selectAll("select * from songs;")), ENT_QUOTES, 'UTF-8');
@@ -330,7 +330,8 @@ $('#recent-contest-countdown-<?= $contest['id'] ?>').countdown(<?= $contest['sta
 </div>
 <div class="row shadow my-4 wyoj-topcard">
 	<div class="col-12 p-4">
-		<h3>比赛排行榜</h3>
+		<h3>比赛排行榜(180天内三场及以上比赛)</h3>
+		<a href="/ranklist">全部排名</a>
 	</div>
 	<?php foreach($topusers as $user): ?>
 		<div class="col-md-3 mb-4">

+ 3 - 1
app/controllers/problem.php

@@ -104,7 +104,7 @@
 			Cookie::set('uoj_preferred_language', $language, time() + 60 * 60 * 24 * 365, '/');
 		}
 		$esc_language = DB::escape($language);
- 		
+
 		$result = array();
 		$result['status'] = "Waiting";
 		$result_json = json_encode($result);
@@ -114,6 +114,8 @@
 		} else {
 			DB::query("insert into submissions (problem_id, submit_time, submitter, content, language, tot_size, status, result, is_hidden) values (${problem['id']}, now(), '${myUser['username']}', '$esc_content', '$esc_language', $tot_size, '${result['status']}', '$result_json', {$problem['is_hidden']})");
 		}
+
+#		file_get_contents("http://localhost:24270/submit");
 	}
 	function handleCustomTestUpload($zip_file_name, $content, $tot_size) {
 		global $problem, $contest, $myUser;

+ 1 - 0
app/controllers/ranklist.php

@@ -6,5 +6,6 @@
 	}
 ?>
 <?php echoUOJPageHeader('比赛排行榜') ?>
+<h4>只显示最近 180 天内参与场数大于等于 3 场的选手</h4>
 <?php echoRanklist($config) ?>
 <?php echoUOJPageFooter() ?>

BIN
app/controllers/subdomain/blog/.archive.php.swp


+ 2 - 2
app/controllers/subdomain/blog/blog.php

@@ -81,8 +81,8 @@
 			if (!$comment) {
 				return '评论不能为空';
 			}
-			if (strlen($comment) > 140) {
-				return '不能超过140个字节';
+			if (strlen($comment) > 500) {
+				return '不能超过500个字节';
 			}
 			return '';
 		},

+ 0 - 4
app/controllers/super_manage.php

@@ -26,11 +26,8 @@
 			$contest = queryContest($id);
 			genMoreContestInfo($contest);
 			if (isset($contest['extra_config']['unrated'])) continue;
-			error_log("Recalculating contest rating: $id {$contest['name']}");
-			error_log(print_r($contest, true));
 
 			$contest_data = queryContestData($contest);
-			error_log(print_r($contest_data, true));
 			$score = array();
 			$standings = array();
 			$ratings = array();
@@ -40,7 +37,6 @@
 			calcRatingGlicko2($standings, $ratings, $rating_rds, $rating_vols);
 
 			for ($i = 0; $i < count($standings); ++$i) {
-				error_log("New rating for $i {$ratings[$i]}, {$rating_rds[$i]}");
 				DB::update("update user_info set rating = {$ratings[$i]}, rating_rd = {$rating_rds[$i]}, rating_vol = {$rating_vols[$i]} where username = '{$standings[$i][2][0]}';");
 			}
 		}

BIN
app/libs/.uoj-html-lib.php.swo


BIN
app/libs/.uoj-query-lib.php.swo


+ 15 - 10
app/libs/uoj-html-lib.php

@@ -1301,19 +1301,21 @@ function echoRanklist($config = array()) {
 	$header_row .= '</tr>';
 	
 	$users = array();
-	$print_row = function($user, $now_cnt) use (&$users) {
-		if (!$users) {
+	$relcnt = 0;
+	$print_row = function($user, $now_cnt) use (&$users, &$relcnt) {
+		#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;
-		}
+#		} elseif ($user['rating'] == $users[count($users) - 1]['rating']) {
+#			$rank = $users[count($users) - 1]['rank'];
+#		} else {
+#			$rank = $now_cnt;
+#		}
 		
 		$user['rank'] = $rank;
+		$relcnt++;
 		
 		echo '<tr>';
-		echo '<td>' . $user['rank'] . '</td>';
+		echo '<td>' . $user['rank'] . ' (' . $relcnt . ')</td>';
 		echo '<td>' . getAvatar($user) . '</td>';
 		echo '<td>' . getUserLink($user['username']) . '</td>';
 		echo '<td>' . HTML::escape($user['motto']) . '</td>';
@@ -1322,8 +1324,11 @@ function echoRanklist($config = array()) {
 		
 		$users[] = $user;
 	};
-	$col_names = array('username', 'email', 'qq', 'rating', 'motto', 'rating_rd');
-	$tail = 'order by rating desc, username asc';
+	$col_names = array('username', 'email', 'qq', 'rating', 'motto');
+	$tail = 'inner join contests_registrants c on user_info.username = c.username inner join contests s on s.id = c.contest_id where datediff(now(), s.start_time) <= 180 group by c.username having cnt >= 3 order by rating desc, username asc';
+	#	$tail = 'order by rating desc, username asc';
+	#
+	$config['raw_sql'] = 'select u.username, u.email, u.rating, u.rating_rd, u.rating_vol, u.motto, u.qq, count(*) cnt from user_info u inner join contests_registrants c on u.username = c.username inner join contests s on s.id = c.contest_id where datediff(now(), s.start_time) <= 180 group by c.username having cnt >= 3 order by rating desc, username asc';
 	
 	if (isset($config['top10'])) {
 		$tail .= ' limit 10';

+ 22 - 5
app/models/Paginator.php

@@ -16,8 +16,15 @@ class Paginator {
 			$this->cur_start = 0;
 			$this->table = $config['data'];
 		} elseif (!isset($config['echo_full'])) {
-			$this->n_rows = DB::selectCount("select count(*) from {$config['table_name']} where {$config['cond']}");
-			
+			if (!isset($config['raw_sql'])) {
+				$this->n_rows = DB::selectCount("select count(*) from {$config['table_name']} where {$config['cond']}");
+			}
+			else {
+				$this->table = DB::selectAll($config['raw_sql']);
+				$this->n_rows = count($this->table);
+			}
+
+			# 这里有一个潜在 bug,晚点修。
 			$this->page_len = isset($config['page_len']) ? $config['page_len'] : 10;
 			
 			$this->n_pages = max((int)ceil($this->n_rows / $this->page_len), 1);
@@ -29,13 +36,23 @@ class Paginator {
 				$this->cur_page = $this->n_pages;
 			}
 			$this->cur_start = ($this->cur_page - 1) * $this->page_len;
-	
-			$this->table = DB::selectAll("select ".join($config['col_names'], ',')." from {$config['table_name']} where {$config['cond']} {$config['tail']} limit {$this->cur_start}, {$this->page_len}");
+
+			if (!isset($config['raw_sql'])) {
+				$this->table = DB::selectAll("select ".join($config['col_names'], ',')." from {$config['table_name']} where {$config['cond']} {$config['tail']} limit {$this->cur_start}, {$this->page_len}");
+			}
+			else {
+				$this->table = DB::selectAll($config['raw_sql']);
+				$this->n_rows = count($this->table);
+			}
+
 		} else {
 			$this->n_pages = 1;
 			$this->cur_page = 1;
 			$this->cur_start = ($this->cur_page - 1) * $this->page_len;
-			$this->table = DB::selectAll("select ".join($config['col_names'], ',')." from {$config['table_name']} where {$config['cond']} {$config['tail']}");
+			if (isset($config['raw_sql']))
+				$this->table = DB::selectAll("select ".join($config['col_names'], ',')." from {$config['table_name']} where {$config['cond']} {$config['tail']}");
+			else
+				$this->table = DB::selectAll($config['raw_sql']);
 		}
 		
 		$this->max_extend = isset($config['max_extend']) ? (int)$config['max_extend'] : 5;

BIN
app/views/.blog-preview.php.swp


+ 21 - 0
app/views/page-footer.php

@@ -25,6 +25,27 @@
 			<?php endif ?>
 		</div>
 		</div>
+
+<!--
+<script 
+  data-host-id="1" 
+  data-auto-reg="true" 
+  data-login-token="" 
+  data-title="" 
+  data-logo="" 
+  data-theme-color="#1fe1f9" 
+  data-close-width="48" 
+  data-close-height="48" 
+  data-open-width="380" 
+  data-open-height="680" 
+  data-welcome="请在这里留言" 
+  data-popup-title="需要联系管理员?" 
+  data-popup-subtitle="快来这里联系我们" 
+  data-popup-image="" 
+  data-popup-closable="true" 
+  src="https://x.ryp.org.cn/widget.js" 
+  async 
+></script>-->
 		<!-- /container -->
 	</body>
 </html>