Azure / opendigitaltwins-dtdl

Digital Twins Definition Language
Creative Commons Attribution 4.0 International
466 stars 160 forks source link

Multidimensional units #96

Open krwq opened 3 years ago

krwq commented 3 years ago

Could you enable being able to create multidimensional units? Our (https://github.com/dotnet/iot) LSM9DS1 sensor (embedded on SenseHat) and many other sensors return 3-dimensional units but currently using array or object with units is not possible.

I.e.: (object)

{
    "@id": "dtmi:dotnet:iot:lsm9ds1:magnetometer;1",
    "@type": "Interface",
    "displayName": "LSM9DS1 - Magnetometer",
    "contents": [
        {
          "@type": [ "Telemetry" ],
          "name": "MagneticInduction",
          "displayName": "Magnetic induction",
          "description": "Magnetic induction vector in Tesla",
          "schema": {
              "@type": "Object",
              "fields": [
                  {
                      "name": "x",
                      "schema": {
                          "@type": "MagneticInduction",
                          "schema": "double",
                          "unit": "tesla"
                      }
                  },
                  {
                      "name": "y",
                      "schema": {
                          "@type": "MagneticInduction",
                          "schema": "double",
                          "unit": "tesla"
                      }
                  },
                  {
                      "name": "z",
                      "schema": {
                          "@type": "MagneticInduction",
                          "schema": "double",
                          "unit": "tesla"
                      }
                  }
              ]
          }
        }
    ],
    "@context": "dtmi:dtdl:context;2"
}

causes:

Unhandled exception. Parsing exception -- 3 errors in model -- see Errors property for details on each -- first error includes message: dtmi:dotnet:iot:lsm9ds1:magnetometer;1 has 'contents' value with name 'MagneticInduction' which has 'schema' value which has 'fields' value with name 'x' whose property 'schema' has value that does not have @type of Array, Enum, Map, or Object, nor is it a standard value for this property. Provide a value for property 'schema' with @type in the set of allowable types, or choose one of the following values for property 'schema': boolean, date, dateTime, double, duration, float, integer, long, string, time.

Array:

{
    "@id": "dtmi:dotnet:iot:lsm9ds1:magnetometer;1",
    "@type": "Interface",
    "displayName": "LSM9DS1 - Magnetometer",
    "contents": [
        {
          "@type": [ "Telemetry" ],
          "name": "MagneticInduction",
          "displayName": "Magnetic induction",
          "description": "Magnetic induction vector in Tesla",
          "schema": {
              "@type": "Array",
              "elementSchema": {
                      "@type": "MagneticInduction",
                      "unit": "tesla",
                      "schema": "double"
              },
          }
        }
    ],
    "@context": "dtmi:dtdl:context;2"
}

causes

Unhandled exception. Parsing exception -- 1 errors in model -- see Errors property for details on each -- first error includes message: dtmi:dotnet:iot:lsm9ds1:magnetometer;1 has 'contents' value with name 'MagneticInduction' which has 'schema' value whose property 'elementSchema' has value that does not have @type of Array, Enum, Map, or Object, nor is it a standard value for this property. Provide a value for property 'elementSchema' with @type in the set of allowable types, or choose one of the following values for property 'elementSchema': boolean, date, dateTime, double, duration, float, integer, long, string, time.
krwq commented 3 years ago

This might be a dup of https://github.com/Azure/opendigitaltwins-dtdl/issues/81

briancr-ms commented 3 years ago

Yes, based on the way we've been thinking about this, this would be a dup of #81. Without going into all the details, we've been thinking about enabling semantic types at the field level in an Object. Something like this example:

{
  "@type": "Object",
  "fields": [
    {
      "@type": [ "Field", "Temperature" ],
      "name": "temp",
      "schema": "double",
      "unit": "degreeCelsius"
    },
    {
      "@type": [ "Field", "RelativeHumidity" ],
      "name": "humidity",
      "schema": "integer",
      "unit": "percent"
    }
  ]
}

Would an approach like this cover your use cases?

krwq commented 3 years ago

Yes I think so, cc: @colombod

krwq commented 3 years ago

as a side note: since all fields are under "fields" should "Field" type be implied?

briancr-ms commented 3 years ago

Yes, we may be able to infer the "Field" type. That's one of the details that needs to be nailed down.