FloWorks - Statistic Collector (states, basic statistic)

FloWorks - Statistic Collector (states, basic statistic)

viktor_k4
Not applicable
2,121 Views
19 Replies
Message 1 of 20

FloWorks - Statistic Collector (states, basic statistic)

viktor_k4
Not applicable

[ FlexSim 21.2.4 ]

Hello FlexSim Community!


I’ve faced several issues regarding the implementation of Statistic Collectors. Available tutorials are only about the standard usage of Flexsim, while I work with the FloWorks module. I’ve attached a sample of the model I am working on.


Firstly, I wanted to add a statistic collector that records the daily state (Empty, Full, Filling, Releasing, Not Empty) of my tanks in hours during a simulation run (one year) - see Daily-States. To do so, I found this tutorial: https://answers.flexsim.com/questions/103600/statistics-collector-for-a-daily-collection-of-sta.html. However, the statistic collector generates zeros in the data table and I have no idea why. Maybe, there is a more efficient and simpler way to create such a collector.


Then, I wanted to record daily statistics of my tanks: current, minimum, maximum, and average content, output, and input - see Daily_Statistics_A1. To get the idea of how to do so, I used this tutorial: https://docs.flexsim.com/en/21.2/Tutorials/AdditionalTools/Tutorial2StatsCollector/2-9OutputByHourBy.... But, it seems that the collector doesn’t reset some of the values for the next day (max and min) and accumulates them during a simulation run (a trigger?). Also, the collector avoids day(0), so you can see zeros in the first row. In addition, it might be interesting to see how many times tanks reach their max and min volumes during a day.


I hope that my post will help other FloWorks users as well.


PS


I haven't updated FlexSim to the latest version yet.


Example_For_SCs.fsm

Accepted solutions (1)
2,122 Views
19 Replies
Replies (19)
Message 2 of 20

patrick_zweekhorst
Collaborator
Collaborator
Accepted solution

Hi @Viktor K4 ,

Thank you for asking such a nice question and doing all the research. The example model also helps us for answering your question. In the attached example model I have tried to answer the first part of your question. I will update the answer later for the second part.

I have made a really simple and small ProcessFlow to collect all the data that you need. This little flow just saves the total amount of time spend in a state. If you know that of till the start of the current day you can calculate how much time was spend in each state at the end of the current day. This creates a table like shown below:

1642774069960.png

Is this more or less what you are looking for? If not please let me know. Also let me know if you need a little more explanation on how this works.

Edit:
The second part of your question is a little bit more difficult. What I would do if I needed this information, is the following. I would create a tracked variable that exactly follows the content (or in/output) tracked variable of the tank. We can’t use the actual tracked variable because we will need to reset the tracked variable at the end of the day. To do this I again created a little ProcessFlow. The right part is just to follow the original tracked variable; the left part is to log everything at the end of the day. Please take a look at this flow and check if that makes sense. If not, we can always explain it a little more.
1642775821175.png

Patrick

example-for-scsTal.fsm

example-for-scsTal_1.fsm

Message 3 of 20

viktor_k4
Not applicable

Hello Patrick (@Patrick Zweekhorst)! Thank you for your explicit answer. Firstly, I tried to “digest” the example model and check all used class references with the FlexSim Manual. The first answer is clear to me, only why did you use state(1) in the SaveTimeState? Why do we need 1?


The second answer was a bit challenging to “digest” (not the logic behind it but rather the setting process), as there is not much information on tracked variables as in comparison to the Statistic Collector. I would appreciate your deeper explanation. One thing, when the Statistic Collector calculates the minimum content of each tank, it gives zeros in the Data Table. How to solve it?

0 Likes
Message 4 of 20

patrick_zweekhorst
Collaborator
Collaborator

Hi @Viktor K4 ,


To answer your first question. The 1 is needed since you want to log the FloWorks states. The default FlexSim states are logged on the default profile. FloWorks extends on FlexSim and uses its own state profile. This is the first custom profile of the objects. Using the FloWorks dashboard templates automatically set the number 1 for the state logging. Now that we make our own statistics collector we need to do this.

