Station Dashboard KPIs
The Station Dashboard KPIs function (get_station_dashboard_kpis) returns 18 metrics across 4 sections in a single database call. This powers the station detail view on the OEE dashboard.
Function Signature
get_station_dashboard_kpis(
p_station_id UUID,
p_org_id VARCHAR,
p_time_start TIMESTAMPTZ,
p_time_end TIMESTAMPTZ
)KPI Sections
Section 1: Top Bar (4 metrics)
| KPI | Type | Description |
|---|---|---|
station_efficiency_pct | NUMERIC(7,2) | Standard Hours / Actual Hours x 100% |
jobs_completed | BIGINT | Count of completed jobs in time range |
jobs_in_progress | BIGINT | Currently active jobs (no time filter) |
jobs_queued | BIGINT | Currently pending jobs (no time filter) |
Section 2: The One Number
Same as station_efficiency_pct from Section 1 — displayed prominently as the central KPI.
Section 3: Job Performance (7 metrics)
| KPI | Type | Description |
|---|---|---|
avg_job_duration_hours | NUMERIC(10,2) | Average wall-clock time from first clock-in to last clock-out |
avg_active_time_hours | NUMERIC(10,2) | Average actual labor hours per job |
avg_workers_per_job | NUMERIC(5,2) | Average distinct workers per job |
standard_hours_earned | NUMERIC(10,2) | Sum of standard hours for completed jobs |
scrap_rate_pct | NUMERIC(7,2) | Scrapped / Total Finished x 100% |
first_pass_yield_pct | NUMERIC(7,2) | Jobs completed without rework / Total Finished x 100% |
top_scrap_reason / top_scrap_reason_count | TEXT / BIGINT | Most common scrap reason |
First Pass Yield is calculated by checking ops_job_station_history.entry_number — if a job visited the station more than once (entry_number > 1), it was reworked and does not count as first-pass.
Section 4: Issues & Downtime (4 metrics)
| KPI | Type | Description |
|---|---|---|
total_idle_hours | NUMERIC(10,2) | Wall-clock time minus active labor time |
idle_pct | NUMERIC(7,2) | Idle / (Idle + Labor) x 100% |
avg_time_between_jobs_hours | NUMERIC(10,2) | Average gap between consecutive job completions |
longest_gap_hours | NUMERIC(10,2) | Largest gap between jobs |
Metadata (2 fields)
| Field | Type | Description |
|---|---|---|
total_standard_hours | NUMERIC(10,2) | Sum of standard hours for completed jobs |
total_actual_hours | NUMERIC(10,2) | Sum of labor hours from ops_time_entries |
Data Sources
The function joins across several tables:
ops_jobs— job states, part counts, timestampsops_products/ops_product_families— standard hoursops_time_entries— actual labor hoursops_job_station_history— rework detection (first pass yield)
Standard Hours Resolution
Standard hours are resolved with fallback:
COALESCE(p.standard_hours, pf.standard_hours, 0)Product-level standard hours take priority over family-level.
Codebase Paths
- SQL function:
database/sql_scripts/functions/ops/ops_station_dashboard_kpis.sql - Backend:
backend/endpoints/ops.ts - Frontend:
frontend/src/app/features/oee-dashboard/