question

Enrique Elizaga avatar image
0 Likes"
Enrique Elizaga asked Jeanette F commented

query state time from objects

Hi, I am getting the time in particular states in this way:

double FLHRS = 0;
Object FL = Group("name")[INDEX];
FLHRS += FL.as(Object).stats.state().getTotalTimeAt("travel empty");
FLHRS += FL.as(Object).stats.state().getTotalTimeAt("travel loaded");

Is there a way to do this using a query?

FlexSim 22.0.0
querysql queriesobject states
· 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.

Jeanette F avatar image Jeanette F ♦♦ commented ·

Hi @Enrique Elizaga, was Felix Möhlmann's answer helpful? If so, please click the "Accept" button at the bottom of their answer. Or if you still have questions, add a comment and we'll continue the conversation.

If we haven't heard back from you within 3 business days we'll auto-accept an answer, but you can always unaccept and comment back to reopen your question.

0 Likes 0 ·

1 Answer

Felix Möhlmann avatar image
1 Like"
Felix Möhlmann answered

You can clone the state profile node into a global table and then use an SQL query on that.

Object FL = Group("name")[INDEX];
treenode states = FL.find(">stats/state_current/profile").as(Table).cloneTo(Table("GlobalTable1"));
Table result = Table.query("SELECT SUM(time) FROM GlobalTable1 WHERE state == 'travel empty' OR state == 'travel loaded'");
double FLHRS = result[1][1];

Though that is just an extra step to arrive at the same result. Might I ask why you want to use a query instead of the command?

· 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.

Mischa Spelt avatar image Mischa Spelt commented ·

In that case, shouldn't something like this also work (untested!)?

Object FL = Group("name")[INDEX];
treenode states = FL.find(">stats/state_current/profile");

Table result = Table.query("SELECT SUM(time) FROM $1 WHERE state == 'travel empty' OR state == 'travel loaded'", states);

double FLHRS = result[1][1];


1 Like 1 ·
Enrique Elizaga avatar image Enrique Elizaga commented ·
Hi @Felix Möhlmann thank you for your answer. I was wondering if it was possible to query the object's statistics directly without that extra step. Thanks!
0 Likes 0 ·