Skills modelling
4 minute read
Model operators skills
The Orchestrator REST API enables to create and read all the Digital Twin entities described
in Model section, in particular the characteristics (i.e. quasi-static data). CharacteristicDescriptor and
CharacteristicValue are used in order to model operator skills (e.g., work experience, manual dexterity), besides the
general features (e.g., sex, age, handedness).
This API is available through a dedicated Swagger interface for each Clawdite instance. Furthermore, it is possible to
generate API clients for several languages, such as Python, Java and JavaScript. The mentioned clients are already
generated and available within each Clawdite instance and make it possible to interact with Clawdite’s Orchestrator
from external components.
In the following a few examples about skills modelling will be provided.
Install the Orchestrator client dependencies
In order to use the generated API clients inside external components it is needed to correctly setup and install the dependencies. Note that you need a personal GitLab token for accessing the registries. In case you don’t have it please contact the project’s maintainers.
pip install orchestrator-python-client --index-url https://__token__:<your_personal_token>@gitlab-core.supsi.ch/api/v4/projects/86/packages/pypi/simple<dependencies>
<dependency>
<groupId>ch.supsi.dti.isteps.hdt</groupId>
<artifactId>orchestrator-java-client</artifactId>
<version>x.y.z</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>gitlab-maven</id>
<url>https://gitlab-core.supsi.ch/api/v4/projects/86/packages/maven</url>
</repository>
</repositories>npm install orchestrator-javascript-client --registry https://token:<your_personal_token>@gitlab-core.supsi.ch/api/v4/projects/86/packages/npm/Create a Skill
In order to define a skill it is needed to create a CharacteristicDescriptor with an associated CharacteristicValue.
Note that a CharacteristicDescriptor is uniquely linked to an already existing FactoryEntityModel.
Moreover, the Worker (or FactoryEntity in general) which possesses the skill (i.e., CharacteristicValue) needs to
be defined in advance.
import os
from datetime import datetime
from collections import OrderedDict
import orchestrator_python_client as hdt_client
from orchestrator_python_client import ApiClient, FactoryEntityModelCategoryDto, FactoryEntityModelDto, WorkerDto,
CharacteristicDescriptorDto, CharacteristicValueDto, FieldType
# NOTE: you need to specify the HDT_ENDPOINT and HDT_API_KEY environment variables
configuration = hdt_client.Configuration(host=os.getenv('HDT_ENDPOINT'))
configuration.api_key['apiKeyAuth'] = os.getenv('HDT_API_KEY')
api_client = hdt_client.ApiClient(configuration)
factory_entity_model_category_api = hdt_client.FactoryEntityModelCategoryApi(api_client)
factory_entity_model_api = hdt_client.FactoryEntityModelApi(api_client)
worker_api = hdt_client.WorkerApi(api_client)
characteristic_descriptor_api = hdt_client.CharacteristicDescriptorApi(api_client)
characteristic_value_api = hdt_client.CharacteristicValueApi(api_client)
operator_category = factory_entity_model_category_api.create_factory_entity_model_category(
FactoryEntityModelCategoryDto(name="Operator",
description="description")).payload
worker_model = factory_entity_model_api.create_factory_entity_model(
FactoryEntityModelDto(name="Worker",
description="description",
factory_entity_model_categories_id=[operator_category.id])).payload
worker = worker_api.create_worker(
WorkerDto(creation_date=datetime.now().isoformat(),
factory_entity_model_id=worker_model.id)).payload
# "Gender" characteristic creation
gender_descriptor = characteristic_descriptor_api.create_characteristic_descriptor(
CharacteristicDescriptorDto(name="Gender",
description="Operator gender",
factory_entity_model_id=worker_model.id)).payload
worker_gender = characteristic_value_api.create_characteristic_value(
CharacteristicValueDto(values=OrderedDict({datetime.now().isoformat(): "Male"}),
type=FieldType.STRING,
characteristic_descriptor_id=gender_descriptor.id,
factory_entity_id=worker.id)).payload
# "Manual dexterity" skill creation
manual_dexterity_descriptor = characteristic_descriptor_api.create_characteristic_descriptor(
CharacteristicDescriptorDto(name="Manual dexterity",
description="Operator manual dexterity",
factory_entity_model_id=worker_model.id)).payload
worker_manual_dexterity = characteristic_value_api.create_characteristic_value(
CharacteristicValueDto(values=OrderedDict({datetime.now().isoformat(): "41"}),
type=FieldType.NUMBER,
characteristic_descriptor_id=manual_dexterity_descriptor.id,
factory_entity_id=worker.id)).payloadimport java.util.Collections;
import java.time.LocalDateTime;
import org.openapitools.client.ApiClient;
import org.openapitools.client.api.FactoryEntityModelCategoryApi;
import org.openapitools.client.api.FactoryEntityModelApi;
import org.openapitools.client.api.WorkerApi;
import org.openapitools.client.api.CharacteristicDescriptorApi;
import org.openapitools.client.api.CharacteristicValueApi;
import org.openapitools.client.model.FactoryEntityModelCategoryDto;
import org.openapitools.client.model.FactoryEntityModelDto;
import org.openapitools.client.model.WorkerDto;
import org.openapitools.client.model.CharacteristicDescriptorDto;
import org.openapitools.client.model.CharacteristicValueDto;
import org.openapitools.client.model.FieldType
private void createSkill() {
// NOTE: you need to specify the HDT_ENDPOINT and HDT_API_KEY environment variables
ApiClient apiClient = new ApiClient().setBasePath(System.getenv("HDT_ENDPOINT"));
String apiKey = System.getenv("HDT_API_KEY");
if(apiKey != null && !apiKey.isEmpty())
apiClient.addDefaultHeader("x-api-key", apiKey);
final FactoryEntityModelCategoryApi factoryEntityModelCategoryApi = new FactoryEntityModelCategoryApi(apiClient);
final FactoryEntityModelApi factoryEntityModelApi = new FactoryEntityModelApi(apiClient);
final WorkerApi workerApi = new WorkerApi(apiClient);
final CharacteristicDescriptorApi characteristicDescriptorApi = new CharacteristicDescriptorApi(apiClient);
final CharacteristicValueApi characteristicValueApi = new CharacteristicValueApi(apiClient);
FactoryEntityModelCategoryDto operatorCategory = factoryEntityModelCategoryApi.createFactoryEntityModelCategory(
new FactoryEntityModelCategoryDto()
.setName("Operator")
.setDescription("description"));
FactoryEntityModelDto workerModel = factoryEntityModelApi.createFactoryEntityModel(
new FactoryEntityModelDto()
.setName("Worker")
.setDescription("description")
.setFactoryEntityModelCategoriesId(Collections.singletonList(operatorCategory.getId())));
WorkerDto worker = workerApi.createWorker(
new WorkerDto()
.setCreationDate(LocalDateTime.now().toString())
.setFactoryEntityModelId(workerModel.getId()));
// "Gender" characteristic creation
CharacteristicDescriptorDto genderDescriptor = characteristicDescriptorApi.createCharacteristicDescriptor(
new CharacteristicDescriptorDto()
.setName("Gender")
.setDescription("Worker gender")
.setFactoryEntityModelId(workerModel.getId()));
CharacteristicValueDto workerGender = characteristicValueApi.createCharacteristicValue(
new CharacteristicValueDto()
.setValues(new TreeMap<>() {{
put(LocalDateTime.now().toString(), "Male");
}})
.setType(FieldType.STRING)
.setCharacteristicDescriptorId(genderDescriptor.getId())
.setFactoryEntityId(worker.getId()));
// "Manual dexterity" skill creation
CharacteristicDescriptorDto manualDexterityDescriptor = characteristicDescriptorApi.createCharacteristicDescriptor(
new CharacteristicDescriptorDto()
.setName("Manual dexterity")
.setDescription("Worker anual dexterity")
.setFactoryEntityModelId(workerModel.getId()));
CharacteristicValueDto workerManualDexterity = characteristicValueApi.createCharacteristicValue(
new CharacteristicValueDto()
.setValues(new TreeMap<>() {{
put(LocalDateTime.now().toString(), "41");
}})
.setType(FieldType.NUMBER)
.setCharacteristicDescriptorId(manualDexterityDescriptor.getId())
.setFactoryEntityId(worker.getId()));
}import { Configuration, FactoryEntityModelCategoryApi, FactoryEntityModelApi, WorkerApi, CharacteristicDescriptorApi,
CharacteristicValueApi } from 'orchestrator-javascript-client';
// NOTE: you need to specify the HDT_ENDPOINT and HDT_API_KEY environment variables
const configuration = new Configuration({
basePath: process.env.HDT_ENDPOINT,
apiKey: { apiKeyAuth: process.env.HDT_API_KEY }
});
const factoryEntityModelCategoryApi = new FactoryEntityModelCategoryApi(configuration);
const factoryEntityModelApi = new FactoryEntityModelApi(configuration);
const workerApi = new WorkerApi(configuration);
const characteristicDescriptorApi = new CharacteristicDescriptorApi(configuration);
const characteristicValueApi = new CharacteristicValueApi(configuration);
async function createSkill() {
const operatorCategory = await factoryEntityModelCategoryApi.createFactoryEntityModelCategory({
name: "Operator",
description: "description"
});
const workerModel = await factoryEntityModelApi.createFactoryEntityModel({
name: "Worker",
description: "description",
factoryEntityModelCategoriesId: [operatorCategory.payload.id]
});
const worker = await workerApi.createWorker({
creationDate: new Date().toISOString(),
factoryEntityModelId: workerModel.payload.id
});
// "Gender" characteristic creation
const genderDescriptor = await characteristicDescriptorApi.createCharacteristicDescriptor({
name: "Gender",
description: "Operator gender",
factoryEntityModelId: workerModel.payload.id
});
await characteristicValueApi.createCharacteristicValue({
values: { [new Date().toISOString()]: "Male" },
type: "STRING",
characteristicDescriptorId: genderDescriptor.payload.id,
factoryEntityId: worker.payload.id
});
// "Manual dexterity" skill creation
const manualDexterityDescriptor = await characteristicDescriptorApi.createCharacteristicDescriptor({
name: "Manual dexterity",
description: "Operator manual dexterity",
factoryEntityModelId: workerModel.payload.id
});
await characteristicValueApi.createCharacteristicValue({
values: { [new Date().toISOString()]: "41" },
type: "NUMBER",
characteristicDescriptorId: manualDexterityDescriptor.payload.id,
factoryEntityId: worker.payload.id
});
}