Skip to main content
Version: 0.0.98

ts_shape.events.production.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
Classes
NameDescription
TargetEventsCompare any production metric to targets.

TargetEvents​

classsource
TargetEvents(
dataframe: pd.DataFrame,
*,
time_column: str = "systime",
shift_definitions: dict[str, tuple[str, str]] | None = 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, )

Functions
NameDescription
compare_to_targetCompare actual metric to per-shift targets.
target_achievement_summarySummarize target achievement over time.
target_hit_rateHow often are targets met?
Parameters
NameTypeDescriptionDefault
dataframeDataFrameLong-format timeseries frame (one row per sample, uuid identifies the signal).required
time_columnstrTimestamp column.'systime'
shift_definitionsdict[str, tuple[str, str]] | NoneMapping of shift name to (start, end) "HH:MM" times. None (default) uses three shifts: 06:00-14:00, 14:00-22:00, 22:00-06:00.None

compare_to_target​

methodsource
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
NameTypeDescriptionDefault
metric_uuidstrUUID of the metric signal (counter).required
targetsdict[str, float]Dict mapping shift names to target values.required
value_columnstrColumn containing metric values.'value_integer'
handle_resetsboolWhen True (default), treat a decreasing counter as a reset and count the production after the reset instead of losing it, so actual is the reset-aware total. The increments are computed once over the whole signal and booked to the shift of the reading that reports them, so the shifts add up to the signal total. The result gains a resets column with the number of resets observed in each shift. When False, actual is simply max(0, last - first) and a shift containing a reset reports too little.True
production_dayboolWhen True, the post-midnight portion of an overnight shift (e.g. 22:00 -> 06:00) is attributed to the shift's start date, so each (date, shift) group is one contiguous interval (the default). When False, readings are grouped by their raw calendar date; a night shift is then split across two dates and, with handle_resets=False, its group spans the whole day so last - first sweeps in other shifts' production. Only affects schedules with an overnight shift.True
Returns
TypeDescription
DataFrameDataFrame with columns:
DataFrame- date, shift, actual, target, variance, achievement_pct, status
DataFrame- resets (only when handle_resets=True)

target_achievement_summary​

methodsource
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
NameTypeDescriptionDefault
metric_uuidstrUUID of the metric signal (counter).required
daily_targetfloatDaily production target.required
value_columnstrColumn containing metric values.'value_integer'
handle_resetsboolWhen True (default), treat a decreasing counter as a reset and count the production after the reset instead of losing it, so actual is the reset-aware daily total, with increments booked to the day of the reading that reports them so the days add up to the signal total. The result gains a resets column with the number of resets observed each day. When False, actual is simply max(0, last - first) and a day containing a reset reports too little.True
Returns
TypeDescription
DataFrameDataFrame with columns:
DataFrame- date, actual, target, variance, achievement_pct, status
DataFrame- resets (only when handle_resets=True)

target_hit_rate​

methodsource
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
NameTypeDescriptionDefault
metric_uuidstrUUID of the metric signal (counter).required
daily_targetfloatDaily production target.required
value_columnstrColumn containing metric values.'value_integer'
as_frameboolWhen True (default), return a one-row DataFrame (see below). as_frame=False returns the dictionary form; it is deprecated, emits a DeprecationWarning and will be removed in the next major release.True
Returns
NameTypeDescription
DataFrame | dict[str, float | int]With as_frame=True (default), a one-row summary DataFrame with
columnsDataFrame | dict[str, float | int]
DataFrame | dict[str, float | int]- start, end, duration_seconds: first analysed day's midnight to the midnight after the last day (tz-aware in the data's tz; NaT / 0 without data)
DataFrame | dict[str, float | int]- total_days: Number of days analyzed.
DataFrame | dict[str, float | int]- days_on_target: Days where target was met.
DataFrame | dict[str, float | int]- hit_rate_pct: Percentage of days meeting target.
DataFrame | dict[str, float | int]- avg_achievement_pct: Average achievement across days.
DataFrame | dict[str, float | int]With as_frame=False (deprecated), a dict with the keys
DataFrame | dict[str, float | int]total_days, days_on_target, hit_rate_pct, avg_achievement_pct.