← Files Technical Interview CopilotARCHIVED FILE
scripts/practice_planner.py
2.71 KB · Nov 9, 2026 · 01:33 UTC
"""Deterministic *coaching* helpers; no prediction of hiring outcomes.
Usage: python3 scripts/practice_planner.py (shows illustrative allocation).
"""
from __future__ import annotations
from math import floor
def allocate_minutes(total_minutes: int, topic_weights: dict[str, float]) -> dict[str, int]:
"""Use the largest-remainder method for user-chosen priorities.
Every minute is assigned; weights do NOT imply employer interview probabilities.
"""
if isinstance(total_minutes, bool) or not isinstance(total_minutes, int) or total_minutes < 0:
raise ValueError("total_minutes must be a nonnegative integer")
if not isinstance(topic_weights, dict) or not topic_weights:
raise ValueError("provide at least one named topic")
from math import isfinite
if any(not isinstance(k, str) or not k.strip() for k in topic_weights):
raise ValueError("topic names must be nonempty strings")
if any(isinstance(v, bool) or not isinstance(v, (int, float)) or not isfinite(v) or v < 0 for v in topic_weights.values()):
raise ValueError("weights must be finite nonnegative numbers")
weight_sum = sum(topic_weights.values())
if weight_sum <= 0:
raise ValueError("at least one positive weight required")
shares = {k: total_minutes * v / weight_sum for k, v in topic_weights.items()}
base = {k: floor(v) for k, v in shares.items()}
left = total_minutes - sum(base.values())
for k in sorted(shares, key=lambda k: (-round(shares[k]-base[k], 12), k))[:left]:
base[k] += 1
return base
def weighted_coaching_score(scores: dict[str, int | None], weights: dict[str, float]) -> float | None:
"""Coaching average in [0,4] across *assessed* dimensions; None if no evidence.
Missing dimensions never count as zero. This is not a hiring score.
"""
if set(scores) != set(weights) or not scores:
raise ValueError("scores and weights need matching nonempty dimensions")
from math import isfinite
assessed = []
for name, score in scores.items():
weight = weights[name]
if isinstance(weight, bool) or not isinstance(weight, (int, float)) or not isfinite(weight) or weight < 0:
raise ValueError("weights must be finite nonnegative numbers")
if score is None:
continue
if isinstance(score, bool) or not isinstance(score, int) or not 0 <= score <= 4:
raise ValueError("coaching scores must be integers 0 through 4 or None")
if weight:
assessed.append((score, weight))
total = sum(w for _,w in assessed)
return (sum(s*w for s,w in assessed)/total) if total else None
if __name__ == '__main__':
print(allocate_minutes(90, {"coding": 3, "design": 2, "behavioral": 1}))
SHA-256: 496dfe84455b6f3a0898d520379d41ecd276ec2cacfc2231ea41aa5123aa16dd