PoseiDAT / schemas

The core schemas for the PoseiDAT data interchange formats
MIT License
1 stars 5 forks source link

Initial schemas for AIS entities and AIS measurements #30

Closed Nielsien closed 3 years ago

Nielsien commented 3 years ago

Things I added:

  1. AIS measurement schema
  2. AIS enums in a seperate folder and added it to the npm build:typings script
  3. AIS entity to the core schemas (ship with static AIS data properties)
  4. Spatial axes measurement schema

At the moment an AIS measurement is just a big object with lots of optional properties you can add. The way I wanted it to work is that a certain message_type value binds certain required properties, but could not find a way to satisify this yet, will look to it in the coming weeks.

I want to write more tests for the ais, but need to find a way to bind required properties to a certain message_type value

Example schema code of how I wanted it to work:

"oneOf": [
    {
      "if": {
        "properties": {
          "message_type": {
            "oneOf": [
              { "const": 1},
              { "const": 2},
              { "const": 3}
            ]
          }
        }
      },
      "then": {
        "required": ["position", "RAIM_flag","COG","true_heading", "special_maneuvre_indicator",
          "position_accuracy","ROT", "SOG", "timestamp"]
      }
    },
    {
      "if": {
        "properties": {
          "message_type": {
            "oneOf": [
              { "const": 4},
              { "const": 11}
            ]
          }
        }
      },
      "then": {
        "required": ["position", "position_accuracy", "position_device_type","timestamp",  "RAIM_flag", "SOTDMA_communication_state"]
      }
    }

    ...... etc.
  ]

But this code does not work with json schemas so need to find something. Maybe a way to do this is just to handle it in tests instead of json schemas. Or write a different schema for each message_type, but this would make a lot of duplicate properties in the total docs

Further my tests fail because it says: 'can't resolve reference https://poseidat.org/schema/enum/ais/ais-message-type.json' But I think the reason is that jest cant find my schemas since they arent yet on the live version. So I think i cant test those until they are live

Nielsien commented 3 years ago

Oops commitlint was disabled, next commits will be following the commitlint convention

Qwerios commented 3 years ago

Okay so this is more of a work in progress not ready for merging. A few things:

You added some odd capitalisation on the schema name. I think the DGNSS part of both the schema and filename should be lower case like the rest of the repo. Similar casing issues on the enums. We shy away from capitals in filenames due to some operating systems having case-insensitive filesystems. Also changing case is not always seen as a change in git.

typo in ais-special-maneuvre.json -> ais-special-maneuver.json

The reason jest fails is because not all the enum types are exported in schemas.ts. The schema validator imports them from there automatically so they need to be exported. I added the missing ais message type enum as a test and it then moved on to the next one thats missing. I recommend adding an ais namespace inside the enum structure to mirror the folder structure you chose.

So something like this:

export const schemas = {
  core: { ... },
  enum: {
    deviceType: enumDeviceType as JSONSchema7,
    effortZone: enumEffortZone as JSONSchema7,
    ...
    ais: {
      altitudeSensorTypes: enumAISAltitudeSensorTypes as JSONSchema7,
      shipTypes: enumAISShipTypes as JSONSchema7,
      ...
    }   
  }

Sort them alphabetically to ensure you can easily see which is missing.

And finally for the switching json schema structure look at the entry_type setup between the core/base-entry.json and the specialised schemas in the src/entry/ folder. The entry_type is defined as a string in the base class and the specific types use an enum with only 1 option. This will allow for runtime validation to pick the right schema. You will end up with specialised schemas in separate files though.

Qwerios commented 3 years ago

Oh and disabling commitlint is a bannable offense ;)

Nielsien commented 3 years ago

Very well and thanks!

The odd capitalization was to indicate a abbreviation of an term like they do in the navigation center docs, but will change to lower case. I'll improve on those points, and make a worthwhile pr.

I'll close this pull request and create a new fork with commitlint.