I am using on entry and on exit trigger in queue to calculate the real time volume and area in queue. I have set up the global variable and make them show in dashboard. However, the number is always higher than it should be. (For example, there's only 5 cubic feet in queue, but the calculation shows 11 or something else.) There might be some repeated calculation but I do not know how to avoid them.
The reason I am using this way is because the volume and the area of each item going into queue is different. Or if there are any other ways that I could use please let me know.
Thank you!
*I have queue1 and queue2, and my code is trying to calculate queue1 and queue2 separately, and also the total(sum) of queue1 and queue2.
*The code in queue1 and queue2 is basically the same. The difference is only the variable's name's different. (For example, name Queue1_Volume will become Queue2_Volume in queue2.)
*I have set the item label of Volume, Width and Length.
Here's my entry code for queue1:
Object current = ownerobject(c);
Object item = param(1);
int port = param(2);
double itemVolume = item.Volume ;
// update the accumulate volumes in queue
Queue1_Volume += itemVolume;
// updata queue's current volume
Current_Queue1_Volume += itemVolume;
// Update total queues' volumes
TotalQueueVolume += itemVolume;
// area counting
double itemarea = item.Length * item.Width ;
// update the accumulate area in queue
Queue1_area += itemarea;
// updata queue's current area
Current_Queue1_area += itemarea;
// Update total queues' area
TotalQueuearea += itemarea;
And the exit code for queue1:
Object item = param(1);
// get the leaving item's volume label
double itemVolume = item.Volume;
// update this queue's volume
Current_Queue1_Volume -= itemVolume;
// update total queues' volumes
TotalQueueVolume -= itemVolume;
// get the leaving item's area label
double itemarea = item.Length * item.Width;
// update this queue's area
Current_Queue1_area -= itemarea;
// update total queues' area
TotalQueuearea -= itemarea;