Station Dashboard KPIs

ops station kpi analytics

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)

KPITypeDescription
station_efficiency_pctNUMERIC(7,2)Standard Hours / Actual Hours x 100%
jobs_completedBIGINTCount of completed jobs in time range
jobs_in_progressBIGINTCurrently active jobs (no time filter)
jobs_queuedBIGINTCurrently 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)

KPITypeDescription
avg_job_duration_hoursNUMERIC(10,2)Average wall-clock time from first clock-in to last clock-out
avg_active_time_hoursNUMERIC(10,2)Average actual labor hours per job
avg_workers_per_jobNUMERIC(5,2)Average distinct workers per job
standard_hours_earnedNUMERIC(10,2)Sum of standard hours for completed jobs
scrap_rate_pctNUMERIC(7,2)Scrapped / Total Finished x 100%
first_pass_yield_pctNUMERIC(7,2)Jobs completed without rework / Total Finished x 100%
top_scrap_reason / top_scrap_reason_countTEXT / BIGINTMost 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)

KPITypeDescription
total_idle_hoursNUMERIC(10,2)Wall-clock time minus active labor time
idle_pctNUMERIC(7,2)Idle / (Idle + Labor) x 100%
avg_time_between_jobs_hoursNUMERIC(10,2)Average gap between consecutive job completions
longest_gap_hoursNUMERIC(10,2)Largest gap between jobs

Metadata (2 fields)

FieldTypeDescription
total_standard_hoursNUMERIC(10,2)Sum of standard hours for completed jobs
total_actual_hoursNUMERIC(10,2)Sum of labor hours from ops_time_entries

Data Sources

The function joins across several tables:

  • ops_jobs — job states, part counts, timestamps
  • ops_products / ops_product_families — standard hours
  • ops_time_entries — actual labor hours
  • ops_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/

See Also