ATTENTION

This 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

Go Back   FlexSim Community Forum > FlexSim Software > Q&A
Downloads

Q&A Using Flexsim and building models

  #1  
Old 08-19-2015
qin tian qin tian is offline
Flexsim User
 
Join Date: Dec 2007
Location: Shanghai, China
Posts: 137
Downloads: 115
Uploads: 0
Thanks: 59
Thanked 3 Times in 3 Posts
Rep Power: 161
qin tian is on a distinguished road
Default 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  
Old 08-20-2015
Anthony Johnson's Avatar
Anthony Johnson Anthony Johnson is offline
Manager of Product Development
 
Join Date: Jul 2007
Posts: 440
Downloads: 86
Uploads: 4
Thanks: 171
Thanked 899 Times in 288 Posts
Rep Power: 735
Anthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond repute
Default

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


All times are GMT -6.
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Copyright 1993-2018 FlexSim Software Products, Inc.