target_tracking
target_tracking ¤
Target vs actual comparison module.
Generic module for comparing any metric to targets: - Shift/daily target comparison - Variance analysis - Target achievement tracking over time
TargetEvents ¤
TargetEvents(
dataframe: DataFrame,
*,
time_column: str = "systime",
shift_definitions: (
dict[str, tuple[str, str]] | None
) = None
)
Bases: Base
Compare any production metric to targets.
Every plant has daily/shift targets. This module provides a generic way to compare actual performance against those targets.
Merge keys: [date, shift] for shift-level, [date] for daily.
Pipeline example::
target = TargetEvents(df)
result = target.compare_to_target('counter', {'shift_1': 450})
# → merge with PerformanceLossEvents.performance_by_shift() on [date, shift]
# → merge with QualityEvents.nok_by_shift() on [date, shift]
# → result['status'] column enables filtering/alerting
Example usage
tracker = TargetEvents(df)
Compare counter to fixed target¤
result = tracker.compare_to_target( metric_uuid='production_counter', targets={'shift_1': 450, 'shift_2': 450, 'shift_3': 400}, )
Achievement summary over time¤
summary = tracker.target_achievement_summary( metric_uuid='production_counter', daily_target=1300, )
compare_to_target ¤
compare_to_target(
metric_uuid: str,
targets: dict[str, float],
*,
value_column: str = "value_integer",
handle_resets: bool = True,
production_day: bool = True
) -> pd.DataFrame
Compare actual metric to per-shift targets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metric_uuid
|
str
|
UUID of the metric signal (counter). |
required |
targets
|
dict[str, float]
|
Dict mapping shift names to target values. |
required |
value_column
|
str
|
Column containing metric 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
|
production_day
|
bool
|
When True, the post-midnight portion of an overnight
shift (e.g. |
True
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with columns: |
DataFrame
|
|
DataFrame
|
|
target_achievement_summary ¤
target_achievement_summary(
metric_uuid: str,
daily_target: float,
*,
value_column: str = "value_integer",
handle_resets: bool = True
) -> pd.DataFrame
Summarize target achievement over time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metric_uuid
|
str
|
UUID of the metric signal (counter). |
required |
daily_target
|
float
|
Daily production target. |
required |
value_column
|
str
|
Column containing metric 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
|
|
target_hit_rate ¤
target_hit_rate(
metric_uuid: str,
daily_target: float,
*,
value_column: str = ...,
as_frame: Literal[True] = ...
) -> pd.DataFrame
target_hit_rate(
metric_uuid: str,
daily_target: float,
*,
value_column: str = ...,
as_frame: Literal[False]
) -> dict[str, float | int]
target_hit_rate(
metric_uuid: str,
daily_target: float,
*,
value_column: str = "value_integer",
as_frame: bool = True
) -> pd.DataFrame | dict[str, float | int]
How often are targets met?
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metric_uuid
|
str
|
UUID of the metric signal (counter). |
required |
daily_target
|
float
|
Daily production target. |
required |
value_column
|
str
|
Column containing metric values. |
'value_integer'
|
as_frame
|
bool
|
When True (default), return a one-row DataFrame (see
below). |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
DataFrame | dict[str, float | int]
|
With |
|
columns |
DataFrame | dict[str, float | int]
|
|
DataFrame | dict[str, float | int]
|
|
|
DataFrame | dict[str, float | int]
|
|
|
DataFrame | dict[str, float | int]
|
|
|
DataFrame | dict[str, float | int]
|
|
|
DataFrame | dict[str, float | int]
|
|
|
DataFrame | dict[str, float | int]
|
With |
|
DataFrame | dict[str, float | int]
|
total_days, days_on_target, hit_rate_pct, avg_achievement_pct. |