feat: update sort_by_id rule
This commit is contained in:
+8
-7
@@ -38,14 +38,15 @@ def sort_by_id(data, limit=True):
|
||||
# 学号升序,分数降序,运行时间升序
|
||||
sorted_data = sorted(data, key=lambda x: (x["id"], -x["score"], x["running_time"]))
|
||||
|
||||
# 字典去重
|
||||
unique_students = {}
|
||||
for record in sorted_data:
|
||||
id = record["id"]
|
||||
if id not in unique_students:
|
||||
unique_students[id] = record
|
||||
# 按照姓名@学号唯一去重
|
||||
unique_students = []
|
||||
unique_students_id_name = set()
|
||||
for score in sorted_data:
|
||||
if f"{score['name']}@{score["id"]}" not in unique_students_id_name:
|
||||
unique_students.append(score)
|
||||
unique_students_id_name.add(f"{score['name']}@{score["id"]}")
|
||||
|
||||
return list(unique_students.values())[
|
||||
return unique_students[
|
||||
: len(unique_students) if limit == True else abs(limit) : (
|
||||
1 if limit > 0 else -1
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user