noita leaderboard + view + management commands
This commit is contained in:
@@ -5,6 +5,7 @@ from django.db.models import (
|
||||
Case,
|
||||
When,
|
||||
Sum,
|
||||
Count,
|
||||
IntegerField,
|
||||
Subquery,
|
||||
OuterRef,
|
||||
@@ -154,7 +155,6 @@ def get_leaderboard(request: HttpRequest):
|
||||
|
||||
# Get unique users and their scores, then apply ranking
|
||||
leaderboard = (
|
||||
# User.objects.filter(objectiv_set__isnull=False)
|
||||
User.objects.filter(objectiv__isnull=False)
|
||||
.distinct()
|
||||
.annotate(
|
||||
@@ -163,13 +163,14 @@ def get_leaderboard(request: HttpRequest):
|
||||
output_field=IntegerField(),
|
||||
)
|
||||
)
|
||||
.annotate(objectives_count=Count("objectiv", distinct=True))
|
||||
.annotate(
|
||||
rank=Window(
|
||||
expression=Rank(),
|
||||
order_by=F("total_score").desc(),
|
||||
)
|
||||
)
|
||||
.values("rank", "username", "total_score")
|
||||
.values("rank", "username", "total_score", "objectives_count")
|
||||
.order_by("rank")
|
||||
)
|
||||
|
||||
@@ -179,13 +180,14 @@ def get_leaderboard(request: HttpRequest):
|
||||
"rank": entry["rank"],
|
||||
"username": entry["username"],
|
||||
"total_score": entry["total_score"] or 0,
|
||||
"objectives_count": entry["objectives_count"],
|
||||
}
|
||||
for entry in leaderboard
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@router.post("submit", response=NoitaSubmissionOut)
|
||||
@router.post("submit", response={200: NoitaSubmissionOut, 400: dict})
|
||||
def submit_log_file(request: HttpRequest, file: UploadedFile = File(...)):
|
||||
"""
|
||||
Submit a Noita run file (log file, screenshot, or video).
|
||||
@@ -200,6 +202,7 @@ def submit_log_file(request: HttpRequest, file: UploadedFile = File(...)):
|
||||
# Validate file type
|
||||
allowed_types = [
|
||||
"text/plain",
|
||||
"text/x-log",
|
||||
"image/jpeg",
|
||||
"image/jpg",
|
||||
"image/png",
|
||||
|
||||
Reference in New Issue
Block a user