Skip to main content
Version: 0.0.98

Data model and layers

ts-shape is a set of pandas functions and classes. There is no runtime, store or scheduler: every step takes a DataFrame and returns one, so you can start at any layer with data you already have.

The input format​

All signals live in one long-format DataFrame, one row per sample:

ColumnTypeContent
systimedatetime (tz-aware recommended)sample timestamp
uuidstringsignal identifier, for example line1:running
value_doublefloatmeasured values
value_integerintcounters, codes
value_boolboolrun states, flags
value_stringstringpart numbers, order ids, state names
is_deltabool, optionalwhether the row is a change (delta) or a snapshot

A signal uses one value_* column; the others stay empty. Not every column has to be present, only systime, uuid and the value columns the detector reads. Detectors take the column names as arguments (time_column, value_column, ...), so other layouts work too.

Signal metadata (name, unit, configuration) is a second frame keyed by uuid. DataIntegratorHybrid joins the two.

What a signal is (a counter that resets, a change-encoded state, a sampled measurement) changes how it must be aggregated. Signal semantics and data checks describes how to declare this once as a SignalSpec and let detectors follow it.

Layers​

LayerPackageInputOutputExamples
Loadts_shape.loaderparquet, S3, Azure Blob, Databricks, TimescaleDB, JSONlong-format frameParquetLoader, AzureBlobParquetLoader, MetadataJsonLoader
Transformts_shape.transformlong framelong frameDoubleFilter, DateTimeFilter, TimezoneShift, DataHarmonizer
Featurests_shape.featureslong framestatistics, cycles, segments, feature tablesNumericStatistics, CycleExtractor, SegmentExtractor
Detectts_shape.eventslong frameevent or KPI tableMachineStateEvents, OEEEvents, OutlierDetectionEvents
Event logts_shape.eventlogdetector outputOCEL 2.0 tables, XES-style frameto_event_log, to_event_log_xes, to_event_log_ocel

Every arrow is a pandas DataFrame:

ts_shape.Pipeline chains transforms and detectors into one reusable definition (Pipelines).

Detectors​

Detectors are grouped into packs under ts_shape.events: quality, production, engineering, maintenance, energy, correlation, supplychain, development, and profiling (mapping-free machine profiles from raw PLC signals). Each detector is a class named ...Events that inherits from ts_shape.utils.base.Base. The base class:

  • copies the input frame, converts the time column to datetime and sorts by it;
  • converts nullable, pyarrow and text-number value columns to NumPy dtypes once;
  • raises ColumnNotFoundError when the time or uuid column is missing, and warns with DataQualityWarning when a signal uuid you pass is not in the data, or when a signal's values are in another value_* column than the one the detector reads (a counter in value_double read from value_integer); the warning names the value_column= to pass.

You configure the detector in the constructor and call its methods:

import ts_shape

df = ts_shape.make_timeseries(["line1:running"], n_points=500, freq="1min", value_column="value_bool")
state = ts_shape.MachineStateEvents(df, run_state_uuid="line1:running")
intervals = state.detect_run_idle(min_duration="2min")

ts_shape.list_detectors() lists every detector class, and ts_shape.list_detectors("events.quality") one pack.

Output shapes​

Every detector method returns a DataFrame in one of four shapes:

ShapeRequired columnsUsed for
pointsystime, uuid, source_uuidsomething that happened at an instant (an outlier, a rule violation)
intervalstart, end, duration_seconds, uuid, source_uuidsomething that lasted (a run, a downtime, a batch)
summarystart, end, duration_secondsa value per time window (OEE per day, parts per shift)
staticnonea table not tied to time (statistics by reason, a fitted model)

uuid is the event type the detector emits (for example quality:outlier) and source_uuid the signal it was found on. Column naming, units and error behavior are specified in Naming and output conventions.

Because the shapes are fixed, any detector output can be normalized into one event log. See Event log.

Extending​

  • A plain function df -> df can be a step in a Pipeline.
  • A threshold or interval rule can be declared in YAML as a lambda rule; it then works with the event log like a built-in detector.
  • A new detector class subclasses Base, returns one of the shapes above and registers a label rule (Adding a detector method).

Scope​

ts-shape runs in memory on pandas. It is meant for batch analysis of historian, data-lake and database extracts, not for low-latency control. Data larger than memory can be processed slice by slice (one day at a time, with events and windows stitched across the borders) by chunked processing, for the detectors whose result does not need the whole signal at once.