For the second part: Tracked variables can be very useful for collecting statistics. Maybe you have seen the tracked variables in the ToolBox. In this case, since you want to track statistics per Tank you don't want to create all those tracked variables in the ToolBox. If you would do that you would need to add extra tracked variables each time you add a tank. Also linking the tank to the correct tracked variable might be a bit more work. That is why I created some tracked variables on the tokens. They work the same as the global tracked variables from the ToolBox, but just stored on a label.

This also automatically creates extra tracked variables if you need more tanks. For setting the event correctly you will first need to sample any of the tracked variables out of the ToolBox. This makes sure you have the correct event to listen to. You can then change the Object reference to token.ContentTrackedVar. This right part is just to copy the contents tracked variable from the tank. When this content changes we save the current content and the current rate, if the content is changing. Of the left we log and reset the log tracked variable each day. This is also where the log of the minimum content goes wrong (I forgot to save the latest model....) We don't need to reset the tracked variable to value 0 and the beginning of the day, but to the current content of the tank. This can easily be changed in the "Reset tracked var" activity.

Where we had contentLog.reset() we need contentLog.reset( conterVar.value ). This resets the tracked variable to the current content instead of 0. You in fact don't need the next line anymore if you do this. There is no need to set the value of the tracked variable anymore because it is already set correctly.

1643049745263.png

I hope this helps you already some steps further. If not feel free to send me an email for some more help.

Patrick

Message 5 of 20

viktor_k4
Not applicable
Hi @Patrick Zweekhorst,


Thank you for your explanation! I feel more knowledgeable in the topic now.


A minor question. Since my tanks have initial volumes, is there a way to make the statistic collector (Daily Content) gather the data starting from the first day? I played with the Delay activity and it didn't work out.

0 Likes
Message 6 of 20

patrick_zweekhorst
Collaborator
Collaborator

Hi @Viktor K4 ,


In that case we just need to set the initial value for the content log tracked variable. This can be done in the second SetCounters activity:

1643287173882.png


Instead of 0 you can just put in the content of the tank.

Please let me know if this does not help

Patrick

Message 7 of 20

viktor_k4
Not applicable
Hi! Sorry for such a late reply. Everything works! Thank you! Is there also a simple method to calculate daily states in percentages (24 h = 100%)?
0 Likes
Message 8 of 20

ryan_c10
Not applicable

Hi @Viktor K4,

I added a Calculated Table to the model to get the daily states as percentages. You just have to take each column in the DailyStatesCollector divided by 24, then display it as a percent. I also made the modifications that @Patrick Zweekhorst pointed out in his replies to your comments above.

example-for-scstal-1-rc.fsm

I hope this helps! Let us know if you have further questions!

Message 9 of 20

viktor_k4
Not applicable
Hi @Ryan Clark,


Thank you for your contribution in solving my issue. I've implemented your elegant solution in my current model, and it works just fine. I hadn't used Calculated Tables before, so it was a new learning experience for me :).

0 Likes
Message 10 of 20

ryan_c10
Not applicable
No problem! Glad to help!
0 Likes
Message 11 of 20

viktor_k4
Not applicable

Hello @Ryan Clark,


Actually, I have a pertinent question. I want add a custom state "Analysis" in my model, when a tank is being analysed (see the "Analysis_1" activity). How to do it? The purpose of it is that I can add this state to my statistic collector and collect more specific data. New_Example_States.fsm

0 Likes
Message 12 of 20

ryan_c10
Not applicable

Hi @Viktor K4,

I modified your model to add the custom state you wanted. See the video below to see how I added the custom state into each tank:

add-custom-state-demo.gif

Then, I added a couple of Custom Code activities in your Process Flow to manually set the state to Analysis and then back to Full. I also added to the SaveTimeState and SetCounters activities a label for the time spent in Analysis, and I added related columns in the Statistics Collector and in the Calculated Table.

new-example-states-rc.fsm

0 Likes
Message 13 of 20

viktor_k4
Not applicable

