方寸 Portal

AI Engineer Portal

Your personal operating system for career transition.

Private mode

Exercise

Build a production quality alert system

Build a Production Quality Alert System

Quality alerts should trigger on patterns, not individual events. A single bad response is noise. A 10% decline in pass rate over 4 hours is a signal worth waking someone up for.

What to build

Implement QualityAlertSystem:

  1. record_event(feature, score, passed, timestamp_s=None) — Appends a quality event. Uses time.time() if timestamp not provided.

  2. rolling_stats(feature, window_seconds=3600) -> dict — Computes stats for the most recent window_seconds: {"n", "pass_rate", "avg_score", "p5_score", "p95_score"}. Returns empty dict if no events.

  3. check_alerts(feature, thresholds: dict | None = None) -> list[dict]thresholds supports: min_pass_rate (default 0.8), min_avg_score (default 0.7), max_p5_score_floor (default 0.3, alert if p5 drops below this). Returns list of {"alert_type", "current_value", "threshold", "feature"} dicts.

  4. baseline_drift(feature, baseline_pass_rate: float) -> dict | None — Returns {"delta", "is_drift": bool} where is_drift is True when rolling pass rate is more than 0.05 below baseline. Returns None if fewer than 20 events in window.

Constraints

  • Standard library only. Window eviction uses event timestamps, not wall-clock time.

Evaluation / hard / Step 32 of 36

Practice stage

Evaluation and review loops

Hint

Separate the scoring logic from the interpretation logic. Your goal is not just a number; it is a useful next action.

Success criteria
  • - Produces a useful signal, not decorative output
  • - Makes regression review easier
  • - Would support a benchmark or observability loop
Review checklist
  • - Would this output help decide what to fix next?
  • - Are important failure modes visible?
  • - Does the score hide any ambiguity I should record?

Practice

Generate a variation

Generate a new exercise variation to deepen understanding or practice a related concept.

Attempt history

Recent submissions

Before you submit, decide what a strong answer should make obvious to the reviewer.

No attempts yet.