Templates

What

Templates are entities that contain configuration data required to perform a task (of a service). This could be for instance the import/export or generation of events. In order to facilitate the searchability of templates, they are also classified by their (template)Type and one or more (template)Roles.

 

Import

The import of the events of a timeseries using a csv or json file is supported by the ms-utilities microservice (version 1.4.5 or higher). The ms-utilities can be tested via the (openApi) url: https://<baseUrl>/ms-utilities/v1/docs and requires an authorized user (username/password or jwt). To import the events, one requires a template (json document). This template is stored in the byNeuron database:

POST https://<baseUrl>/ms-utilities/v1/{tenant}/events/import/{template}

with tenant being the tenants unique key and template being the unique externalId of the template within that tenant.

 

Template description

{
  "general": {
		"fileNamePattern": "{{AccessPoint.externalId}}.*", 
		// file.originalname
		// Device/AccessPoint/Contract/Arrangement/Party...
		// relations can be owned or related but have to exist
		// if " quotes are everywhere, they will be removed
		"charset": "utf8",
		"mimetype": "text/csv", // file.mimetype txt -> text/plain, csv -> text/csv
		"eventsRow": 2,  // row number where the events start, first row is 0!
		"headerRow": 1, // row with the header of the events 'table'
		"separator": ";", // ; | \t
		"timeZone": "Europe/Amsterdam",
		"action": "create",  // create/update/delete
		"itemOwner": "Device",  // Optional: The EntityType owning the item, if not present we assume None
  },
  "columns": [
    {
      "index": 0,
      "valuePattern": [
        "{{AccessPoint.externalId}}"
      ]
    },
    {
      "index": 2,
      "valuePattern": "{{Event.timestamp | date:'YYYY-MM-DD HH:mm:ss'}}",
			"valuePrefix": "=" // in case there would be a prefix
    },
    {
      "index": 4,
      "headerPatterns": [ // pattern per header line!! rows before the evenst actually start
        "","{{Item.externalId}},.*"
      ],
      "valuePattern": "{{Event.value | integer}}" // integer  or float
    }
  ]
}
 

Notes:

  • patterns to capture variables and their values use a double escape for special characters!
    • eg "{{AccessPoint.externalId | date:'YYYY-MM-DD HH:mm:ss'}},[\\w]*,{{Device.name}},[\\w]*,[\\w]*,[\\w]*"
  • variables in a pattern are identified by the following pattern {{ <EntityType>.<attribute> (| <datatype>(:<format between quotes>)?)?}} with:
    • EntityType: AccessPoint, Device, Contract, Party, Arrangement, Place
    • attribute: the attribute of the entity
    • datatype and optional format:
      • string
      • integer
      • float:'3.3' → if format is specified, 3 leading digits and 3 decimals
      • date:'YYYY-MM-DD HH:mm:ss' → format of the date (ref moment.js)
 
 
 
 
 
Did this answer your question?
😞
😐
🤩