Skip to content

batch_tracking

batch_tracking ¤

Batch / recipe production tracking.

Detect batch boundaries from a string signal that carries the current batch ID, compute duration statistics, per-batch yield, and batch transition matrices.

BatchTrackingEvents ¤

BatchTrackingEvents(
    dataframe: DataFrame,
    batch_uuid: str,
    *,
    event_uuid: str = "prod:batch",
    value_column: str = "value_string",
    time_column: str = "systime"
)

Bases: Base

Track batch/recipe production from a batch-ID string signal.

A "batch" is defined as a contiguous period where the batch-ID value remains constant. A new batch begins when the value changes.

Example usage

batches = BatchTrackingEvents(df, batch_uuid='batch_id_signal')

detected = batches.detect_batches() stats = batches.batch_duration_stats() yields = batches.batch_yield('part_counter') transitions = batches.batch_transition_matrix()

Initialize batch tracker.

Parameters:

Name Type Description Default
dataframe DataFrame

Input DataFrame with timeseries data.

required
batch_uuid str

UUID of the batch-ID signal.

required
event_uuid str

UUID to tag derived events with.

'prod:batch'
value_column str

Column holding the batch ID string.

'value_string'
time_column str

Name of timestamp column.

'systime'

detect_batches ¤

detect_batches() -> pd.DataFrame

Detect batch start/end from value changes in the batch-ID signal.

Returns:

Type Description
DataFrame

DataFrame with columns:

DataFrame
  • batch_id: The batch identifier string.
DataFrame
  • start: Timestamp of the first sample in the batch.
DataFrame
  • end: Timestamp of the last sample in the batch.
DataFrame
  • duration_seconds: Duration of the batch.
DataFrame
  • sample_count: Number of data points in the batch.
DataFrame
  • uuid: Event UUID.
DataFrame
  • source_uuid: Source signal UUID.

batch_duration_stats ¤

batch_duration_stats() -> pd.DataFrame

Compute duration statistics grouped by batch type (batch_id).

Returns:

Type Description
DataFrame

DataFrame with columns:

DataFrame
  • batch_id
DataFrame
  • count: Number of occurrences of this batch type.
DataFrame
  • min_duration_seconds
DataFrame
  • avg_duration_seconds
DataFrame
  • max_duration_seconds
DataFrame
  • total_duration_seconds

batch_yield ¤

batch_yield(
    counter_uuid: str,
    *,
    value_column_counter: str = "value_integer"
) -> pd.DataFrame

Compute production quantity for each detected batch.

Uses a monotonic counter signal. The yield per batch is the counter increase during the batch interval.

Parameters:

Name Type Description Default
counter_uuid str

UUID of the monotonic part counter.

required
value_column_counter str

Column holding counter values.

'value_integer'

Returns:

Type Description
DataFrame

DataFrame with columns:

DataFrame
  • batch_id
DataFrame
  • start
DataFrame
  • end
DataFrame
  • duration_seconds
DataFrame
  • quantity: Parts produced during the batch.
DataFrame
  • uuid
DataFrame
  • source_uuid

batch_transition_matrix ¤

batch_transition_matrix() -> pd.DataFrame

Build a transition frequency matrix: which batch follows which.

Returns:

Type Description
DataFrame

DataFrame (pivot table) where index = from_batch, columns = to_batch,

DataFrame

values = transition count. An extra total column is appended.