In manufacturing, is common to extract sensor data in the following form, where A and B correspond to similar devices (known as assets).
In this format, the user needs to create a combined formula for each parent group. For example:
(Input: Sensor data table needs specific columns per parent group)
When handling several assets, this becomes cumbersome, so a better way is to stack the data per group asset.
To do this programmatically, we need contextual data containing the hierarchy. For example:
(Input: asset hierarchy)
In JSL, how can you move from the sensor data and hierarchy (inputs) to the asset table (desired output)?
(output: asset data table)
All tables and scripts are attached. Here is the input table script (metadata containing parent-child is added as column properties).
Names Default To Here( 1 );
// New data table
dt = New Table( "sensor table" );
n_rows = 10;
n_additional_rows = 0;
// New column: Index
dt << New Column( "Index", Numeric, "Continuous", Format( "Best", 12 ) ) <<
Begin Data Update << Add Rows( n_rows );
dt:Index << Set Formula( Row() );
dt << End Data Update;
// A sensor
dt << New Column( "A sensor 1",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Selected
) << New Column( "A sensor 2",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Selected
) << New Column( "A sensor 3",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Selected
) << Group Columns( "A sensors", {:A sensor 1, :A sensor 2, :A sensor 3} )
<< Begin Data Update;
For Each Row(
dt,
:A sensor 1 = Random Normal( 0, 1 );
:A sensor 2 = Random Normal( 0, 1 );
:A sensor 3 = Random Normal( 0, 1 );
);
dt << End Data Update;
// B sensors
dt << Add Rows( n_additional_rows );
dt << New Column( "B sensor 1",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Selected
) << New Column( "B sensor 2",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Selected
/*) << New Column( "B sensor 3",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Selected*/
) << Group Columns( "B sensors", {:B sensor 1, :B sensor 2}) //, :B sensor 3} )
<< Begin Data Update;
For Each Row(
dt,
:B sensor 1 = Random Normal( 0, 3 );
:B sensor 2 = Random Normal( 0, 2 );
//:B sensor 3 = Random Normal( 0, 3.5 );
);
dt << End Data Update;
colnames = dt << Get Column Names( String );
for each({col, index}, colnames,
column(dt, col) << Set Property( "child", col ) );
// Calculations.
// New formula column: Stdev[A sensor ...r 2,A sensor 3]
dt << New Column( "Stdev[A sensors]",
Numeric,
"Continuous",
Format( "Best", 12 ),
Formula( Std Dev( :A sensor 1, :A sensor 2, :A sensor 3 ) ));
// Move selected column: Stdev[A sensors]
dt <<Move Selected Columns( {:"Stdev[A sensors]"n}, after( :A sensor 3 ) );
// New formula column: Stdev[A sensor ...r 2,A sensor 3]
dt << New Column( "Stdev[B sensors]",
Numeric,
"Continuous",
Format( "Best", 12 ),
Formula( Std Dev( :B sensor 1, :B sensor 2) ));//, :B sensor 3 ) ));
// Move selected column: Stdev[A sensors]
dt <<Move Selected Columns( {:"Stdev[B sensors]"n}, after( :B sensor 2 ) );
// Create metadata
For Each( {col, index}, {:A sensor 1, :A sensor 2, :A sensor 3},
col << Set Property( "parent", "A" ) << Set Property( "parent_alias", "asset" )
);
For Each( {col, index}, {:B sensor 1, :B sensor 2}, //, :B sensor 3},
col << Set Property( "parent", "B" ) << Set Property( "parent_alias", "asset" )
);
For Each( {col, index}, {:A sensor 1, :B sensor 1},
col << Set Property( "child_alias", "sensor 1" )
);
For Each( {col, index}, {:A sensor 2, :B sensor 2},
col << Set Property( "child_alias", "sensor 2" )
);
For Each( {col, index}, {:A sensor 3},//, :B sensor 3},
col << Set Property( "child_alias", "sensor 3" )
);