38 lines
895 B
Python
38 lines
895 B
Python
from ninja import ModelSchema, Schema
|
|
|
|
from submissions.models import PuzzleResponse
|
|
from submissions.schemas import SteamCollectionItemOut, UserInfoOut
|
|
|
|
|
|
class PuzzleResponseRankingOut(ModelSchema):
|
|
class Meta:
|
|
model = PuzzleResponse
|
|
fields = [
|
|
"id",
|
|
"puzzle_name",
|
|
"created_at",
|
|
"updated_at",
|
|
]
|
|
|
|
points: int
|
|
rank_points: int
|
|
puzzle_user_rank: int
|
|
user_response_rank: int
|
|
|
|
user_id: int
|
|
|
|
final_cost: int | None
|
|
final_cycles: int | None
|
|
final_area: int | None
|
|
|
|
@staticmethod
|
|
def resolve_user_id(obj) -> int:
|
|
return obj.submission.user.id
|
|
|
|
|
|
class RankingSchema(Schema):
|
|
users: list[UserInfoOut]
|
|
puzzles: list[SteamCollectionItemOut]
|
|
responses_by_userid: dict[int, list[PuzzleResponseRankingOut]]
|
|
ranking_by_puzzle: dict[int, list[PuzzleResponseRankingOut]]
|