Hi,
Trying to optimize the iterations.
I have a reference table where each column is a name from a main data table column. I want to iterate through each row of the reference data table and then add the values from Column(dt_main, "Values") to New A and New B Columns in the reference table if Column(dt_ref, "Nrows")>2 & Comment[i] == "A > B".
I am using an associative array because I am interested only in the last recorded values of each type A and B, mapped to the corresponding X/Y/Wafer ID.
The below script takes a very long time. Is there a way to optimize?
Names Default To Here( 1 );
start = Tick Seconds();
dt_main = Data Table( "maintable" );
dt_ref = Data Table( "referencetable" );
Try( dt_ref << delete columns( :New N, :New R ) );
dt_ref << New Column( "New A", "Numeric" );
dt_ref << New Column( "New B", "Numeric" );
nrows = [];
For( nn = 1, nn <= N Rows( dt_ref ), nn++,
Insert Into( nrows, nn )
);
dt_ref << begin data update;
For Each( {r, i}, nrows,
If( dt_ref:N Rows[i] > 2 & dt_ref:Comment[i] == "A > B",
/// Create AA to get the last recorded values for each A and B to the corresponding X/Y/Wafer ID from dt_main
countsessions = Associative Array(
dt_main:Type[dt_main << get rows where( dt_main:X Coord == dt_ref:X Coord[i] & dt_main:Y Coord == dt_ref:Y Coord[i] & dt_main:Wafer ID == dt_ref:Wafer ID[i] )],
dt_main:Value[dt_main << get rows where( dt_main:X Coord == dt_ref:X Coord[i] & dt_main:Y Coord == dt_ref:Y Coord[i] & dt_main:Wafer ID == dt_ref:Wafer ID[i] )];
);
Try( dt_ref:New A[i] = countsessions["A"] );
Try( dt_ref:New B[i] = countsessions["B"] );
)
);
dt_ref << end data update;
end = Tick Seconds();
Show( Char( end - start ) );