diff --git a/RANK.html b/RANK.html index 65096d9..b383178 100644 --- a/RANK.html +++ b/RANK.html @@ -18,10 +18,13 @@
该页面展示所有提交成功的得分(包括零分)。
+该页面展示得分前五名和最近三十次提交成功的数据(包括零分)。
数据非实时刷新,可能有最长五分钟的延迟。
详细信息点击「查看详情」即可查看。
-这里展示得分前五名的数据。
+以得分排序,若分数相同,则运行时间短的靠前。
+| 详细信息 | |||||
|---|---|---|---|---|---|
| 0000-00-00 00:00:00 | +000000000000 | +加载中… | +00 | +000.000000000ms | ++ + | +
这里展示最近三十次提交成功的数据。
+以提交时间倒序排序。
+| 时间 | +学号 | +姓名 | +得分 | +运行时间 | +详细信息 | +||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0000-00-00 00:00:00 | 000000000000 | diff --git a/RANK.md b/RANK.md index 4faf87c..9b167a3 100644 --- a/RANK.md +++ b/RANK.md @@ -1,12 +1,18 @@ # 挑战赛数据展示 -该页面展示所有提交成功的得分(包括**零分**)。 +该页面展示**得分前五名**和**最近三十次提交成功**的数据(包括**零分**)。 数据非实时刷新,可能有最长**五分钟**的延迟。 详细信息点击「查看详情」即可查看。 -## 评测结果 +## 前五名排行榜 + +这里展示**得分前五名**的数据。 + +以得分排序,若分数相同,则运行时间短的靠前。 + +---
| 详细信息 | - + +|||||
|---|---|---|---|---|---|
| 0000-00-00 00:00:00 | +000000000000 | +加载中… | +00 | +000.000000000ms | ++ + | +
| 时间 | +学号 | +姓名 | +得分 | +运行时间 | +详细信息 | +
|---|---|---|---|---|---|
| 0000-00-00 00:00:00 | 000000000000 | diff --git a/app.py b/app.py index 1169982..8533bb5 100644 --- a/app.py +++ b/app.py @@ -1,5 +1,6 @@ from flask import Flask, request, send_from_directory, abort, jsonify import csv +import datetime import os app = Flask(__name__) @@ -87,12 +88,59 @@ def get_scores(): try: with open(csv_file_path, mode="r", encoding="utf-8") as 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("Cache-Control", "public, max-age=300") return scores except Exception as e: 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__": app.run(host="0.0.0.0", port=880, debug=True) diff --git a/get_scores.js b/get_scores.js index 6139d03..782db5b 100644 --- a/get_scores.js +++ b/get_scores.js @@ -1,9 +1,11 @@ -async function fetchData() { +const BACKEND_URL = "https://rank.intcplab.cn"; + +async function fetchScoresData(para, inject) { try { - const response = await fetch("https://rank.intcplab.cn/get_scores"); + const response = await fetch(`${BACKEND_URL}/${para}`); const data = await response.json(); - const tableBody = document.getElementById("data-table-body"); + const tableBody = document.getElementById(`${inject}`); tableBody.innerHTML = ""; data.forEach((item, index) => { @@ -16,7 +18,7 @@ async function fetchData() {${item.score} | ${item.running_time} | - + | `; @@ -39,11 +41,11 @@ async function fetchData() { } } -function showDetailsModal(index) { +function showDetailsModal(para, index) { const modal = document.getElementById("detailsModal"); const modalDetails = document.getElementById("modal-details"); - - fetch("https://rank.intcplab.cn/get_scores") + console.log(para, index); + fetch(`${BACKEND_URL}/${para}`) .then((response) => response.json()) .then((data) => { modalDetails.innerHTML = data[index].details + "