diff --git a/backend/main.py b/backend/main.py index 627ceca..1d50c2d 100644 --- a/backend/main.py +++ b/backend/main.py @@ -1,4 +1,4 @@ -from typing import Optional +from typing import Dict, List, Optional """VerIQ — FastAPI application (v1 MVP). Standalone public IQ test with signed, verifiable results. @@ -23,11 +23,11 @@ # --- in-memory test sessions (single-process MVP) --------------------------- # session_token -> {task_ids, started_at, ip} -SESSIONS: dict[str, dict] = {} +SESSIONS: Dict[str, dict] = {} SESSION_TTL_S = 60 * 60 # 1 hour to finish after start # --- simple per-IP rate limiting -------------------------------------------- -_RATE: dict[str, list[float]] = {} +_RATE: Dict[str, List[float]] = {} RATE_LIMIT_STARTS_PER_HOUR = 10 @@ -64,13 +64,13 @@ # --- models ------------------------------------------------------------------ class StartResponse(BaseModel): session_token: str - tasks: list[dict] + tasks: List[dict] time_limit_s: int class FinishRequest(BaseModel): session_token: str - answers: dict[str, int] = Field(default_factory=dict) + answers: Dict[str, int] = Field(default_factory=dict) total_time_s: float = 0.0 diff --git a/backend/oauth.py b/backend/oauth.py index 3316d99..e7d9ec2 100644 --- a/backend/oauth.py +++ b/backend/oauth.py @@ -1,4 +1,4 @@ -from typing import Optional +from typing import Dict, Optional, Tuple """VerIQ — identity binding via OAuth (phase 2 scaffolding). X (Twitter): OAuth 2.0 Authorization Code with PKCE. @@ -31,7 +31,7 @@ IG_USERINFO = "https://graph.facebook.com/me" # in-memory PKCE/state store (single-process MVP; fine for v1) -FLOWS: dict[str, dict] = {} +FLOWS: Dict[str, dict] = {} FLOW_TTL_S = 600 @@ -70,7 +70,7 @@ return {"state": state, "challenge": challenge, "verifier": verifier} -def x_authorize_url(result_id: str) -> tuple[str, Optional[str]]: +def x_authorize_url(result_id: str) -> Tuple[str, Optional[str]]: """Returns (authorize_url, state) or None if not configured.""" cid = _env("X_CLIENT_ID") if not cid: @@ -88,7 +88,7 @@ return X_AUTHORIZE + "?" + urlencode(params), flow["state"] -def ig_authorize_url(result_id: str) -> tuple[str, Optional[str]]: +def ig_authorize_url(result_id: str) -> Tuple[str, Optional[str]]: app_id = _env("IG_APP_ID") if not app_id: return None diff --git a/backend/scoring.py b/backend/scoring.py index e50fbb0..44aea98 100644 --- a/backend/scoring.py +++ b/backend/scoring.py @@ -1,4 +1,4 @@ -from typing import Optional +from typing import Dict, List, Optional """VerIQ — scoring: raw points -> IQ score + percentile. v1 model: fixed weights per difficulty tier, z-score normalization against @@ -44,7 +44,7 @@ return None -def max_raw_score(task_ids: list[str]) -> int: +def max_raw_score(task_ids: List[str]) -> int: total = 0 for tid in task_ids: t = task_by_id(tid) @@ -53,7 +53,7 @@ return total -def raw_score(answers: dict[str, int], task_ids: list[str]) -> int: +def raw_score(answers: Dict[str, int], task_ids: List[str]) -> int: """answers: {task_id: chosen_index}. Missing = wrong.""" total = 0 for tid in task_ids: @@ -77,7 +77,7 @@ return None -def score_test(answers: dict[str, int], task_ids: list[str], +def score_test(answers: Dict[str, int], task_ids: List[str], total_time_s: float, flagged: bool) -> dict: """Compute raw score, IQ, percentile, category breakdown.""" bank = load_bank() @@ -99,7 +99,7 @@ percentile = round(0.5 * (1 + math.erf(z / math.sqrt(2))) * 100, 1) # category breakdown - cats: dict[str, dict] = {} + cats: Dict[str, dict] = {} for tid in task_ids: t = task_by_id(tid) if not t: @@ -122,7 +122,7 @@ } -def sanity_check(answers: dict[str, int], task_ids: list[str], +def sanity_check(answers: Dict[str, int], task_ids: List[str], total_time_s: float) -> bool: """Flag implausible completions: too fast or suspiciously perfect.""" n = len(task_ids)