A Template is a user defined concept similar to a class, that groups common properties (e.g. properties of different twin items).

Templates allows you to bind together set of datapoints and properties common to your solution. You can typically define a re-usable schema in order to scale easily your solutions across all similar templates.

Creating a Template

To start registering a template inside the platform, you need to define an unique key identifier, a name and its properties. Properties of a template are typically datapoint (timeseries) or variable (string, integer and float).

For example: A my_example_factory_template might have as datapoint, Bearing1, Bearing2 and Bearing_anomaly and as variable threshold and as json Bearing_properties

Using the Python Toolkit, you can register a template using the following logic:

wizata_dsapi.api().upsert_template(
    key="my_example_factory_template",
    name="My Example Factory Template"
)

 wizata_dsapi.api().add_template_property(
    template='my_example_factory_template',
    property_name='Bearing1'
)
 wizata_dsapi.api().add_template_property(
    template='my_example_factory_template',
    property_name='Bearing2'
)
 wizata_dsapi.api().add_template_property(
    template='my_example_factory_template',
    property_name='Bearing3'
)

 wizata_dsapi.api().add_template_property(
    template='my_example_factory_template',
    property_name='Bearing4',
    property_type='datapoint'
)

 wizata_dsapi.api().add_template_property(
    template='my_example_factory_template',
    property_name='Threshold',
    property_type='float'
)

 wizata_dsapi.api().add_template_property(
    template='my_example_factory_template',
    property_name='Bearing_properties',
    property_type='json'
)

📘

property_type is by default datapoint and therefore not required.

Or parallelly, using the UI, clicking on Add and completing the form:

Image 1: Creating a template

Image 1: Creating a template

With the template_key you can also use lists and get methods linked to templates:

my_template = wizata_dsapi.api().get(template_key='my_example_factory_template')

Additionally, you can delete a template property using the remove_property() method, passing the template property name as a parameter:

# Removing humidity as a template property
wizata_dsapi.api().remove_property(name='Bearing1')

Or with the UI, once you click on the Edit Template Properties button inside your specific template:

Image 2: Editing Template Properties

Image 2: Editing Template Properties

Property type

A property can have multiple types:

  • datapoint: str corresponding to the hardware ID of datapoint.
  • json: Can be any complex JSON object, passed as a dict in python (must be serializable)
  • string: Char chain of type str.
  • integer: Is an int.
  • float: Is a floating decimal value.
  • relative: Is a time format based on now value; Format is now, then '+' or '-', then an integer value, then a unit ( y, M, d, h, m, s, ms. For example: “now-1d” , “now+1h”, “now”, “now-2M”, …)
  • datetime: Is a fixed datetime specified as an integer representing a ms epoch. All datetime are UTC based.

At the exception of datapoint when being used in a pipeline, all properties are passed in variables and context.properties.


Register a Twin

Once your template is created you need to register a Digital Twin. Each asset will have fixed value for variable and/or mapped datapoints.

Therefore, once querying a registered Twin on a template, you don’t need to know the detailed datapoint.

To register the Twin, you will have to create a map between a template property name and the value:

wizata_dsapi.api().register_twin(
    template="my_example_factory_template",
    twin="motor_1",
    properties={
        "Bearing1": "mt1_bearing1",
        "Bearing2": "mt1_bearing2"
        "Bearing3": "mt1_bearing3"
        "Bearing4": "mt1_bearing4",
        "threshold": 3.1, 
        "Bearing_properties": {"bearing_pressure_threshold": 89.5,
                               "bearing_temperature_threshold": 67}
      
    }
)

Once you register a twin, you need to set all properties correctly. The API will validate that your registration is respected, but if the template is modified, you will have to manually update all registrations.

Or with the UI, you can easily map the properties and the datapoints:

Image 3: Register a Twin

Image 3: Register a Twin


Query Template

After registering a twin on a template, you can /a dataframe based on the template:

df = wizata_dsapi.api().query(
    template="my_example_factory_template",
    twin="motor_1",
    datapoints = ["Bearing1","Bearing2"],
    start=datetime.strptime("2024-09-01", "%Y-%m-%d"),
    end=datetime.strptime("2024-09-02", "%Y-%m-%d"),
    interval=60000
)

📘

The dataframe received will contain as columns the property name of your template.

Any solution based on this dataframe should be compatible with any asset registered on the template.