cycle_processor
cycle_processor ¤
Assign sample data to cycles and compute per-cycle results.
Boundary rule (used by every method): a sample belongs to a cycle when
cycle_start <= systime < cycle_end. The interval is half-open, so with
back-to-back cycles a sample at the shared timestamp belongs to the later
cycle only, and every sample is counted once. A cycle without an end
(cycle_end NaT) gets no samples. Samples with a missing timestamp belong
to no cycle. Samples are matched on time only: pass the values of the machine
the cycles belong to.
CycleDataProcessor ¤
CycleDataProcessor(
cycles_df: DataFrame,
values_df: DataFrame,
cycle_uuid_column: str = "cycle_uuid",
time_column: str = "systime",
)
Bases: Base
A class to process cycle-based data and values with optimized performance. Samples are matched to cycles with a sorted search (no per-cycle scans).
Initializes the CycleDataProcessor with cycles and values DataFrames.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cycles_df
|
DataFrame
|
DataFrame containing columns 'cycle_start', 'cycle_end', and 'cycle_uuid'. |
required |
values_df
|
DataFrame
|
DataFrame containing the values and timestamps in the 'systime' column. |
required |
cycle_uuid_column
|
str
|
Name of the column representing cycle UUIDs.
|
'cycle_uuid'
|
time_column
|
str
|
Name of the column representing the timestamps for the
values. |
'systime'
|
Raises:
| Type | Description |
|---|---|
ColumnNotFoundError
|
If a cycle column or the time column is missing. |
TypeError
|
If one of cycles and values is tz-aware and the other naive. |
split_by_cycle ¤
split_by_cycle() -> dict[str, pd.DataFrame]
Splits the values DataFrame by cycles defined in the cycles DataFrame.
Returns:
| Type | Description |
|---|---|
dict[str, DataFrame]
|
Dictionary where keys are cycle_uuids and values are DataFrames with the corresponding cycle data.
Keys are in chronological cycle order; cycles without samples are
left out. Rows keep their |
merge_dataframes_by_cycle ¤
merge_dataframes_by_cycle() -> pd.DataFrame
Merges the values DataFrame with the cycles DataFrame based on the cycle time intervals.
Returns:
| Type | Description |
|---|---|
DataFrame
|
The samples that fall in a cycle, with an added |
group_by_cycle_uuid ¤
group_by_cycle_uuid(
dataframe: DataFrame | None = None,
) -> list[pd.DataFrame]
Group the DataFrame by the cycle_uuid column, resulting in a list of DataFrames, each containing data for one cycle.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataframe
|
DataFrame | None
|
DataFrame to be grouped by cycle_uuid. If None,
uses |
None
|
Returns:
| Type | Description |
|---|---|
list[DataFrame]
|
List of DataFrames, one per cycle uuid, in order of first appearance. |
split_dataframes_by_group ¤
split_dataframes_by_group(
dfs: list[DataFrame], group_column: str
) -> list[pd.DataFrame]
Splits a list of DataFrames by groups based on a specified column. This function performs a groupby operation on each DataFrame in the list and then flattens the result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dfs
|
list[DataFrame]
|
List of DataFrames to be split. |
required |
group_column
|
str
|
Column name to group by. |
required |
Returns:
| Type | Description |
|---|---|
list[DataFrame]
|
List of DataFrames, each corresponding to a group in the original DataFrames.
Rows whose |
Raises:
| Type | Description |
|---|---|
ColumnNotFoundError
|
If one of |
compute_cycle_statistics ¤
compute_cycle_statistics() -> pd.DataFrame
Compute statistics for each cycle.
Returns:
| Type | Description |
|---|---|
DataFrame
|
One row per cycle in |
compare_cycles ¤
compare_cycles(
reference_cycle_uuid: str,
value_column: str = "value_double",
) -> pd.DataFrame
Compare all cycles against a reference cycle.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reference_cycle_uuid
|
str
|
UUID of the reference cycle |
required |
value_column
|
str
|
Column holding the values to compare. |
'value_double'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
One row per cycle with data for |
Raises:
| Type | Description |
|---|---|
ColumnNotFoundError
|
If |
identify_golden_cycles ¤
identify_golden_cycles(
value_column: str = "value_double",
method: str = "low_variability",
top_n: int = 5,
target: float | None = None,
) -> list[str]
Identify the best performing cycles (golden cycles).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value_column
|
str
|
Column holding the values to evaluate. |
'value_double'
|
method
|
str
|
|
'low_variability'
|
top_n
|
int
|
Number of golden cycles to identify |
5
|
target
|
float | None
|
Target value, required for |
None
|
Returns:
| Type | Description |
|---|---|
list[str]
|
Up to |
Raises:
| Type | Description |
|---|---|
ValueError
|
For an unknown |
ColumnNotFoundError
|
If |