cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
lehaofeng
Level IV

How the pass/fail formula works?

I'm having a problem where the formulas are returning null values.
The raw table is the raw data and there is a specification table, which is used to determine whether the raw data passes or fails according to the specification table. I have written a JSL, please help me to see what the problem is, thanks.

Names Default To Here( 1 );
//raw data
dt = Data Table( "raw data001" );

dt1 = dt << subset( all rows, all columns );

//spec table

dtbz = Data Table( "Spec" );
LSL = dtbz[0, 3];
USL = dtbz[0, 4];
dtbz << New Column( "combine", formula( :Project || :Item ) );

// Create separate judgment columns for the columns to be judged
items = Design( dtbz:Item << get values(), <<levels )[2];



// new column to justify the pass/no pass


For( i = 1, i <= N Items( items ), i++,
	it = items[i];
	
	dt1 << New Column( it || "—pass/no pass",
		formula(
					
			If(
				:Project == "A" & N Items( Loc( dtbz:combine << get as matrix(), "A" || it ) ) > 0,
					dtbz:LSL[Loc( dtbz:combine << get as matrix(), "A" || it )[1]] <= Column( dt1, items[i] ) <= dtbz:USL[
					Loc( dtbz:combine << get as matrix(), "A" || it )[1]], 	
					
				:Project == "B" & N Items( Loc( dtbz:combine << get as matrix(), "B" || it ) ) > 0,
					dtbz:LSL[Loc( dtbz:combine << get as matrix(), "B" || it )[1]] <= Column( dt1, items[i] ) <= dtbz:USL[
					Loc( dtbz:combine << get as matrix(), "B" || it )[1]], 	
					
				:Project == "C" & N Items( Loc( dtbz:combine << get as matrix(), "C" || it ) ) > 0,
					dtbz:LSL[Loc( dtbz:combine << get as matrix(), "C" || it )[1]] <= Column( dt1, items[i] ) <= dtbz:USL[
					Loc( dtbz:combine << get as matrix(), "C" || it )[1]], 	
					
				:Project == "D" & N Items( Loc( dtbz:combine << get as matrix(), "D" || it ) ) > 0,
					dtbz:LSL[Loc( dtbz:combine << get as matrix(), "D" || it )[1]] <= Column( dt1, items[i] ) <= dtbz:USL[
					Loc( dtbz:combine << get as matrix(), "D" || it )[1]], 	
					
						
						
			)
		)
	)
);

 

11 REPLIES 11
txnelson
Super User

Re: How the pass/fail formula works?

I annotated the script in an effort to make the reading of it easier.  I also made a minor change to the Try() function, moving it to providing a result to dtbzRow.  

See if this helps in the underastanding

Names Default To Here( 1 );
//raw data
dt = Data Table( "raw data001" );

dt1 = dt << subset( all rows, all columns );

//spec table

dtbz = Data Table( "Spec" );

// Create separate judgment columns for the columns to be judged
// items = Design( dtbz:Item << get values(), <<levels )[2];
// items = dt << get column names( string, numeric );
Summarize( dtbz, items = by( :item ) );

// new column to justify the pass/no pass

For( i = 1, i <= N Items( items ), i++,
	it = items[i];

	Eval(
		Substitute(
				Expr(
					dt1 << New Column( it || "—yield",
						formula(
							curProject = :Project;  // Get the value of the current row
							                        // in the raw data table
							dtbzRow = .;  // dtbzRow is the row in the spec table where
							              // the spec limits are for the current Project
							              // and the current Item  Initialize it to 
							              // a missing value so any previous value is
							              // removed
							// Set the dtbzRow value to the spec table row where the
							// limits for the Project and Item are found.
							// If no such row is in the spec table, set the value
							// to 0
							dtbzRow = Try(
								(dtbz << get rows where(
									dtbz:Project == curProject & dtbz:item == __it__
								))[1],
								0
							);
							
							// If a spec row is found, and there are both USL and LSL
							// limits then set the yield value.  If not found the 
							// yield value returned is a missing value
							If(
								dtbzRow > 0 & Is Missing( dtbz:LSL[dtbzRow] ) == 0 &
								Is Missing( dtbz:USL[dtbzRow] ) == 0,
								// If the column's value is between the LSL and USL
								// the value is set to 1, if outside one of the 
								// limits it is set to 0 
								If(
									dtbz:LSL[dtbzRow] <= As Column( dt1, __it__ ) <= dtbz
									:USL[dtbzRow],
									1,
									0
								),
								.
							);
						)
					)
				),
			Expr( __it__ ), it
		)
	);
);
Jim
lehaofeng
Level IV

Re: How the pass/fail formula works?

I understand, thanks for your patience!