# DigiFabrix OEE Intelligence – Foundation Release

## What is included
- ISA-95-style plant hierarchy: Plant → Area → Line → Machine.
- Product, ideal cycle, machine-specific rate, cavity and changeover configuration.
- Shift master, cross-midnight shifts, tea/lunch/planned breaks and plant calendar.
- Multi-product shift planning with automatic break and changeover deductions.
- Hour-by-hour plan generation, including reduced targets during breaks/changeovers.
- Immutable device production/rejection ingestion API with API-key hashing and deduplication.
- Automatic Running / Idle / Stopped / Offline state engine.
- Machine state history, three-level loss hierarchy, 16-loss seed master and breakdown tickets.
- Hourly and shift OEE snapshots for trend reporting.
- Professional responsive live command-center dashboard.

## OEE definition
Availability = Run Time / Planned Production Time
Performance = (Ideal Cycle Time × Total Count) / Run Time
Quality = Good Count / Total Count
OEE = Availability × Performance × Quality

Breaks marked `is_excluded_from_oee=1` are removed from Planned Production Time. Changeover can either be excluded or classified as planned availability loss based on customer policy; this release deducts it from the production target and stores it separately.

## Installation
1. Import `sql/oee_database.sql`.
2. Edit `includes/config.php`.
3. Add machines/products/shifts and API keys.
4. Generate an API key hash: `SHA2('your-secret-key',256)` and insert it in `api_keys`.
5. Point devices to `api/ingest.php` with JSON fields: `machine_id`, `production_count`, `rejection_count`, `event_time`, `sequence`, `api_key`.
6. Configure cron:
   - every minute: `php cron/state_engine.php`
   - at minute 2 every hour: `php cron/hourly_oee.php`
   - every 15 minutes: `php cron/shift_finalize.php`
7. Open `index.php`.

## Existing 5-column table
Your existing table can remain as a staging/source table. Recommended options:
- Change device API to write directly to `device_production_log`; or
- Create a one-minute bridge cron that copies new rows into `device_production_log` and maps `machine_id`.
Do not overwrite raw data. OEE calculations should be reproducible from immutable event rows.

## Important production hardening still required
- Authentication/session middleware and role-based permissions.
- CSRF protection on forms.
- Full master CRUD and approval workflow.
- Customer-specific policy decisions for planned downtime, micro-stop threshold, cumulative device counters, rework and startup scrap.
- Alert connectors (email/WhatsApp/SMS), ERP production-order interface and maintenance CMMS interface.
- Automated tests, backup/retention, partitioning for high-volume logs, HTTPS and audit review.
