4 Replies Latest reply on Jun 7, 2017 6:08 AM by fmanniti RSS
    fmanniti Creator

    Calculate average value between multiple column in stream

    Hi

    Let's say I have a stream with this Shape

    TimestampTemperature_1Temperature_2Temperature_3Temperature_4Temperature_5Temperature_6Some other stuff...

     

    And I would like this output

    TimestampAverageMinimumMaximum
    Average value between Temperature_1...Temperature_6Minimum value between Temperature_1...Temperature_6Maximum 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?