你好,
我有時間溫度表1和操作開始和結束時間表2。我想在時間溫度日誌中添加一個新列,並在操作時間內處理單元格“操作”。有誰知道怎麼做?
凱文,
表2令人困惑,結束時間早於開始時間。 與溫度表匹配的唯一時間是開始時間。下面是一個腳本,但是,我預計結束時間晚於開始時間。
您可以通過連接與Time with Start Time匹配的兩個表來找到這些啟動操作,請參閱第二個JSL塊。
由於只有開始時間匹配,我向copydown添加了不同操作的代碼,並創建了一個持續時間列來直觀地比較溫度穩定性。
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 ) ) )
);
加入
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 )
)