Skip to content

segment_extractor

segment_extractor ¤

SegmentExtractor ¤

SegmentExtractor(
    dataframe: DataFrame, column_name: str = "systime"
)

Bases: Base

Extract time ranges from a categorical signal that changes over time.

Given a signal UUID (e.g. order number or part number) whose value changes over time, detects transitions and produces one row per contiguous segment with its start time, end time, and active value.

Methods: - extract_time_ranges: Detect value changes and return time range segments.

extract_time_ranges classmethod ¤

extract_time_ranges(
    dataframe: DataFrame,
    segment_uuid: str,
    uuid_column: str = "uuid",
    value_column: str = "value_string",
    time_column: str = "systime",
    min_duration: Optional[str] = None,
) -> pd.DataFrame

Detect value transitions and extract time ranges per segment.

Parameters:

Name Type Description Default
dataframe DataFrame

Input DataFrame in long format.

required
segment_uuid str

The UUID of the categorical signal to segment by (e.g. 'order_number', 'part_number').

required
uuid_column str

Column identifying each timeseries.

'uuid'
value_column str

Column containing the categorical values. Use 'value_string' for string signals, 'value_integer' for integer signals, etc.

'value_string'
time_column str

Column containing timestamps.

'systime'
min_duration Optional[str]

Optional minimum segment duration (e.g. '10s', '1min'). Segments shorter than this are dropped.

None

Returns:

Type Description
DataFrame

DataFrame with columns:

DataFrame
  • segment_value: The active value during this range.
DataFrame
  • segment_start: Start timestamp of the range.
DataFrame
  • segment_end: End timestamp of the range.
DataFrame
  • segment_duration: Duration as Timedelta.
DataFrame
  • segment_index: Sequential index of the segment.