Table of Contents

Table of Contents

Tutorial Task 2.8 - Content By Type Over Time

Tutorial Task 2.8 - Content By Type Over Time

Task Overview

In this task, you will create a Statistics Collector that records the content in inventory by type over time:

This task is based on the same model that was used in the Task 1 of this series. For information on how to open the model, please refer to that task:

Statistics Tutorial 1 - Create a Basic Statistics Collector

Step 1 Add Events to the Statistics Collector

In this step you will add events to the statistics collector. To do this:

  1. Click on the Toolbox tab on the left of the screen and click the button to add a new tool. Navigate to the Statistics section and select Statistics Collector. This will open a properties window.
  2. Click on the field at the top and rename the statistics collector to ContentByTypeOverTime.
  3. On the Events tab, click on the sampler button . Then click on the Storage System in the Toolbox. Choose the On Slot Entry option.
  4. In the Additional Labels area, click the plus button , and choose Add label for this event....
  5. Set the Name of the label to Delta.
  6. Set the Value of the label to 1.
  7. In the Row Value(s) field, type the following code: data.item.Type
  8. Check the Finish involved rows after this event box.
  9. In the top left of the Events tab, click on the sampler button Then click on the Storage System in the Toolbox. Choose the On Slot Exit option.
  10. In the Additional Labels area, click the plus button , and choose Add label for this event....
  11. Set the Name of the label to Delta.
  12. Set the Value of the label to -1.
  13. In the Row Value(s) field, type the following code: data.item.Type
  14. Check the Finish involved rows after this event box.

Explanation

In this step, you listened to the On Slot Entry and On Slot Exit event. In both cases, you added a label to both events called Delta. Delta will be used later to increment or decrement the content, as items enter or exit inventory. Both events also use the item's Type label as the row value.

Step 2 Add Columns to the Statistics Collector

In this step, you will add columns to the Statistics Collector. To do this:

  1. Click on the Columns tab.
  2. Click the button and choose Add column.
  3. Set the column's Name to Time.
  4. Click the arrow next to the Row Add Value field select Time and then select Model Date/Time.
  5. Click the button once again and choose Add column.
  6. In the Name field, rename this column to Type.
  7. Click the arrow next to the Row Add Value field, point to Data, and choose Row Value.
  8. Set the Storage Type property to Integer.
  9. Click the button once again and choose Add column.
  10. In the Name field, rename this column to Content.
  11. Set the Event Value field to data.row.Content.
  12. Set the Storage Type property to Integer.
  13. In the Event/Column Connections area, select the Storage System - On Slot Entry event and check the Content box to connect this event to the Content column.
  14. Select the Storage System - On Slot Exit event and check the Content box to connect this event to the Content column.

Explanation

In this step, you added three columns: Time, Type, and Content. The Time and Type columns are straightforward; whenever an item enters or exits inventory, these two columns will record the current time and the Type associated with each row. The third column doesn't record a value when the row is added. Instead, it is connected to both events. Once the row has been added, then the statistics collector will fire its On Row Updating trigger, and then update the connected column. When that event happens, the Content column will record the value of Content, a row label on the data entity.

One remaining task is to make sure that the Content label has the correct data, which you will do later in this task.

Step 3 Set the Row Options for the Statistics Collector

This step has a single step: click on the Row Options tab, and check the Keep value and labels for finished rows box.

Normally, when you finish a row, the statistics collector deletes the labels connected with that row value. By checking this box, you can tell the statistics collector to keep those labels, as well as the row value. The row is still finished, however, and the row value and labels are disconnected from that row. The next time an event produces the row value, the statistics collector will add a new row, and connect the row value and the row labels to the new row.

This option allow the statistics collector to remember values between events, even though both events finish the row.

Step 4 Add Triggers to the Statistics Collector

In this step, you will add triggers to the Statistics Collector. To do this:

  1. Click on the Triggers tab.
  2. Click the plus button and choose On Row Updating.
  3. Click the plus button in the On Row Updating trigger and choose Increment row label.
  4. In the popup, set the Increment field to "Content".
  5. Set amount to increment by to data.Delta.
  6. Click the Apply button.

You can right click on the ContentByTypeOverTime collector in the Toolbox and select the View Table option. If you reset and run the model, you will see the table record the output by type each hour. You may wish to run the model as fast as possible to see the data populate.

Explanation

When an item enters the Storage System, the statistics collector creates the data entity and adds two important labels:

  • The item label (an event parameter label) records which item entered.
  • The Delta label (an additional label) records a value of 1.

This event returns the type of the item as the Row Value. Since the statistics collector always finishes its rows, it doesn't have a row for that row value. This means that it will always add a row for the value. However, because you checked the Keep value and labels for finished rows box, the Content label for that row is present, and remembers the previous value of Content for that row. Since the row value is the Type of the item, the Content label on this row matches the content for that Type.

When the row is added, the Time and Type columns are recorded. Then, the On Row Updating trigger fires, where you incremented the Content row label by Delta. In this case, Delta is 1, so the Content increases.

After the trigger fires, the statistics collector sets the Event Value of the Content column, because it is connected to the current event. In this case, the statistics collector records the value of the Content row label.

When an item exits the Storage System, the same process happens, except that the Content label is decremented, rather than incremented.

Step 5 Creating a Chart

Now you will create a chart to show the data in the statistics collector as a time plot. To do this:

  1. Click the Dashboards button at the top of the screen and select the Add a Dashboard option.
  2. While the dashboard view is active, navigate to the library on the left. Under the Base Chart Types section, find and drag a Time Plot chart onto the dashboard. This will open the new chart’s properties window.
  3. Click on the Data Source field and select the OutputByHourByType collector from the options.
  4. Set the X Values property to the Time column.
  5. Set the Y Values property to the Content column.
  6. Check the Type box in the Color Split By list.
  7. On the Settings, change the Draw Style property to Stair Step.
  8. Click on the Text tab.
  9. Check the Custom Title box, and set the custom title to Content By Type.
  10. In the Show Column Headers area, check the Type box.
  11. Click on the Colors tab.
  12. Click the Edit Values button, and choose Remove all colors.
  13. Click the plus button three times to add three colors.
  14. Click the Apply Button.

If you reset and run the model now, you will be able to see the chart show a time plot of your ContentByTypeOverTime collector. As before you may have to run the model for some time to see the results.