// ian.cox@jmp.com: 02Jun2005 // ****************************************************************************************** // Given a column reference, returns the spec limits in a vector, [lower, upper, target]: // If a limit is not defined it is returned as . // ****************************************************************************************** getSpecs = Function({col}, {Default Local}, // Note that the number of arguments in slp below can change! It can be 0 (if the // property is not even defined) or 1, 2 or 3 slp = col << GetProperty("Spec Limits"); // Assume that nothing is defined . . . l = .; u = .; t = .; // Find out what is defined . . . for(i=1, i<=NArg(slp), i++, thisExpr = Arg(slp, i); sType = Char(Head(thisExpr)); if ( sType == "LSL", l = Arg(thisExpr, 1), sType == "USL", u = Arg(thisExpr, 1), sType == "Target", t = Arg(thisExpr, 1) ) ); Matrix({l, u, t}) ); // ****************************************************************************************** // Given a table, make a new table containing the spec limits from the column properties // ****************************************************************************************** extractSpecs = Function({dt}, {Default Local}, // Make the new table cols = dt << GetColumnNames("String"); dt2 = NewTable("Spec Limits from "||(dt << GetName), AddRows(NItems(cols)), NewColumn("Variable", Character), NewColumn("LSL", Numeric), NewColumn("USL", Numeric), NewColumn("Target", Numeric), NewColumn("Mean", Numeric) // ); // Fill in the table for (c=1, c<=NItems(cols), c++, cName = cols[c]; specs = getSpecs(Column(dt, cName)); Column(dt2, "Variable")[c] = cName; Column(dt2, "LSL")[c] = specs[1]; Column(dt2, "USL")[c] = specs[2]; Column(dt2, "Target")[c] = specs[3]; Column(dt2, "Mean")[c] = Mean(Column(dt, c) << getValues); // ); // Return a reference to the limits table we made dt2 ); // ****************************************************************************************** // Given a column reference, sets spec liomits property // ****************************************************************************************** SetSpecLimits = function({c, lsl, usl, tar}, cmd = Expr(c << SetProperty("Spec Limits", {LSL(expr(lsl)), USL(expr(usl)), Target(expr(tar))})); eval(evalexpr(cmd)); ); // ****************************************************************************************** // Given a table dt, and a table dt1 containing spec limits, populates spec limit properties in dt // ****************************************************************************************** populateSpecs = Function({dt, dt1}, {Default Local}, // Loop over rows of dt1, and iff there is a matching column in dt set its property clist = dt << GetColumnNames(Numeric, String); for (r=1, r<=NRows(dt1), r++, name = Column(dt1, "Variable")[r]; lsl = Column(dt1, "LSL")[r]; usl = Column(dt1, "USL")[r]; tar = Column(dt1, "Target")[r]; if (Contains(clist, name), SetSpecLimits(Column(dt, name), lsl, usl, tar)); ) ); // Make a table with spec limits to test 'extractSpecs' dt = New Table( "Table With Limits Defined", Add Rows( 2 ), New Column( "100mAADCvalue", Numeric, Continuous, Format( "Best", 10 ), Set Property( "Spec Limits", {LSL( 9 ), USL( . ), Target( 25.5 )} ), Set Values( [20, 20] ) ), New Column( "100mADCIOCurrent", Numeric, Continuous, Format( "Best", 10 ), Set Property( "Spec Limits", {LSL( 44 ), USL( 194 ), Target( . )} ), Set Values( [103.2, 101.16] ) ), New Column( "800mAADCvalue", Numeric, Continuous, Format( "Best", 10 ), Set Property( "Spec Limits", {LSL( . ), USL( 192 ), Target( 172 )} ), Set Values( [173, 172] ) ), New Column( "800mADCIOCurrent", Numeric, Continuous, Format( "Best", 10 ), Set Property( "Spec Limits", {LSL( 719 ), USL( . ), Target( . )} ), Set Values( [800.15, 786.28] ) ), New Column( "ADCcalibrationhighvoltage", Numeric, Continuous, Format( "Best", 10 ), Set Property( "Spec Limits", {LSL( . ), USL( 135 ), Target( . )} ), Set Values( [125, 126] ) ) ); // Extract the limits dtLimits = extractSpecs(dt); Speak("Spec limits extracted"); Wait(5); // Make a table with no spec limits to test 'populateSpecs' dt2 = New Table( "Table With No Limits Defined", Add Rows( 2 ), New Column( "100mAADCvalue", Numeric, Continuous, Format( "Best", 10 ), Set Values( [20, 20] ) ), New Column( "100mADCIOCurrent", Numeric, Continuous, Format( "Best", 10 ), Set Values( [103.2, 101.16] ) ), New Column( "800mAADCvalue", Numeric, Continuous, Format( "Best", 10 ), Set Values( [173, 172] ) ), New Column( "800mADCIOCurrent", Numeric, Continuous, Format( "Best", 10 ), Set Values( [800.15, 786.28] ) ), New Column( "ADCcalibrationhighvoltage", Numeric, Continuous, Format( "Best", 10 ), Set Values( [125, 126] ) ) ); populateSpecs(dt2, dtLimits); Speak("Spec limits populated");