segment_processor
segment_processor ¤
SegmentProcessor ¤
SegmentProcessor(
dataframe: DataFrame, time_column: str = "systime"
)
Bases: Base
Apply extracted time ranges to process data and compute metric profiles.
Takes the output of SegmentExtractor.extract_time_ranges and uses it to filter and annotate process parameter data, then computes statistical metrics per UUID per segment.
Methods: - apply_ranges: Filter process data by time ranges, annotate with segment info. - compute_metric_profiles: Compute statistical metrics per UUID per segment.
apply_ranges
classmethod
¤
apply_ranges(
dataframe: DataFrame,
time_ranges: DataFrame,
uuid_column: str = "uuid",
time_column: str = "systime",
target_uuids: list[str] | None = None,
) -> pd.DataFrame
Cut process data into the extracted time ranges.
Every row whose timestamp lies in a range gets that range's
segment_value and segment_index. Ranges are half-open,
segment_start <= t < segment_end, so a sample exactly at a
boundary belongs to the range that starts there and contiguous
ranges (interval_end="next_change") cut every row exactly once.
The row exactly at segment_end belongs to the range only when the
range's end_inclusive is True (extract_time_ranges sets it for
the last segment, closed at the end of the data, and for every
interval_end="last_sample" segment). Without an end_inclusive
column, the end is inclusive when no other range starts at that
instant. Rows outside every range (before the first range, in gaps
such as an empty order number) are dropped; rows without a timestamp
are dropped.
Overlapping ranges (only possible with a hand-built time_ranges)
are applied one by one, so a row in two ranges appears twice; a
warning says how many overlaps there are.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataframe
|
DataFrame
|
Input DataFrame with process parameter data (all UUIDs). |
required |
time_ranges
|
DataFrame
|
Output from SegmentExtractor.extract_time_ranges, or
any frame with |
required |
uuid_column
|
str
|
Column identifying each timeseries. |
'uuid'
|
time_column
|
str
|
Column containing timestamps. |
'systime'
|
target_uuids
|
list[str] | None
|
Optional list of UUIDs to include. None keeps all. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
The matching rows of |
DataFrame
|
parsed to datetime), ordered by range and then by input order, |
DataFrame
|
with added columns: |
DataFrame
|
|
DataFrame
|
|
compute_metric_profiles
classmethod
¤
compute_metric_profiles(
dataframe: DataFrame,
uuid_column: str = "uuid",
value_column: str = "value_double",
group_column: str = "segment_value",
metrics: list[str] | None = None,
) -> pd.DataFrame
Compute statistical metrics per UUID per segment.
Typically called on the output of apply_ranges. Computes the
statistics of NumericStatistics.summary_as_dict per (UUID, segment)
pair, for all pairs at once. Missing values are ignored; pairs with
fewer than 2 non-missing values are left out.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataframe
|
DataFrame
|
Input DataFrame (output of apply_ranges or similar). |
required |
uuid_column
|
str
|
Column identifying each timeseries. |
'uuid'
|
value_column
|
str
|
Column containing numeric values. |
'value_double'
|
group_column
|
str
|
Column to group segments by (e.g. 'segment_value', 'segment_index'). Use 'segment_value' to aggregate all ranges of the same order, or 'segment_index' for individual ranges. |
'segment_value'
|
metrics
|
list[str] | None
|
Subset of metric names to compute. None uses all 19. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with columns [uuid, |
DataFrame
|
metric_1, ...], one row per pair, sorted by uuid and group. |
DataFrame
|
|
DataFrame
|
these columns) when no pair has 2 values. |