cycles_extractor
cycles_extractor ¤
CycleExtractor ¤
CycleExtractor(
dataframe: DataFrame,
start_uuid: str,
end_uuid: Optional[str] = None,
value_change_threshold: float = 0.0,
)
Bases: Base
Class for processing cycles based on different criteria.
Initializes the class with the data and the UUIDs for cycle start and end.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataframe
|
DataFrame
|
Input DataFrame with cycle data |
required |
start_uuid
|
str
|
UUID for cycle start variable |
required |
end_uuid
|
Optional[str]
|
UUID for cycle end variable (defaults to start_uuid) |
None
|
value_change_threshold
|
float
|
Minimum threshold for considering a value change significant (default: 0.0) |
0.0
|
process_persistent_cycle ¤
process_persistent_cycle() -> pd.DataFrame
Processes cycles where the value of the variable stays true during the cycle.
process_trigger_cycle ¤
process_trigger_cycle() -> pd.DataFrame
Processes cycles where the value of the variable goes from true to false during the cycle.
process_separate_start_end_cycle ¤
process_separate_start_end_cycle() -> pd.DataFrame
Processes cycles where different variables indicate cycle start and end.
process_step_sequence ¤
process_step_sequence(
start_step: int, end_step: int
) -> pd.DataFrame
Processes cycles based on a step sequence, where specific integer values denote cycle start and end.
process_state_change_cycle ¤
process_state_change_cycle() -> pd.DataFrame
Processes cycles where the start of a new cycle is the end of the previous cycle.
process_value_change_cycle ¤
process_value_change_cycle() -> pd.DataFrame
Processes cycles where a change in the value indicates a new cycle.
Uses the value_change_threshold to determine if a numeric change is significant.
validate_cycles ¤
validate_cycles(
cycle_df: DataFrame,
min_duration: str = "1s",
max_duration: str = "1h",
warn: bool = True,
) -> pd.DataFrame
Validate cycles based on duration constraints.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cycle_df
|
DataFrame
|
DataFrame with cycle data (output from process_* methods) |
required |
min_duration
|
str
|
Minimum acceptable cycle duration (default: '1s') |
'1s'
|
max_duration
|
str
|
Maximum acceptable cycle duration (default: '1h') |
'1h'
|
warn
|
bool
|
Whether to log warnings for invalid cycles (default: True) |
True
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with additional 'is_valid' column and 'validation_issue' column |
detect_overlapping_cycles ¤
detect_overlapping_cycles(
cycle_df: DataFrame, resolve: str = "flag"
) -> pd.DataFrame
Detect and optionally resolve overlapping cycles.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cycle_df
|
DataFrame
|
DataFrame with cycle data |
required |
resolve
|
str
|
How to handle overlaps - 'flag' (mark only), 'keep_first', 'keep_last', 'keep_longest' |
'flag'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with 'has_overlap' column and potentially filtered rows |
suggest_method ¤
suggest_method() -> Dict[str, Any]
Suggest the best cycle extraction method based on data characteristics.
Analyzes the input DataFrame to recommend appropriate extraction method(s).
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dictionary with method suggestions and reasoning |
get_extraction_stats ¤
get_extraction_stats() -> Dict[str, Any]
Get statistics about the last cycle extraction.
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dictionary with extraction statistics including counts, success rate, and warnings |