feat: add top 50 rank
chore: adjust recent commit num to 30
This commit is contained in:
@@ -18,10 +18,13 @@
|
|||||||
<div class="crossnote markdown-preview ">
|
<div class="crossnote markdown-preview ">
|
||||||
|
|
||||||
<h1 id="挑战赛数据展示">挑战赛数据展示 </h1>
|
<h1 id="挑战赛数据展示">挑战赛数据展示 </h1>
|
||||||
<p>该页面展示所有提交成功的得分(包括<strong>零分</strong>)。</p>
|
<p>该页面展示<strong>得分前五名</strong>和<strong>最近三十次提交成功</strong>的数据(包括<strong>零分</strong>)。</p>
|
||||||
<p>数据非实时刷新,可能有最长<strong>五分钟</strong>的延迟。</p>
|
<p>数据非实时刷新,可能有最长<strong>五分钟</strong>的延迟。</p>
|
||||||
<p>详细信息点击「查看详情」即可查看。</p>
|
<p>详细信息点击「查看详情」即可查看。</p>
|
||||||
<h2 id="评测结果">评测结果 </h2>
|
<h2 id="前五名排行榜">前五名排行榜 </h2>
|
||||||
|
<p>这里展示<strong>得分前五名</strong>的数据。</p>
|
||||||
|
<p>以得分排序,若分数相同,则运行时间短的靠前。</p>
|
||||||
|
<hr>
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -33,7 +36,35 @@
|
|||||||
<th>详细信息</th>
|
<th>详细信息</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody id="data-table-body">
|
<tbody id="top-data-table-body">
|
||||||
|
<tr>
|
||||||
|
<td>0000-00-00 00:00:00</td>
|
||||||
|
<td>000000000000</td>
|
||||||
|
<td>加载中…</td>
|
||||||
|
<td>00</td>
|
||||||
|
<td>000.000000000ms</td>
|
||||||
|
<td>
|
||||||
|
<button>正在加载</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<h2 id="最近三十条评测结果">最近三十条评测结果 </h2>
|
||||||
|
<p>这里展示<strong>最近三十次提交成功</strong>的数据。</p>
|
||||||
|
<p>以提交时间倒序排序。</p>
|
||||||
|
<hr>
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>时间</th>
|
||||||
|
<th>学号</th>
|
||||||
|
<th>姓名</th>
|
||||||
|
<th>得分</th>
|
||||||
|
<th>运行时间</th>
|
||||||
|
<th>详细信息</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody id="recent-data-table-body">
|
||||||
<tr>
|
<tr>
|
||||||
<td>0000-00-00 00:00:00</td>
|
<td>0000-00-00 00:00:00</td>
|
||||||
<td>000000000000</td>
|
<td>000000000000</td>
|
||||||
|
|||||||
@@ -1,12 +1,18 @@
|
|||||||
# 挑战赛数据展示
|
# 挑战赛数据展示
|
||||||
|
|
||||||
该页面展示所有提交成功的得分(包括**零分**)。
|
该页面展示**得分前五名**和**最近三十次提交成功**的数据(包括**零分**)。
|
||||||
|
|
||||||
数据非实时刷新,可能有最长**五分钟**的延迟。
|
数据非实时刷新,可能有最长**五分钟**的延迟。
|
||||||
|
|
||||||
详细信息点击「查看详情」即可查看。
|
详细信息点击「查看详情」即可查看。
|
||||||
|
|
||||||
## 评测结果
|
## 前五名排行榜
|
||||||
|
|
||||||
|
这里展示**得分前五名**的数据。
|
||||||
|
|
||||||
|
以得分排序,若分数相同,则运行时间短的靠前。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
@@ -19,7 +25,40 @@
|
|||||||
<th>详细信息</th>
|
<th>详细信息</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody id="data-table-body">
|
<tbody id="top-data-table-body">
|
||||||
|
<tr>
|
||||||
|
<td>0000-00-00 00:00:00</td>
|
||||||
|
<td>000000000000</td>
|
||||||
|
<td>加载中…</td>
|
||||||
|
<td>00</td>
|
||||||
|
<td>000.000000000ms</td>
|
||||||
|
<td>
|
||||||
|
<button>正在加载</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
## 最近三十条评测结果
|
||||||
|
|
||||||
|
这里展示**最近三十次提交成功**的数据。
|
||||||
|
|
||||||
|
以提交时间倒序排序。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>时间</th>
|
||||||
|
<th>学号</th>
|
||||||
|
<th>姓名</th>
|
||||||
|
<th>得分</th>
|
||||||
|
<th>运行时间</th>
|
||||||
|
<th>详细信息</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody id="recent-data-table-body">
|
||||||
<tr>
|
<tr>
|
||||||
<td>0000-00-00 00:00:00</td>
|
<td>0000-00-00 00:00:00</td>
|
||||||
<td>000000000000</td>
|
<td>000000000000</td>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
from flask import Flask, request, send_from_directory, abort, jsonify
|
from flask import Flask, request, send_from_directory, abort, jsonify
|
||||||
import csv
|
import csv
|
||||||
|
import datetime
|
||||||
import os
|
import os
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
@@ -87,12 +88,59 @@ def get_scores():
|
|||||||
try:
|
try:
|
||||||
with open(csv_file_path, mode="r", encoding="utf-8") as csvfile:
|
with open(csv_file_path, mode="r", encoding="utf-8") as csvfile:
|
||||||
reader = csv.DictReader(csvfile)
|
reader = csv.DictReader(csvfile)
|
||||||
scores = jsonify(list(reader)[::-1])
|
data = list(reader)
|
||||||
|
# 时间倒序
|
||||||
|
data.sort(
|
||||||
|
key=lambda x: datetime.datetime.strptime(
|
||||||
|
x["time"], "%Y-%m-%d %H:%M:%S"
|
||||||
|
),
|
||||||
|
reverse=True,
|
||||||
|
)
|
||||||
|
scores = jsonify(data[:30])
|
||||||
|
|
||||||
scores.headers.add("Access-Control-Allow-Origin", "*")
|
scores.headers.add("Access-Control-Allow-Origin", "*")
|
||||||
|
scores.headers.add("Cache-Control", "public, max-age=300")
|
||||||
return scores
|
return scores
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return jsonify({"error": str(e)}), 500
|
return jsonify({"error": str(e)}), 500
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/get_top_scores", methods=["GET"])
|
||||||
|
def get_top_scores():
|
||||||
|
try:
|
||||||
|
with open(csv_file_path, mode="r", encoding="utf-8") as csvfile:
|
||||||
|
reader = csv.DictReader(csvfile)
|
||||||
|
scores = list(reader)
|
||||||
|
|
||||||
|
# 数据处理
|
||||||
|
for score in scores:
|
||||||
|
score["score"] = float(score["score"])
|
||||||
|
score["running_time"] = float(score["running_time"].replace("ms", ""))
|
||||||
|
|
||||||
|
# 分数降序,运行时间升序
|
||||||
|
scores_sorted = sorted(
|
||||||
|
scores, key=lambda x: (-x["score"], x["running_time"])
|
||||||
|
)
|
||||||
|
|
||||||
|
# 存储最佳记录
|
||||||
|
best_scores_by_id = {}
|
||||||
|
for score in scores_sorted:
|
||||||
|
student_id = score["id"]
|
||||||
|
if student_id not in best_scores_by_id:
|
||||||
|
best_scores_by_id[student_id] = score
|
||||||
|
|
||||||
|
# 取前五名
|
||||||
|
for score in scores:
|
||||||
|
score["running_time"] = str(score["running_time"]) + "ms"
|
||||||
|
top_scores = list(best_scores_by_id.values())[:5]
|
||||||
|
|
||||||
|
response = jsonify(top_scores)
|
||||||
|
response.headers.add("Access-Control-Allow-Origin", "*")
|
||||||
|
scores.headers.add("Cache-Control", "public, max-age=300")
|
||||||
|
return response
|
||||||
|
except Exception as e:
|
||||||
|
return jsonify({"error": str(e)}), 500
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run(host="0.0.0.0", port=880, debug=True)
|
app.run(host="0.0.0.0", port=880, debug=True)
|
||||||
|
|||||||
+11
-8
@@ -1,9 +1,11 @@
|
|||||||
async function fetchData() {
|
const BACKEND_URL = "https://rank.intcplab.cn";
|
||||||
|
|
||||||
|
async function fetchScoresData(para, inject) {
|
||||||
try {
|
try {
|
||||||
const response = await fetch("https://rank.intcplab.cn/get_scores");
|
const response = await fetch(`${BACKEND_URL}/${para}`);
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
|
||||||
const tableBody = document.getElementById("data-table-body");
|
const tableBody = document.getElementById(`${inject}`);
|
||||||
tableBody.innerHTML = "";
|
tableBody.innerHTML = "";
|
||||||
|
|
||||||
data.forEach((item, index) => {
|
data.forEach((item, index) => {
|
||||||
@@ -16,7 +18,7 @@ async function fetchData() {
|
|||||||
<td>${item.score}</td>
|
<td>${item.score}</td>
|
||||||
<td>${item.running_time}</td>
|
<td>${item.running_time}</td>
|
||||||
<td>
|
<td>
|
||||||
<button onclick="showDetailsModal(${index})">查看详情</button>
|
<button onclick="showDetailsModal('${para}', ${index})">查看详情</button>
|
||||||
</td>
|
</td>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@@ -39,11 +41,11 @@ async function fetchData() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function showDetailsModal(index) {
|
function showDetailsModal(para, index) {
|
||||||
const modal = document.getElementById("detailsModal");
|
const modal = document.getElementById("detailsModal");
|
||||||
const modalDetails = document.getElementById("modal-details");
|
const modalDetails = document.getElementById("modal-details");
|
||||||
|
console.log(para, index);
|
||||||
fetch("https://rank.intcplab.cn/get_scores")
|
fetch(`${BACKEND_URL}/${para}`)
|
||||||
.then((response) => response.json())
|
.then((response) => response.json())
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
modalDetails.innerHTML = data[index].details + "<br><br>";
|
modalDetails.innerHTML = data[index].details + "<br><br>";
|
||||||
@@ -51,4 +53,5 @@ function showDetailsModal(index) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
window.onload = fetchData;
|
window.onload = fetchScoresData("get_top_scores", "top-data-table-body");
|
||||||
|
window.onload = fetchScoresData("get_scores", "recent-data-table-body");
|
||||||
|
|||||||
Reference in New Issue
Block a user