Feature: Leaderboard difficulty isolation, proposal category select, numeric answer matcher, 25 new questions (65 total)
This commit is contained in:
+14
-3
@@ -386,7 +386,7 @@ async def get_hint(session_id: str, db: Session = Depends(get_db)):
|
||||
return {"hint": hint_text}
|
||||
|
||||
@app.get("/finale", response_class=HTMLResponse)
|
||||
async def finale(request: Request, score: int = 0, total: int = 10, time: int = 0, lang: str = "de"):
|
||||
async def finale(request: Request, score: int = 0, total: int = 10, time: int = 0, lang: str = "de", diff: str = "all"):
|
||||
max_score = 1000 if (total <= 10 and score > 10) else (total * 100 if total <= 10 else total)
|
||||
tier = get_tier_evaluation(score, total, lang)
|
||||
if time >= 60:
|
||||
@@ -396,6 +396,8 @@ async def finale(request: Request, score: int = 0, total: int = 10, time: int =
|
||||
else:
|
||||
time_str = f"{time} Sek." if lang != "en" else f"{time} sec."
|
||||
|
||||
clean_diff = diff if diff in ["easy", "medium", "hard"] else "all"
|
||||
|
||||
return templates.TemplateResponse(
|
||||
request=request,
|
||||
name="finale.html",
|
||||
@@ -406,6 +408,7 @@ async def finale(request: Request, score: int = 0, total: int = 10, time: int =
|
||||
"time_seconds": time,
|
||||
"time_formatted": time_str,
|
||||
"lang": lang,
|
||||
"difficulty": clean_diff,
|
||||
"tier": tier
|
||||
}
|
||||
)
|
||||
@@ -460,7 +463,11 @@ async def submit_leaderboard(payload: LeaderboardSubmitRequest, db: Session = De
|
||||
db.commit()
|
||||
db.refresh(entry)
|
||||
|
||||
better_count = db.query(LeaderboardEntry).filter(
|
||||
better_query = db.query(LeaderboardEntry)
|
||||
if entry.difficulty and entry.difficulty != "all":
|
||||
better_query = better_query.filter(LeaderboardEntry.difficulty == entry.difficulty)
|
||||
|
||||
better_count = better_query.filter(
|
||||
(LeaderboardEntry.score > entry.score) |
|
||||
((LeaderboardEntry.score == entry.score) & (LeaderboardEntry.time_seconds < entry.time_seconds)) |
|
||||
((LeaderboardEntry.score == entry.score) & (LeaderboardEntry.time_seconds == entry.time_seconds) & (LeaderboardEntry.id < entry.id))
|
||||
@@ -469,6 +476,7 @@ async def submit_leaderboard(payload: LeaderboardSubmitRequest, db: Session = De
|
||||
|
||||
return {
|
||||
"success": True,
|
||||
"id": entry.id,
|
||||
"entry_id": entry.id,
|
||||
"rank": rank,
|
||||
"nickname": entry.nickname,
|
||||
@@ -530,10 +538,11 @@ async def submit_suggestion(payload: SuggestionCreateRequest, db: Session = Depe
|
||||
opts.append(opt.strip())
|
||||
options_json = json.dumps(opts, ensure_ascii=False)
|
||||
|
||||
chosen_cat = payload.category if payload.category in ["hogwarts", "characters", "spells", "creatures", "quidditch", "lore", "general"] else "general"
|
||||
diff = payload.difficulty if payload.difficulty in ["easy", "medium", "hard"] else "medium"
|
||||
|
||||
new_suggestion = Question(
|
||||
category="community",
|
||||
category=chosen_cat,
|
||||
question=payload.frage.strip(),
|
||||
canonical_answer=payload.antwort.strip(),
|
||||
hint=payload.tipp.strip() if payload.tipp else None,
|
||||
@@ -546,9 +555,11 @@ async def submit_suggestion(payload: SuggestionCreateRequest, db: Session = Depe
|
||||
)
|
||||
db.add(new_suggestion)
|
||||
db.commit()
|
||||
db.refresh(new_suggestion)
|
||||
|
||||
return {
|
||||
"success": True,
|
||||
"id": new_suggestion.id,
|
||||
"message": "Vielen Dank! Dein Vorschlag wurde eingereicht und wird von uns geprüft, bevor er im Quiz erscheint."
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user