question

Elena Haviland avatar image
0 Likes"
Elena Haviland asked Elena Haviland commented

How to count number of specific flow items into a sink?

A sink in my model accepts two different type of flow items. I'd like to keep count of how many of each type arrive at that sink and ideally have those numbers posted in my dashboard. m-line-transport-concept-d.fsm

Choose One
sinkcounting
5 |100000

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

Joerg Vogel avatar image
1 Like"
Joerg Vogel answered Elena Haviland commented

You can create two number labels in your sink. Then you increment each label if a condition becomes true that one type has entered the sink. You can show any label of an object in a dashboard. I think it is dynamic text which will do this. With the eye dropper tool you can choose the label directly from the sink in your 3D model, if you adjust the parameters and functions of the dashboard object.

Jörg

· 3
5 |100000

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

Elena Haviland avatar image Elena Haviland commented ·

Hi Jorg,

Thank you for the response. How would I code the condition statement so if it is true, then the label is incremented? Sorry, I'm not experienced in c++ coding..

The Label I created to keep track of the number of BuildModules that arrive at the sink is called BuildModule. Also at each source, I am assigning a unique item type (1, 2, or 3)

In the OnEntry trigger, I choose Data>Increment Value and then open the code edit, but I'm not sure what to enter? Here's what I have so far:

treenode item = param(1);

treenode current = ownerobject(c);

int port = param(2);

treenode thenode = label(item, "BuildModule");

if (getitemtype(item)==1);

{

double value =1; inc(thenode,value);

}

0 Likes 0 ·
Joerg Vogel avatar image Joerg Vogel Elena Haviland commented ·

count-items-by-label-attribute-at-sink.fsm is a model wherein s source creates items with a label named as "yourLabel". This label gets at each item the randomly choosen value of 1 or 2 and the color is set by this Number. The OnEntry trigger of the sink contains a code snippet which distinguishes whether the label value is 1 or 2. If it is 1 the node of the label called "yourLabel_if_1" is incremeted by 1. Otherwise the label called "yourLabel_if_2" is incremented by 1. It is important that node is incremented and not the label value:

Node of the Label: current.labels["yourLabel_if_1"]

labels is the attribute name of all Labels.

Value of the Label: current.yourLabel_if_1

0 Likes 0 ·
Elena Haviland avatar image Elena Haviland Joerg Vogel commented ·

Thank you Jorg. I'll keep this code snippit handy. Appreciate you taking the time to write it out for me.

0 Likes 0 ·
Matt Long avatar image
2 Likes"
Matt Long answered Elena Haviland commented

If you didn't want to have to worry about coding stuff up or adding labels, you could change the Sink object to be a Queue. Then set the Queue's Send To Port option to separate out the two different types of items and send one type to a Sink and send the other type to a different Sink. Then you could just chart the input of each of the Sinks to get the totals.

· 1
5 |100000

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

Elena Haviland avatar image Elena Haviland commented ·

Thanks Matt. Great approach.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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