我的分钟数据分析器状态值(字符值)的时间序列较大(〜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");