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"]))
|
sorted_data = sorted(data, key=lambda x: (x["id"], -x["score"], x["running_time"]))
|
||||||
|
|
||||||
# 字典去重
|
# 按照姓名@学号唯一去重
|
||||||
unique_students = {}
|
unique_students = []
|
||||||
for record in sorted_data:
|
unique_students_id_name = set()
|
||||||
id = record["id"]
|
for score in sorted_data:
|
||||||
if id not in unique_students:
|
if f"{score['name']}@{score["id"]}" not in unique_students_id_name:
|
||||||
unique_students[id] = record
|
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) : (
|
: len(unique_students) if limit == True else abs(limit) : (
|
||||||
1 if limit > 0 else -1
|
1 if limit > 0 else -1
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user