Hello,
I have time temperature table 1 and operation start and end time table 2. I would like to add a new column in time temperaure log and label the cell "operation" when it is in the operation time peroid. Does anyone knows how to do that ?
Kevin,
Table 2 is confusing, the End Time is earlier than the Start Time. The only time that matches with the Temperature Table is the Start Time. Below is a script, however, I expected end time to be later than start time.
You could find these start operations by joining the two tables matching Time with Start Time, see the second block of JSL.
Since only the start time matched, I added code to copydown the different operations, and created a duration column to visually compare the temperature stability.
Names Default to Here(1);
dt1 = Data Table("Table 1 Temperature log");
dt2 = Data Table("Table 2 operation Time");
dt1 << New Column ("Operation", character);
for(i=1, i<=nrows(dt2), i++,
tbeg = dt2:Start Time[i];
tend = dt2:End Time[i];
_idx = dt1 << get rows where( tend <= dt1:Time <= tbeg);
if(nrow(_idx)>0,
dt1:Operation[_idx] = "Operation " || char(i);
); //end if
); //end for
//since there is only one row that matches, copy down
//if End Time column was the end of the operation, this would not be needed
//--copy down and get duration
dt1 << New Column("Duration", Numeric, Continuous, Format("min:s") );
_idx = dt1 << get rows where (:Operation != "");
for(i=1, i<=nrow(_idx), i++,
init = dt1:Time[_idx[i]];
If(i < nrow(_idx),
tbeg = _idx[i];
tend = _idx[i + 1] - 1;
dt1:Operation[tbeg :: tend ] = dt1:Operation[_idx[i] ];
, //else
tbeg = _idx[i];
tend = nrow(dt1);
dt1:Operation[tbeg :: tend ] = dt1:Operation[_idx[i] ];
);
dt1[tbeg :: tend,"Duration"] = Transpose(dt1:Time[tbeg :: tend] - init);
);
//--graph
gb = dt1 << Graph Builder(
Size( 534, 454 ),
Show Control Panel( 0 ),
Variables( X( :Duration ), Y( :RoomTemp ), Overlay( :Operation ) ),
Elements( Points( X, Y, Legend( 9 ) ), Line( X, Y, Legend( 11 ) ) )
);
Join
Data Table( "Table 1 Temperature log" ) << Join(
With( Data Table( "Table 2 operation Time" ) ),
By Matching Columns( :Time = :Start Time ),
Drop multiples( 0, 0 ),
Include Nonmatches( 1, 0 ),
Preserve main table order( 1 )
)