FlexSim Knowledge Base
Announcements, articles, and guides to help you take your simulations to the next level.
Sort by:
The Statistics Collector is a powerful object. Its purpose is to record data about the model run as a table, and it is very effect at doing that. However, it is very abstract; being abstract allows it to be highly flexible, but makes it more difficult to learn. This article is meant to help you understand (or remember) how the Statistics Collector models the problem of converting model data from objects and events into a table of data. This article compares a Statistics Collector to a train being loaded an unloaded. It is NOT an article about how to model a trainyard or other rail-industry systems. The purpose is to compare the Statistics Collector, which is very abstract, to something most people understand. So we'll start by talking about the story of a simple freight train. This story has the following elements: Starting - the train starts its journey a the beginning of the line Loading Stops - the train makes several stops along the way to load goods Unload Planning - unlike a normal train, this train determines where it needs to go after this point based on what was loaded into the train Unloading Stops - the train makes several stops along the way to unload goods This is a very simple story. Just keep the sequence in mind - the train starts, makes several load stops, figures out its destinations, and then makes several unload stops. To see how this is like a Statistics Collector, take a look at this model: StatsCollectorVisualization.fsm This model is very simple. It consists of a Source, Queue, Processor, and a final Queue: Items are generated at the Source and flow through the Model. Items have a Type label, so that there are three Types of items: Type 1, Type 2, and Type 3. If you zoom out, you'll see a much bigger section of the model: This section simulates the logic of a Statistics Collector. As the model runs, you'll see AGVs run along the track, like a train. You'll see them make several stops and pick up boxes. Then you'll see them stop at the "Table" (the bigger black box in the image above) and "unload" data into the table. The Statistics Collector tool is a lot like this simulation. It has an internal "train", and you reference that train with the keyword data. When you use the Statistics Collector, you are configuring the journey of the train, which determines what data is recorded in your table. Starting the Train The statistics collector creates a train (the data object) when it observes an event. You configure which events a Statistics Collector cares about on the Events tab. You can listen to many different things, including: A flowitem enters or exits an object A token enters or exits an activity The model is reset The model gets to the warmup time Whenever any of these things happen, the Statistics Collector creates a train (again, called data) and starts it going on its journey. In this example, the Statistics Collector listens for items to enter Queue1. It also listens for items to exit the processor. Either event will start a train. Loading the Train Once the train is going, the Statistics Collector "loads" the train with information. In reality, this happens by adding labels and setting values on data. First, data gets all the values associated with the event (the event parameters) assigned as labels. Then, data gets all the labels specified in the "Additional Labels" section. Finally, data visits the Row Value station. Here, the special property called rowValue is set. Note that as you load the train, you can use anything already on the train to get more information loaded on train. In the example model, the row value is set to "data.item.Type"; data is the train, and the "item" label is already on board, so the row value field can use that to load additional information. Unload Planning The next stop for the train is something that you can't really see, but that is very important. The Statistics Collector inspects the row value on data. The Statistics Collector remembers all row values that it has ever inspected, and it adds a row to the table for each unique row value. This is where the row value got its name. If the Statistics Collector sees a value it has never seen before, it adds a row to the table, and associates the new row with the row value. Once the row is either added or found, the Statistics Collector sets the property rowNum on data. So now, the train knows which row it is going to visit. All that is left in this phase is to figure out which columns the train will visit. First of all, if the row was added, the train will visit all the columns to set their initial value, which is called the Row Add Value (the value to set when the row is added). Whether or not the row was added by the event, the train will also visit any columns that are connected to the event, setting the value to the Event Value (the value to set when a connected event happens). So in summary, the Statistics Collector figures out which row the train will visit based on the row value, adding a row if necessary. If the row was added, then the train visits all columns in the row, to set the Row Add Value. If the event is connected to any columns, the train will also visit those columns, and set the Event Value. Unloading the Train Finally the train can unload data into the table. As it visits each cell, it unloads information into that cell. As the user, you configure what gets unloaded at each cell. You can unload anything into the cell, including anything on the train, anything connected to anything on the train, or anything globally accessible. In reality, whenever the Row Value or Event Value is evaluated, you can access and labels or properties on data. You can also use values on data to access other values. Or you can access global values, such as the current model time, or a Global Variable, or a value in a Global Table. In the example model, the Event Value field accesses the value that is currently in the table at the cell being visited by data. Does the statistics collector really have to travel? In the visualization model, the data train takes up time on the clock to load, plan, and unload. However, for the true Statistics Collector, all of that happens in zero time. For example, when an item enters Queue1, the real statistics collector in the model finishes updating instantaneously. In contrast, the visualized statistics collector train is still moving to get more labels. This is for illustration purposes only. What about "Update when accessed" columns? All Statistics Collectors know when something is trying to read their values. For example, if you have a chart pointed at a Statistics Collector, and that chart repaints, it will read the Statistics Collector. Or if you access the table through FlexScript with code like Table("MyStatisticsCollector")[1][1], that will read the Statistics Collector also. So in a way, it's just another event. However, there are two differences: You can't load custom labels on the train for this event; it "skips" those stops The train visits all rows in the table When you set a column to update when the value is accessed, you are basically connecting it the "OnAccess" event. So when the table is accessed, the data train visits all rows of the table. For each row, it gets the rowValue and rowNum properties set, and then it visits all the "update on access" columns. What about other features? This article just covers the basics, and doesn't cover other features of the Statistics Collector. Just know that there are many ways to configure the train's journey. For a full reference, see https://docs.flexsim.com/en/21.0/Reference/Tools/StatisticsCollector/ However, all of the features discussed in the reference add more detail; you can just improve your mental image of how the Statistics Collector works.
View full article
In version 2018 and on, you can make this chart by dragging the Throughput Per Hour by Type template from the dashboard library. If you install the template (available on the Advanced tab), you will see a Process Flow and a Statistics Collector appear in your toolbox. One of the most common questions from FlexSim users is as follows: How do I make a chart that shows the output every hour? You can make this chart in three steps. Configure the Statistics Collector First, you need a Statistics Collector. Make a new one in the toolbox (click the green plus button, select Statistics, and then select Statistics Collector). On the event listening tab, use the green plus button to add a timer event, and configure as shown here: This timer event will fire every hour (every 3600 seconds) in the model. Notice the shared label, that is storing all members of the Processors group as an array. We will use this label in the next step. Once you have configured the timer, then you need to set up the row mode for this collector. We want one row per processor, and we need to use the Processors label as the row value. Since the Processors label is an array, we will get three rows per timer event, each row corresponding to a processor. Finally, we can add the columns. The three columns are as follows: Time - use the pick list to select Model Date/Time from the Time menu Object - use the pick list to select ID of row value from the IDs menu Output - use the pick list to select Statistic by Object from the Object Statistics menu Use data.rowValue as the object value in the popup If you use the pick options to choose these options, then the storage type and display format options should be set automatically. With these three columns in place, we can watch the table populate. Reset and run the model at high speed. Every model hour, you should see a new set of rows appear, one for each processor in the group. The table will look something like this: Configure the Calculated Table The Statistics Collector table from the previous steps is close to what we want, except that the output value always increases as the model runs. But what about the output for just a single hour? To get that value, we can use a Calculated Table. Make a new calculated table, and give it the following query (in the Query field): SELECT Time, Object, ISNULL(Output - LAG(Output) OVER (PARTITION BY Object), 0) AS OutputPerHour FROM StatisticsCollector1 This query uses SQL window functions. Basically, it says that each row's value should subtract the previous row's value for the object. In addition, if that value is NULL (because it's the first row), then just use a value. If you reset and run the model, so that the collector table has at least a few rows in it, click the Update button to run the query. Notice that the Time and Object columns show numbers. This is because the Calculated Table can't infer the formatting of the column. To set the formatting, use the Display Format Tab. You may also wish the table to update every hour, with the Statistics Collector. Make the Chart Now that our data is correct, we can make a chart. Make a new dashboard, and create a Time Plot chart. Point the chart to the calculated table. Let's use the Time column for the X values, and let's use the OutputPerHour column for the Y values. In addition, make sure to split by the Object column. If the calculated table updates every hour, then running the model should create the chart shown at the beginning of the model. Here is the model used to create this chart (should work in 2017 Update 2 Beta or later; beta must be built on or after August 21, 2017). outputperhourdemo.fsm
View full article
Top Contributors