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_statistics() 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
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
batch_duration_statistics ¤
batch_duration_statistics() -> pd.DataFrame
Compute duration statistics grouped by batch type (batch_id).
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with columns: |
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
batch_yield ¤
batch_yield(
counter_uuid: str,
*,
value_column_counter: str = "value_integer",
handle_resets: bool = True
) -> pd.DataFrame
Compute production quantity for each detected batch.
Uses a monotonic counter signal. With handle_resets=True the
reset-aware increments are computed once over the whole counter and
each is booked to the batch that was running when it was produced: a
reading reports the production since the previous reading, so it
belongs to the batch whose ID was last seen strictly before it. A batch
therefore owns the counter readings after its first sample up to and
including the next batch-ID change, the production between the last
sample of one batch and the first sample of the next counts for the
earlier batch, and the batch quantities add up to the counter total
(readings before the first batch-ID sample, after the last one, or
while the batch ID is empty belong to no batch).
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'
|
handle_resets
|
bool
|
When True (default), treat a decreasing counter as a reset and
count the production after the reset instead of losing it, so
|
True
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with columns: |
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
batch_transition_matrix ¤
batch_transition_matrix(
*, layout: Literal["long", "wide"] = "long"
) -> pd.DataFrame
Count which batch follows which.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layout
|
Literal['long', 'wide']
|
|
'long'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
With |
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
keeps these columns. |
DataFrame
|
With |
DataFrame
|
columns = to_batch, values = transition count, plus a |
DataFrame
|
column. The batch columns depend on the data, so with fewer than |
DataFrame
|
two batches the result is an empty frame with only the |
DataFrame
|
column (index named |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |