Skip to main content

Twin Mapper

Import Jobs

Twin mapper apart of processing data coming from IoT devices (incoming from IoT Hub), can also perform Import Jobs, where the data is fetched from containers of the Twin mapper Storage Account. In order to initialize the data import, the file should be places in container named after the use case name and 'in' directory. <container-name>/in/

Transformed data is pushed to Azure Digital Twins through Bulk Import Jobs. Currently there are 3 use cases:

  • RTCM/RTCMZ
  • RTCMA
  • Generic CSV

For file naming and structure please check documentation or check with Developers.

ADT Relationship

There is possibility to create relations between Digital Twins by uploading a file to adt-relationship container. File name should follow the format adt_relationship_<source-device-prefix>.json Relations will be created using the Bulk Import Jobs.

Device Prefix is defined together with the Product and can be done through a frontend page by user or admin. The relations will be sent towards the Azure Digital Twin instance that is associated with the found Product.

Before creating the relation should be first defined in the Digital Twin Model.

The file format for defining relations:

[
{
sourceId: string,
relationshipName: string,
targetIds: string[],
sourceMetadata?: {
streamName: string,
...
}
}
]

If Digital Twin with sourceId does not exist, it will be created before relationship creation. sourceMetadata is an optional field. If it's present, the Twin with sourceId will be always upserted (update or insert) in the ADT. If sourceMetadata doesn't exist, Twin Mapper will verify if sourceId exists, if not, it will create new Twin, if yes, no action will be taken.

Development

The Twin mapper is responsible for mapping incoming messages to their digital twin counterpart. The mapping can be configured by the user via the frontend-application. The mapping templates are stored in a postgres DB. The postgres DB has to run in order to start Twin mapper

# Seed the Database
pnpm run db:init

# Run the twin-mapper
pnpm run dev:twinmapper
or
npm run start:dapr

Remarks

Any date format will be outputed as a "iso8601" format. The supported incoming date types are "iso8601" format, epoch or epoch millis.

DateTime will be mapped to "yyyy-MM-dd HH:mm:ss.000" ->  output example "2020-07-10 15:00:00.000"
Date will be mapped to "yyyy-MM-dd" -> output example "2020-07-10"
Time will be mapped to "HH:mm:ss.000" -> output example "15:00:00.000"

Test

The tests will cover many transformation cases:

# Run the tests
npm run test // to run all the tests
npm run test <filename> (eg. processor.test.ts) // run one test file

Deploying