Skip to content

feat(mes): Week 5 — Downtime tracking + NLP classifier#143

Open
Mikecranesync wants to merge 3 commits into
mainfrom
feat/mes-week5-downtime
Open

feat(mes): Week 5 — Downtime tracking + NLP classifier#143
Mikecranesync wants to merge 3 commits into
mainfrom
feat/mes-week5-downtime

Conversation

@Mikecranesync
Copy link
Copy Markdown
Owner

Summary

Completes the "Core Four" — downtime tracking now has all three capture modes:

Mode How Who
AUTO PLC fault code → ERROR_CODE_REASON_MAP in state_machine.py (live since Week 2) PLC
MANUAL POST /lines/{id}/downtime with reason_code Operator
NLP POST /lines/{id}/downtime with description text → keyword classifier MIRA_AI

NLP Classifier — pure keyword matching, no LLM required, 13-rule priority table:

  • E_STOP → MAINT_PM → MAINT_BREAKDOWN → CHANGEOVER_TOOLING → CHANGEOVER_PRODUCT → JAM → STARVED_MATERIAL → BLOCKED_DOWNSTREAM → QUALITY_HOLD → OVERLOAD → OVERHEAT → SENSOR_FAIL → COMMS_FAIL → UNKNOWN
  • Case-insensitive, always returns a valid code (never raises)

New endpoints:

  • GET /api/mes/downtime-reasons — all 14 seeded codes with category
  • GET /api/mes/lines/{id}/downtime?hours=8 — event history with duration_min
  • POST /api/mes/lines/{id}/downtime — attach/override reason on open DOWN event
    • 409 if no open DOWN/CHANGEOVER event exists
    • 422 if reason_code unknown or neither field provided

Test plan

  • pytest tests/test_downtime.py -v — 29/29 pass (20 classifier + 9 API)
  • pytest tests/ -v — 95/95 pass (zero regressions Weeks 1–4)
  • All 14 reason codes classifiable; UNKNOWN fallback always returns gracefully

Closes

Closes MIRA#323

🤖 Generated with Claude Code

CharlieNode and others added 3 commits April 16, 2026 00:51
Adds OEE computation engine, 60-second tick loop, fleet endpoints:
- compute_oee() pure function: A×P×Q with clamp/rounding (PRD §10 AC#3, AC#5)
- 30-tick alert at OEE < 60% per line (OEE_ALERT_TICKS=30)
- ItemCount delta tracking from HR100 (cumulative register)
- run_time_in_window() SQL: sums RUNNING seconds in last tick window
- 4 new endpoints: /oee, /oee/history, /oee/summary, /kpis
- oee_calculator background task wired into FastAPI lifespan
- 16 new tests, zero regressions (48/48 suite)

Closes MIRA#321

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
…sts, 66 total pass)

Work order CRUD + product management:
- POST/GET /api/mes/products — create SKU with ideal_cycle_sec
- POST /api/mes/work-orders — creates PENDING; validates line + product + unique order_number
- GET /api/mes/work-orders — list with ?line_id= / ?status= filters
- GET /api/mes/work-orders/{id} — detail
- PATCH /api/mes/work-orders/{id}/status — enforced transitions (PENDING→ACTIVE→COMPLETE/CANCELLED)
- 409 when second ACTIVE work order attempted on same line

Schedule-aware TEEP:
- compute_oee() gains utilisation param (default 1.0 — Week 3 backward compat)
- TEEP = OEE × utilisation (clamped 0-1)
- _active_utilisation() queries schedules table; falls back to 1.0 when no schedules exist

18 new tests, zero regressions (66/66 suite)
Closes MIRA#322

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
…(29 tests, 95 total pass)

Three downtime capture modes now live:
- AUTO: PLC fault code → reason_code already wired via state_poller (Weeks 2+)
- MANUAL: POST /api/mes/lines/{id}/downtime with direct reason_code (OPERATOR/PLC)
- NLP: POST with free-text description → keyword classifier → reason_code (MIRA_AI)

New:
- downtime_classifier.py: pure keyword→reason_code with 13-rule priority table
  (E_STOP > MAINT_PM > MAINT_BREAKDOWN > CHANGEOVER > JAM > ... > UNKNOWN fallback)
- GET /api/mes/downtime-reasons — list all 14 seeded codes
- GET /api/mes/lines/{id}/downtime?hours=8 — downtime history with duration_min
- POST /api/mes/lines/{id}/downtime — attach/override reason on open DOWN event
  409 if line has no open DOWN/CHANGEOVER event
  422 if reason_code unknown or neither field provided

29 new tests (20 NLP classifier + 9 API), zero regressions (95/95 suite)
Closes MIRA#323

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant