question

Craig DIckson avatar image
1 Like"
Craig DIckson asked Matt Long commented

How to access tracked variable statistics in code

I am using tracked variables to gather statistics in my model. One is of type Level, used to count the number of pieces moved; the second is of type Time series.

I would like to access the Min/Avg/Max values in code using getstat(), similar to how I can with any PF Activity, e.g., getstat(trackedvariable("vPiecesReplenished"),"Content", STAT_CURRENT);

However this returns 3.4E38 (i.e., unknown value).

(For a PF activity I use getstat(getactivity("ProcessFlow", sActivity), sStatistic, STAT_CURRENT)

I'm guessing that "Content" is not the right statistic name? What names should I use, or is there a different command? Or is it possible at all?

Thanks,

Craig

FlexSim 16.2.2
flexscripttracked variable
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

Jacob Gillespie avatar image
2 Likes"
Jacob Gillespie answered Matt Long commented

Give an empty string as the name:

getstat(trackedvariable("vPiecesReplenished"),"", STAT_CURRENT);

Normally you have to specify which statistic you want from the given object, but a tracked variable is the statistic.

· 2
5 |100000

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

Matt Long avatar image Matt Long commented ·

Starting in FlexSim 2017 Update 1 you can use the TrackedVariable class. Then the code is even simpler:

TrackedVariable("vPiecesReplenished").value //Current value

The TrackedVariable class also includes methods for getting the average, maximum, minimum, etc.

1 Like 1 ·
Craig DIckson avatar image Craig DIckson commented ·

Thanks. I like easy answers ;-)

0 Likes 0 ·