ATTENTIONThis FlexSim Community Forum is read-only. Please post any new questions, ideas, or discussions to our new community (we call it Answers) at https://answers.flexsim.com/. Our new Question & Answer site brings a modern, mobile-friendly interface and more focus on getting answers quickly. There are a few differences between how our new Q&A community works vs. a classic, threaded-conversation-style forum like the one below, so be sure to read our Answers Best Practices. |
flexsim.com |
|
Downloads |
Q&A Using Flexsim and building models |
#1
|
|||
|
|||
how to return time-weighted mean using getdatastat()
I wonder will the following code return time-weighted mean to avg?
I have defined myPhysicalStock as a tracked variable and checked it to be time-weighted. The mannual on getdatastat() doesn\'t tell me how to return time-weighted mean. Thanks treenode PhysicalStock = node("/Tools/TrackedVariables/myPhysicalStock", model()); double avg = getdatastat(STAT_MEAN, getbundlenrentries(PhysicalStock), getbundlevalue(PhysicalStock, count - 1, 1)) |
#2
|
||||
|
||||
First, I should notify you that in the next version (7.7 coming out in a month or two), this code will not work because we\'ve restructured the Tracked Variable such that the bundle is no longer stored on the node itself, but rather a sub-node. Also, I think in 7.7 you will be able to call getsdtvalue(trackedVariableNode, "mean") to get the mean.
That said, I think the way you would calculate the mean is: Code:
int numEntries = getbundlenrentries(PhysicalStock); double totalTime = getbundlevalue(PhysicalStock, numEntries - 1, 0) - getbundlevalue(PhysicalStock, 0, 0); double weightedSum = getdatastat(STAT_SUM, numEntries - 1, getbundlevalue(PhysicalStock, count - 1, 1) * (getbundevalue(PhysicalStock, count, 0) - getbundevalue(PhysicalStock, count - 1, 0)); double weightedMean = weightedSum / totalTime; |
The Following User Says Thank You to Anthony Johnson For This Useful Post: | ||
Jing Chen (08-22-2015) |
Thread | Thread Starter | Forum | Replies | Last Post |
getdatastat() | Pongjetanapong | FlexSim HC: Q&A | 7 | 07-30-2014 10:33 AM |
Return 0; | shafizad | Q&A | 5 | 05-05-2011 09:32 AM |
Return 0; | shafizad | Q&A | 9 | 02-22-2011 04:46 AM |
Return 0; | shafizad | Q&A | 0 | 12-13-2010 03:50 AM |
Does there exist a function that can calculate the time weighted average of a value in a Global tabl | qin tian | Q&A | 4 | 01-20-2008 07:01 PM |