Strict category matching. - If category != 'ALL': questions MUST be from that category. - Difficulty filter applies inside the chosen category. If it yields 0 questions, we fall back to ALL difficulty *within the same category* (never to the whole DB).
(db: List[dict], category: str, difficulty: str)
| 365 | |
| 366 | # -------------------- Quiz core -------------------- |
| 367 | def build_pool(db: List[dict], category: str, difficulty: str) -> List[dict]: |
| 368 | """Strict category matching. |
| 369 | - If category != 'ALL': questions MUST be from that category. |
| 370 | - Difficulty filter applies inside the chosen category. If it yields 0 questions, we fall back to ALL difficulty |
| 371 | *within the same category* (never to the whole DB). |
| 372 | """ |
| 373 | if difficulty not in DIFFICULTIES: |
| 374 | difficulty = "ALL" |
| 375 | |
| 376 | if category == "ALL": |
| 377 | pool = list(db) |
| 378 | else: |
| 379 | pool = [q for q in db if q.get("category") == category] |
| 380 | |
| 381 | if not pool: |
| 382 | return [] |
| 383 | |
| 384 | if difficulty == "ALL": |
| 385 | return pool |
| 386 | |
| 387 | filtered = [q for q in pool if q.get("difficulty") == difficulty] |
| 388 | return filtered if filtered else pool |
| 389 | |
| 390 | def judge_answer(q: dict, user: str) -> bool: |
| 391 | qtype = q.get("type","text") |
no outgoing calls
no test coverage detected