Thank you for answer, @Ryan Clark. How those two activities - "Set State (Analysis)" and "Set State (Full)" are actually connected? In my original model, I have multiple analyses, and two of them, for example, are conducted when a tank has received a certain amount of product. Besides, I've tried to do the same to truck multiple fillings of different products (blending), and it gives 0s.

0 Likes
Message 14 of 20

ryan_c10
Not applicable

Hi @Viktor K4,

Here's how those Custom Codes are set up:

screenshot-2022-03-01-154616.png

You just reference the Object on which you want to set the state. I found that it wouldn't work well unless I included a Breathe activity before the first Set State activity, so you might want to try that. If you have multiple objects that you need to manually set the state of, then you can do that with multiple custom codes. You just need to make sure to add the custom state into each object's tree like I demonstrated in my previous post.

I hope this helps!

0 Likes
Message 15 of 20

viktor_k4
Not applicable

Hi @Ryan Clark,


Not really. Anyway, I've added to the model a new process which logically follows one of processes in my original model. There are multiple fillings and analyses (+ tech delay), and each of them has its own state. Also, I've updated SaveTimeState, SetCounters, and DailyStatesCollector (calculated table is not updated). Overall, States regarding fillings and tech delay don't work at all, while states regarding both analyses work fine. Could you check it and explain why some of them work and some of them don't work at all?

Updated_Example_States1.fsm

0 Likes
Message 16 of 20

ryan_c10
Not applicable

Hi @Viktor K4,

Sorry for the confusion! I updated your model, and it seems to work as you want now. I was able to solve most of the issues by adding in additional Breathe activities. The problems mostly seem to arise when certain events occur at the same timestamp, but still happen in a certain order. For example, the state would change from "fillingA," but then immediately change to "filling" since the tank technically hadn't started filling yet, and those states change automatically on the FlowObject. So, adding Breathe activities just helps to delay the Set State activities just enough, so they don't get overridden by the automatic state changes.

The only really weird thing is that the tank's state was randomly changing to "full" partway through its releasing process. This seems like it's probably a bug, so I just added a workaround by adding a Wait for Event and a couple Breathe activities to change the state back to "releasing" after it changes to "full."

@Patrick Zweekhorst, would you mind taking a look at this potential bug? Thanks!

I also went ahead and updated the Calculated Table for the percentages. I hope this helps! Best of luck!

updated-example-states1-rc.fsm

0 Likes
Message 17 of 20

patrick_zweekhorst
Collaborator
Collaborator

@Viktor K4 , @Ryan Clark ,


The problem that the tank goes into state full seems to be related to the model logic. At time 38 a token goes through the Set State (full) activity, which sets the state of tank A3. Looking at the logic I think this token should not be related to tank A3, but I am not sure about this.
1646294296426.png

0 Likes
Message 18 of 20

viktor_k4
Not applicable

Hello @Ryan Clark ,


Thank you for your prompt answer. It works well now in the example model, however I've faced one more issue. In my original model, both fillings (product A and B) usually takes a few days. Due to this fact, state "filling_A" (or "filling_B") changes to just "filling" after one day of operation. Is there a way to solve this (e.g., delete state "filling") ? Additional "breathe" activities doesn't do the trick. Maybe @Patrick Zweekhorst knows the answer.


In the updated example model I've attached to this answer, both fillings are prolonged, and state "filling_A" (or "filling_B") keeps being unchanged and works fine (see DailyStatesCollector and DailyStates_Percentages). Maybe my original model is too complex.

updated1.1-example-states1-rc.fsm

0 Likes
Message 19 of 20

patrick_zweekhorst
Collaborator
Collaborator
Hi @Viktor K4 ,


It can be that the state of the flow tank is reset after a network calculation. This makes setting your own states a bit more difficult. This looks a bit like the states of the task executer. I know this is something you wanted to discuss with Abel right?

If you want I can take a look at your original model. If you don't want to post it in an open question here for everyone to see you can also email it to me. I can then summarize what we find under this post.

0 Likes
Message 20 of 20

viktor_k4
Not applicable

Hi @Patrick Zweekhorst,


I see. It's not an urgent task for me at the moment, so I can ask about it during the last training session with Abel if he schedules the session any time soon (e.g., the first half of the next week). Thanks!