question

Paúl Alejandro R avatar image
0 Likes"
Paúl Alejandro R asked tannerp commented

How to register my product quantity by label or type in phpAdmin?

I´m trying to write a code that allows me to register information from my model in a database from phpAdmin. Until now, with the help of this tutorial: https://answers.flexsim.com/articles/19407/sql-tutorial-step-by-step-model-construction-29.html, I´ve been able to succesfully modify the code to register my product labels and arrival time into the sink, however, now I want to register the quantity of products that reach the sink by type or label. For example,as you can see if 2 items from product "2052" reach the sink after 10 seconds, that should be reflected in the database.

However, right now I have this line of code that registers the whole input of the sink, so it updates everytime any product enters. But there should be a way to modify this to make it tell me the input by label or type. (It should act as a view entries list.)

string Cantidad = numtostring(getstat (current,"Input",STAT_CURRENT));

FlexSim 18.1.2
querysqldatabasedatabase connectorquantity
php4.png (7.2 KiB)
php5.png (26.9 KiB)
· 2
5 |100000

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

Jacob Gillespie avatar image Jacob Gillespie ♦ commented ·

@Paúl Alejandro R Do you want it to add a new entry everytime? or do you want to update the row with the corresponding Etiqueta? It used to update before you changed the altquery.

It might be better to run the table clearing query in the OnReset trigger. With your current code it is clearing the the table when the input of the object is less than the number of rows in the table. This works but it is skipping the first entry since you are either clearing the table or inserting into the table.

0 Likes 0 ·
Paúl Alejandro R avatar image Paúl Alejandro R Jacob Gillespie ♦ commented ·
@Jacob Gillespie

I want to add an entry every time, that means that if 1 unit arrives at 10 seconds and a second unit of the same product arrives at 11 seconds, my chart should appear something like this:

Etiqueta(Label) Tiempo(arrival time) Cantidad(Quantity)
2055 10 1
2055 11 1

And I understand your point with the query; I am going to try what you said about making a query in the OnReset trigger.

0 Likes 0 ·

1 Answer

·
Jacob Gillespie avatar image
1 Like"
Jacob Gillespie answered Paúl Alejandro R edited

I would store the input by label in a couple of label Arrays.

string Tiempo = numtostring(time(),2, 3);
string Etiqueta = getlabel(item,"WIP");

current.labels.assert("Etiquetas", []);
current.labels.assert("Cantidades", []);
int indice = current.Etiquetas.indexOf(Etiqueta);

if(indice == -1) {
	current.Etiquetas.push(Etiqueta);
	current.Cantidades.push(1);
	indice = current.Cantidades.length;
}
else
	current.Cantidades[indice] += 1;

string Cantidad = string.fromNum(current.Cantidades[indice]);

string query = concat("insert into  `flexsimdata`.`outtimes2` (`Etiqueta`,`Tiempo`,`Cantidad`)values ('", Etiqueta, "','", Tiempo, "','", Cantidad, "');");
· 4
5 |100000

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

Paúl Alejandro R avatar image Paúl Alejandro R commented ·

@Jacob Gillespie Thank you very much! The only change I made to the code was to erase the "+=1" because I did not want the list to update in that way. I should have mentioned that this database I´m trying to build receives the output of a previous model to become the input of another one. I also followed your recommendation about the clear table query in the OnReset trigger and it works pretty well.

However, now I tried to include pallets with a certain amount of the same product, which means that I would want just one record with all the products that entered the same time.

That means that I need to include a condition, in which if two or more products have the same label and arrival time, their quantities should sum up (even if they do not enter in pallets). When the whole pallet reaches the sink, there is an error message.

When the table should update to:

Etiqueta(Label) Tiempo(Arrival time) Cantidad (Quantity)
40405 5.111 1
40405 6.652 1
2904 12 4

I really hope you can help me with this! I think this is the last missing piece I need.

Thanks a lot again!

0 Likes 0 ·
on-entry-sink.png (29.7 KiB)
ej-db.png (40.7 KiB)
error-message.png (10.6 KiB)
Jacob Gillespie avatar image Jacob Gillespie ♦ Paúl Alejandro R commented ·
@Paúl Alejandro R

Can you attach your model? It would help me to understand what you are trying to do better.

0 Likes 0 ·
Paúl Alejandro R avatar image Paúl Alejandro R Jacob Gillespie ♦ commented ·

@Jacob Gillespie Okay, let me put another example. In the model I attached, there is a dashboard which tells you how many items have reached the sink based on their type (or label, in this case it does not matter). I want to do the same for my database, but I want to add a new record when the time of arrival changes. Does that make sense?

db-prueba5.fsm

Etiqueta(Label) Tiempo(arrival time in seconds) Cantidad(Quantity)
2904
5.11 5
2904 7.52 1
40405 9 2
40405 9.15 1
2904 10 3
2904 11 1
0 Likes 0 ·
db-prueba5.fsm (31.8 KiB)
Jacob Gillespie avatar image Jacob Gillespie ♦ Paúl Alejandro R commented ·

@Paúl Alejandro R

If you take away to the "+=1" then you will just record 1 every time. You might as well get rid of what I added and set the Cantidad to 1 from the start. I guess I misunderstood what you were trying to do.

You are getting that error because the item entering the sink is a pallet which doesn't have a WIP label. You will have to change the code to look at the WIP label of the sub-objects in the pallet.

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.