Skip to content

Production Performance API

Endpoint

text GET /api/v1/production-performance

Read-only endpoint that calculates production performance metrics for a project and optional production/stage scope within a resolved tenant.

Calculation details: Production Performance Calculations

Contract reference: api/openapi.yaml

Authentication

When AUTH_ENABLED=true, requests must include a JWT Bearer access token:

http Authorization: Bearer <access_token>

When AUTH_ENABLED=false, the endpoint is open for local development.

Accept negotiation

Value Description
application/json JSON response (default when Accept is omitted)
application/xml XML response
text/xml XML response
*/* JSON response

Unsupported Accept values return 406 Not Acceptable (NOT_ACCEPTABLE).

Tenant context

Same pair-and-fallback rules as Machine Events:

Situation Result
Both query values present Use the request pair
Neither query value present Use configured DEFAULT_* when both are set
Exactly one query value present 400 TENANT_CONTEXT_INCOMPLETE
Neither query nor configured defaults 400 TENANT_CONTEXT_REQUIRED
Invalid ObjectID 400 INVALID_TENANT_CONTEXT

Query parameters

Parameter Required Description
project_code Yes Project code within the resolved tenant
company_id No Tenant company ObjectID (pair rule applies)
organization_id No Tenant organization ObjectID (pair rule applies)
production_code No Narrow metrics to one production
production_stage_code No Narrow metrics to one stage; requires production_code
start_time No* Window start (RFC 3339; offset accepted, normalized to UTC)
end_time No* Window end (RFC 3339; offset accepted, normalized to UTC)

* start_time and end_time must be supplied together or omitted together. When both are supplied, start_time must be strictly before end_time.

When the time window is omitted, the service derives:

  • effective_end_time — current UTC time at request processing
  • effective_start_time — earliest relevant timestamp from project metadata, embedded operation events, or alarm history for the active scope

Metric scopes

Metrics are computed independently at each returned level:

Response block When present Scope
project Always Entire project
production When production_code is supplied That production only
production_stage When production_stage_code is supplied That stage only

Supplying a stage filter still returns full project and production totals in their respective blocks.

Response fields

Top-level timestamps:

Field Description
generated_at Calculation timestamp (UTC)
effective_start_time Applied window start (UTC)
effective_end_time Applied window end (UTC)

Each metrics object contains:

Field Description
total_operation_time_seconds Operation Start/Break/End interval total
net_operation_time_seconds Alarm-derived net operation time
stop_time_seconds Total stop time
planned_stop_time_seconds Planned stop subset
unplanned_stop_time_seconds Unplanned stop subset
failure_stop_time_seconds Failure stop subset
product_metrics Aggregated product counters

Duration values are int64 seconds. Fractional sub-second remainders are truncated toward zero via int64(duration / time.Second).

When no matching data exists, the endpoint returns HTTP 200 with zero metric values and "product_metrics": [].

Example request

http GET /api/v1/production-performance?project_code=PROJE-001&production_code=URETIM-001&start_time=2026-08-01T00:00:00Z&end_time=2026-08-06T23:59:59Z HTTP/1.1 Host: localhost:8080 Authorization: Bearer <access_token> Accept: application/json

Example response

json { "success": true, "request_id": "550e8400-e29b-41d4-a716-446655440000", "data": { "generated_at": "2026-08-06T15:00:00Z", "effective_start_time": "2026-08-01T00:00:00Z", "effective_end_time": "2026-08-06T23:59:59Z", "project": { "project_name": "Proje Adı", "project_code": "PROJE-001", "metrics": { "total_operation_time_seconds": 3600, "net_operation_time_seconds": 3200, "stop_time_seconds": 400, "planned_stop_time_seconds": 200, "unplanned_stop_time_seconds": 150, "failure_stop_time_seconds": 50, "product_metrics": [ { "product_id": "6a2bc9fbeb8679852cddac2a", "product_code": "URUN-001", "product_name": "Ürün Adı", "successful_count": 100, "revised_count": 5, "scrap_count": 2, "total_count": 107 } ] } }, "production": { "production_name": "Üretim Emri Adı", "production_code": "URETIM-001", "metrics": { "total_operation_time_seconds": 1800, "net_operation_time_seconds": 1600, "stop_time_seconds": 200, "planned_stop_time_seconds": 100, "unplanned_stop_time_seconds": 75, "failure_stop_time_seconds": 25, "product_metrics": [] } } }, "error": null }

Error responses

HTTP Code When
400 PROJECT_CODE_REQUIRED project_code missing
400 PRODUCTION_CODE_REQUIRED / INVALID_FILTER_DEPENDENCY production_stage_code without production_code
400 TENANT_CONTEXT_* / INVALID_TENANT_CONTEXT Tenant resolution failure
400 INVALID_START_TIME / INVALID_END_TIME Malformed time parameter
400 INVALID_TIME_RANGE One-sided times or invalid range
401 AUTHENTICATION_REQUIRED / INVALID_TOKEN Auth failure
404 PROJECT_NOT_FOUND Unknown project for tenant
404 PRODUCTION_NOT_FOUND Unknown production in project
404 PRODUCTION_STAGE_NOT_FOUND Unknown stage in production
406 NOT_ACCEPTABLE Unsupported Accept
503 DATABASE_UNAVAILABLE MongoDB unavailable

See Error Codes.

Database indexes

Non-unique alarm indexes are created by the migration CLI:

  • ix_alarms_machine_timestamp_id_desc
  • ix_alarms_project_production_stage_machine_timestamp_id

See Machine Events for index purpose notes.