Hi
Let's say I have a stream with this Shape
Timestamp | Temperature_1 | Temperature_2 | Temperature_3 | Temperature_4 | Temperature_5 | Temperature_6 | Some other stuff... |
---|---|---|---|---|---|---|---|
And I would like this output
Timestamp | Average | Minimum | Maximum |
---|---|---|---|
Average value between Temperature_1...Temperature_6 | Minimum value between Temperature_1...Temperature_6 | Maximum value between Temperature_1...Temperature_6 |
Is there any snippets which does this without do any loop?
Rightnow I am using DeriveFields but I don't think it's the proper way because what I have to do is
var expr = '';
expr += '(Temperature_1+Temperature_2+Temperature_3+Temperature_4+Temperature_5+Temperature_6)/6,';
var params = {
types: 'NUMBER, NUMBER, NUMBER',
t: stream,
columns: 'Average,Minimum,Maximum'
expressions: expr
};
var outputTable = Resources["InfoTableFunctions"].DeriveFields(params);
outputTable.RemoveField(<name of the field I want to remove>);
outputTable.RemoveField(<name of the field I want to remove>);
outputTable.RemoveField(<name of the field I want to remove>);
outputTable.RemoveField(<name of the field I want to remove>);
...
result = outputTable
but this has two problems:
1) DeriveFields I think is unproperly used because it's supposed to be used when the two infotables have the same fields, here they only have one in common then I have to remove all the other extra fields;
2) To calculate max e minimum temperature I use the function Math.max(Temperature_1, ..., Temperature_6) but expression parameter doesn't want expressions with comma inside so this won't work.
Do you have any better suggestion?
Solved! Go to Solution.
1) Yes you have to remove the extra columns
2) To use services which requiere more than one parameter you should use ";" as separator for expressions instead
1) Yes you have to remove the extra columns
2) To use services which requiere more than one parameter you should use ";" as separator for expressions instead
So you confirm that DeriveFields is the best snippet.
Thank you
Yes, but anyway you may do performance tests comparing iteration (Javascript) vs using DeriveFields (Java), becouse at the end the iteration it's always there, and as you are using Expressions on each Java iteration should do a Javascript call....
I see.
As long as I could check, Iteration is a quite long process when I have a stream on a long period (it takes something like 4 or 5 seconds) so I'm looking for the fastest (and CPU lighter) way.
I'll do all the tests.
Thank you