Skip to content

Integrate ML Pipeline with Main Application #62

@machug

Description

@machug

Overview

The ML pipeline is complete and tested (PR #61) but not yet integrated with the main application. This issue tracks connecting the ML components to the live reading pipeline.

Current State

Complete:

  • ML pipeline implementation in backend/ml/
  • 48/48 tests passing
  • Per-device state isolation
  • Kalman filtering, anomaly detection, curve fitting, MPC

Not Connected:

  • Not called from backend/main.py reading handler
  • Not exposed via API endpoints
  • Not displayed in frontend UI
  • State lost on service restart

Proposed Integration

Phase 1: Basic Integration

  1. Add MLPipelineManager to backend/main.py
  2. Process readings through ML pipeline in handle_tilt_reading()
  3. Broadcast ML results via WebSocket
  4. Display filtered values on dashboard

Phase 2: State Persistence

  1. Hydrate ML state from database on startup (last 48 hours)
  2. Ensures predictions work immediately after restart
  3. Option: Store ML results in new ml_results table

Phase 3: UI Integration

  1. Show Kalman-filtered values on dashboard
  2. Display FG predictions and completion estimates
  3. Anomaly alerts (stuck fermentation, temperature spikes)
  4. MPC temperature trajectory visualization

Data Storage Strategy

Current approach: In-Memory

  • ML state lives in RAM (per-device history buffers)
  • ~157 KB per device for 2-week fermentation
  • Lost on service restart

Recommended: Hydrate from DB

Implementation Notes

  • Keep ML processing async/non-blocking
  • Feature flags for gradual rollout (MLConfig)
  • WebSocket message type: ml_update
  • Consider caching filtered values for API endpoints

Related

Acceptance Criteria

  • ML pipeline processes all live Tilt readings
  • Filtered values broadcast via WebSocket
  • ML state survives service restarts
  • Dashboard shows filtered SG/temp
  • Predictions visible on batch detail page
  • Anomaly alerts displayed to user
  • No performance degradation (<10ms overhead)

Priority

Medium - ML pipeline is functional but not user-visible. Can be done incrementally after PR #61 merges.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions