Task 4: Creating a data model

You add a data model to enumerate the temperatures cold, warm, and hot. When you run the model, it displays a greeting and advice for a cold day.

About this task

In this task, you...

  • Create a data model for weather.
  • Enumerate a data type for temperatures in the data model.
  • Add a composite data type for weather to the data model.
  • Declare a dependency.
  • Update the logic in the decision model.
  • Run the model to check your changes.

You create a data model to define custom data types for your service. Basic data types, including string and integer, are predefined by default in Automation Decision Services. However, organizations often need custom data types that match their operations. For example, a car rental company might need special types such as car, fleet and rental price. These types are defined in a data model, and can be used in multiple artifacts in a decision service (see Creating a data model).

Step 1: Creating a data model and enumerating a data type

About this task

In this step, you create a data model and enumerate the values for a custom data type (see Working with enumeration types).

Tip: You can complete the data model by using external libraries. This operation is not covered in this tutorial. However, you can find it in the External Library tutorial in GitHub repository Automation Decision Services samples.

Procedure

  1. Click My Service in the navigation breadcrumbs to return to the main page of your decision service.
  2. Open the Data tab.
  3. Click Create to create a data model.
  4. Enter Data in the Name field, and click Create.
    The data model editor opens.
  5. In the data model editor, click the "" button next to Data types, and click Enumeration type in the menu.
  6. Change the name of the new enumeration type from new enum to temperature.
    Take a moment explore the editor. The first part displays the language, the documentation, and the different verbalizations of the vocabulary elements. You can collapse this part by clicking the arrow to the right of the type name.
  7. In the Values section, click the Add button twice to add two more values.
  8. Change the names of the values to cold, warm, and hot.
    Your changes are automatically saved. The enumeration type temperature is now defined by these values.

Step 2: Adding a composite data type

About this task

In this step, you add a composite data type that uses the enumeration type temperature. You define a composite data type by using a set of attributes (see Working with composite types).

Procedure

  1. In the data model editor, click the "" button next to Data types, and click Composite type in the menu.
  2. Change the name of the new composite type from new type to weather.
  3. In the Attributes section, click the Add button twice to create two attributes.
  4. Enter the following names and types for the attributes:
    Name Type
    temperature temperature
    rain forecast integer

    The weather data type is now defined by the temperature and the rain forecast.

Step 3: Declaring a dependency

About this task

In this step, you declare a dependency between the decision model and the data model to be able to use the types you defined in step 1 and 2 in the decision model.

Procedure

  1. Click the Navigation history button "" in the top right toolbar, and click My Model to open it.
  2. Open the Dependencies tab.
  3. Click the Add button to declare a new dependency.
  4. Select Data in the table and click Add.
    The custom data types are now ready to be used in the decision model.

Step 4: Changing the logic

About this task

In this step, you update the decision model to use the data types that you defined in your data model.

Procedure

  1. Return to the Modeling tab to work on your decision model.
  2. Change the name of the Rain forecast node to Weather, and change its output type to weather.
    Because these changes are automatically reflected in the dependent node, the Weather advice node shows an error. You resolve the error by updating the weather table to use the new data type.
  3. In the Weather advice node, open Logic > weather table.
  4. Double-click the header of the Rain forecast column, and change the name to Rain forecast %.
  5. Right-click the header again, and click Define column in the menu. Enter the following condition in the rule editor, and then click OK:
    the rain forecast of 'Weather' is at least <min> and less than <max>

    The table no longer displays an error.

  6. Right-click the header again, and click Insert column > Condition after in the menu.
  7. Change the name of the new column to Temperature.
  8. Right-click the header of the new column, and click Define column in the menu. Enter the following condition, and then click OK:
    the temperature of Weather is <a temperature>
  9. Double-click the first cell in the Temperature column, and select cold from the menu.
  10. Double-click the first cell in the Weather advice column, and enter a new message:
    Cold day. Take a coat.
  11. Hover over the warning icon "". It displays the following message:
    Lines 1 to 1 have gaps - Missing values: hot, warm

    You defined three values for the enumeration type temperature. One value is declared in the table, but the editor warns you that two values are undeclared: hot and warm. Because the model still runs, the editor shows a warning and not an error.

    You decide to ignore the warning for now, and disable the gap checking. You can return to the table to make additional changes after deploying the decision service in task 6.

  12. Right-click the Temperature column header, and deselect Check gap in the menu to hide the warning. The gaps do not prevent the operation of the model.
  13. Click Back to the diagram to close the editor.
    The table now provides advice for a cold day.

Step 5: Running the model

About this task

In this step, you run the model to test your changes.

Procedure

  1. Open the Run tab.
  2. Add the following test data:
    • name: Jamie
    • rainForecast: 0
    • temperature: cold
  3. Click Run. You get the following message:
    "Hello Jamie! Cold day. Take a coat."
  4. Change the test data:
    • name: Robin
    • rainForecast: 90
    • temperature: warm
  5. Click Run. You get the following message:
    "Hello Robin! Rainy day. Take an umbrella."
  6. Delete the test data for the next task.

What to do next

In the next task, you create a rain alert by adding an attribute to the composite type and defining the alert in a rule. You also change the interaction policy.