trappy.plotter.Constraint module

This module provides the Constraint class for handling filters and pivots in a modular fashion. This enable easy constraint application.

An implementation of trappy.plotter.AbstractDataPlotter is expected to use the trappy.plotter.Constraint.ConstraintManager class to pivot and filter data and handle multiple column, trace and event inputs.

The underlying object that encapsulates a unique set of a data column, data event and the requisite filters is trappy.plotter.Constraint.Constraint

class trappy.plotter.Constraint.Constraint(trappy_trace, pivot, column, template, trace_index, filters, window)[source]

Bases: object

What is a Constraint?

It is collection of data based on two rules:

  • A Pivot
  • A Set of Filters
  • A Data Column

For Example a pandas.DataFrame

Time CPU Latency
1 x <val>
2 y <val>
3 z <val>
4 a <val>

The resultant data will be split for each unique pivot value with the filters applied

result["x"] = pd.Series.filtered()
result["y"] = pd.Series.filtered()
result["z"] = pd.Series.filtered()
result["a"] = pd.Series.filtered()
Parameters:
  • trappy_trace (pandas.DataFrame or a class derived from trappy.trace.BareTrace) – Input Data
  • column (str) – The data column
  • template (trappy.base.Base event) – TRAPpy Event
  • trace_index (int) – The index of the trace/data in the overall constraint data
  • filters (dict) – A dictionary of filter values
  • window – A time window to apply to the constraint.

E.g. window=(5, 20) will constraint to events that happened between Time=5 to Time=20. :type window: tuple of two ints

get_data_name()[source]

Get name for the data member. This method relies on the “name” attribute for the name. If the name attribute is absent, it associates a numeric name to the respective data element

Returns:The name of the data member
pivot_vals(data)[source]

This method returns the unique pivot values for the Constraint’s pivot and the column

Parameters:data (pandas.DataFrame) – Input Data
populate_data_frame()[source]

Return the populated pandas.DataFrame

class trappy.plotter.Constraint.ConstraintManager(traces, columns, templates, pivot, filters, window=None, zip_constraints=True)[source]

Bases: object

A class responsible for converting inputs to constraints and also ensuring sanity

Parameters:
  • traces (trappy.trace.BareTrace, list(trappy.trace.BareTrace) (or a class derived from trappy.trace.BareTrace)) – Input Trace data
  • columns (str, list(str)) – The column values from the corresponding pandas.DataFrame
  • pivot (str) – The column around which the data will be pivoted:
  • templates (trappy.base.Base) – TRAPpy events
  • filters (dict) – A dictionary of values to be applied on the respective columns
  • window (tuple of ints) – A time window to apply to the constraints
  • zip_constraints (bool) – Permutes the columns and traces instead of a one-to-one correspondence
constraint_labels()[source]
Returns:string to represent the set of Constraints
generate_pivots(permute=False)[source]

Return a union of the pivot values

Parameters:permute (bool) – Permute the Traces and Columns
get_column_index(constraint)[source]