发布日期: 04/13/2021

Examples of Data Feed

Reading Data

Here is a typical data feed script. It expects to find a string 3 characters long starting in column 11. If it does, it uses it as a number and then adds a row to the data table in the column “thickness.”

feed = Open Datafeed( );
myScript = Expr(
	line = feed << Get Line;
	If( Length( line ) >= 14,
		x = NumSubstr( line, 11, 3 ) );
		If( !Is Missing( x ),
			dt << Add Row( {thickness = x} )
		);
	);
);

Assign the script to the data feed object by using Set Script:

feed << Set Script( myScript );

Set Up a Live Control Chart

Here is a sample script that sets up a new data table and starts a control chart based on the data feed.

dt = New Table( "Gap Width" ); // make a data table with one column
dc = dt << New Column( "gap", Numeric, Best );
 

// set up control chart properties

dt << Set Property(
	"Control Limits",
	{XBar( Avg( 20 ), LCL( 19.8 ), UCL( 20.2 ) )}
);
dt << Set Property( "Sigma", 0.1 );
 

// make the data feed

feed = Open Datafeed();
feedScript = Expr(
	line = feed << Get Line;
	z = Num( line );
	Show( line, z ); // if logging or debugging
	If( !Is Missing( z ),
		dt << Add Row( {:gap = z} )
	);
);
feed << Set Script( feedScript );
 

// start the control chart

Control Chart(
	Sample Size( 5 ),
	K Sigma( 3 ),
	Chart Col(
		gap,
		XBar(
			Connect Points( 1 ),
			Show Points( 1 ),
			Show Center Line( 1 ),
			Show Control Limits( 1 )
		),
		R(
			Connect Points( 1 ),
			Show Points( 1 ),
			Show Center Line( 1 ),
			Show Control Limits( 1 )
		)
	)
);
 

/* Either start the feed from the device or test-feed some data

to see it work (comment out one of the lines):

feed << Connect( Port( "com1:" ), Baud( 9600 ) );*/

For( i = 1, i <= 20, i++,
	feed << Queue Line( Char( 20 + Random Uniform() * .1 ) );
	Wait( .1 ); // simulate a delay in the feed
);

Store the Script in a Data Table

You can further automate the production setting by placing a data feed script such as the one above in an On Open data table property. A property with this name is run automatically each time the table is opened (unless you set a preference to suppress execution). If you save such a data table as a template, opening the template runs the data feed script and creates a new data table.

需要更多信息?有问题?从 JMP 用户社区得到解答 (community.jmp.com).