How to import data from global table to empirical distribution table

How to import data from global table to empirical distribution table

hhnaing2
Not applicable
1,228 Views
7 Replies
Message 1 of 8

How to import data from global table to empirical distribution table

hhnaing2
Not applicable

[ FlexSim 23.2.0 ]

Hi,

I would like to connect to SQL server from the production line to pull the past one month uptime and downtime data of the machine. Upon accessing SQL server, it looks like data will be imported to global table. Then, how to import the data from global table to Empirical table automatically. That means once the model starts running, model connect to SQL sever and retrieve data then data will be imported to global table then empirical table. Would that be possible? if yes, appreciate if you could help to make a simple example model. Thanks a lot.

1692319220099.png


0 Likes
Accepted solutions (1)
1,229 Views
7 Replies
Replies (7)
Message 2 of 8

FelixMoehlmann
Collaborator
Collaborator
Accepted solution

You can use the code below to copy the table into the distribution. Just replace the distribution and table names so they match your model.

treenode distributionTable = Model.find("/Tools/EmpiricalDistributions/TestName>variables/data");
Table("TestTable").cloneTo(distributionTable.as(Table));
Message 3 of 8

hhnaing2
Not applicable

Where should this code be written? Global table>>on reset>> script edit? Thanks.

1692346707859.png

0 Likes
Message 4 of 8

jason_lightfoot_adsk
Autodesk
Autodesk

How often do you need it updated? If it's once then just put it in the script console and run it from there.

0 Likes
Message 5 of 8

hhnaing2
Not applicable
I want to update every time the model runs.
0 Likes
Message 6 of 8

jason_lightfoot_adsk
Autodesk
Autodesk

If you have other things that might sample the distribution at reset then you should do it either on reset (you may not be able to control the timing of this - it's based on which object you place the code), or you can use a parameter table entry OnSet trigger to run the code which then happens before all reset triggers fire.

Message 7 of 8

rhramac
Advocate
Advocate

Can this be done on some cadence (say every 5 mins) to update empirical distribution data? Will it reflect when we draw from this emperical distribution?

 

0 Likes
Message 8 of 8

FelixMoehlmann
Collaborator
Collaborator

If you mean to update based on an interval in simulation time, then you could so in a user event or in Process Flow. Changes to the data table during the simulation will affect future output of the distribution.

If you want to do that every x minutes of real time, then that would be difficult to do from within FlexSim. While you can get the current computer clock time with the "realtime()" command, there is no way to wait until a certain real time has elapsed. My only idea would be to regularly check the real time based on the run speed of the model and update the data when the time since the last update is large enough.

0 Likes