我有一個大的時間序列(~250,000)分鐘資料分析器狀態值(字元值)。 分析儀正常運作時的值為 NORMAL,校準期間的值為 CALIB。 校準每天進行一次,但在不同的時間(每天不同的時間)進行,並且持續時間不同,通常約為 30 分鐘。 每個一分鐘的數據點都有時間戳。 我需要為每個校準週期(從給定日期的校準狀態 CALIB 開始到校準狀態 CALIB 結束)分配一個唯一標識符,並產生一個包含每個校準週期的開始和結束時間的表。
我在 JSL 完全是個新手。 誰能提供一個例子來說明我如何使用 JSL 來實現這一點?
預先感謝您的任何幫助。
請找到一種方法(毫無疑問地有很多方法)。 使用匯總表可以連結到來源表,這可能很有用。 執行“檔案 > 新建 > 新腳本”,剪下並貼上下面的程式碼,然後“編輯 > 運行腳本”。
NamesDefaultToHere(1);
// Make some fake data to play with
n = 1000;
startDate = Date DMY( 01, 1, 2016 );
endDate = Date DMY( 12, 10, 2016 );
dates = Sort Ascending(J( n, 1, Random Integer(startDate, endDate) ) );
status = J( n, 1, Random Integer(1, 2) );
dt1 = New Table( "Callibrations",
New Column( "Date", Numeric, "Continuous", Format( "ddMonyyyy h:m", 35 ), Set Values( dates )),
New Column( "Status", Numeric, "Nominal", Set Values( status ), Value Labels( {1 = "NORMAL", 2 = "CALIB"} ) )
);
/************************************************************************************************/
/* Start here . . . */
/************************************************************************************************/
dt1 = CurrentDataTable();
// Define a column that increments when the 'Status' changes:
// https://community.jmp.com/t5/Discussions/Formula-for-automatic-counter-by-group-of-rows/td-p/20120
dt1 << New Column( "Counter", Numeric, "Ordinal", Formula( If( Row() == 1, 1, Lag( :Counter, 1 ) + (Lag( :Status, 1 ) != :Status)) ) );
// Get the start dates
dt1 << New Column( "Start Date", Numeric, "Continuous", Format( "ddMonyyyy h:m", 35 ), Formula( Col Min( :Date, :Counter ) ));
// Get the end dates
dt1 << New Column( "End Date", Numeric, "Continuous", Format( "ddMonyyyy h:m", 35 ), Formula( Col Max( :Date, :Counter ) ));
// Make the required summary table
dt2 = dt1 << Summary(
Group( :Counter, :Status ),
Min( :Start Date ),
Max( :End Date ),
statistics column name format( "column" ),
output table name( "Calibration Periods" )
);
dt2 << deleteProperty("Source");