question

Mischa Spelt avatar image
1 Like"
Mischa Spelt asked Mischa Spelt edited

Dynamically adding events to Statistics Collector

I am dynamically creating a fixed (as in, read from a parameter table) number of task executer flow items at the start of my simulation. I have put a custom state profile on them and am setting the states through various activities in my Process Flow. I would like to get some statistics such as a pie chart and Gantt chart on these items, so I tried to add them to a statistics collector. I found @jordan.johnsons example of a custom item trace Gantt, but that assumes that I have fixed resources in my model that I can use to trigger the Statistics Collector on. Of course I could add a dummy FR and send it a message every time I change my state, but I figured there should be a better solution.

First I tried pointing the Statistics Collector to the On State Change event of my flow item, hoping that when I 'instantiate' it the event listener would get copied along. Since that did not work, I put the flow item in a Group and had the Stats Collector listen to the On State Change for the group, but I guess that it adds event listeners to all the group members on reset.

I tried dynamically attaching my flow items to a statistics collector as follows:

treenode statsCollector = model().find("Tools/StatisticsCollectors/BargeStatevsTime");
function_s(statsCollector, "addEventReference", token.Barge, "OnStateChange");

but no data is added to its table (when I sample a fixed resource in the model, the table does get filled so the columns are set up correctly).

Could I get this to work somehow? If not, is what I want possible to achieve without the ugliest hacks (such as manually generating events on a Fixed Resource every I change the state or changing the model to use persisting task executers)?

EDIT: Here's a demo model.

FlexSim 17.2.2
statistics collectorflow itemsgantt chartstate profiles
customstates.fsm (17.5 KiB)
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

·
Jordan Johnson avatar image
1 Like"
Jordan Johnson answered Mischa Spelt edited

The Statistics Collector currently does everything on its reset. For now, I think the only way to dynamically add objects to the Statistics Collector would be to use the function_s "addEventReference" like you have done, and then use function_s to call OnReset for the statistics collector. It would be necessary to create all the TEs at once for that to work, but it sounds like you are doing that (always remember that those function_s calls are not guaranteed to work in future versions, although I have no current plans of changing them).

For now, that's the only workaround I can offer. We may improve the Statistics Collector's ability to handle dynamic objects in the future.

· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Mischa Spelt avatar image Mischa Spelt commented ·

Thanks Jordan, consider it a feature request :-)

Also noted that the "condition" of the event node has no data by default so to get this solution to work, I have to call

newEvent.find("/condition").value = 1

on the result of the Add Event call. In addition, the objects are not assigned an ID so trying to use StatisticsCollector.getID(current) gives "Invalid ID" so I'll have to make sure my objects have a unique name and use that.

1 Like 1 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.