通過/失敗公式如何運作?我遇到了公式傳回空值的問題。
原始表是原始數據,還有一個規範表,用於根據規範表判斷原始數據是否通過。我寫了個JSL,請幫我看看是什麼問題,謝謝。
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>
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]], ) ) ) );
</LEVELS>
自動化和腳本回复:通過/失敗公式如何計算?這是對您的腳本的修改,我認為它簡化了它,並且仍然為您提供了收益

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, 4];
USL = dtbz[0, 5];
//dtbz << New Column( "combine", formula( :Project || :Item ) );
dtbz << New Column( "combine", character, formula( :Project || :Item ) );
// Create separate judgment columns for the columns to be judged
// items = Design( dtbz:Item << get values(), <<LEVELS> 0,
dtbz:USL[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:USL[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:USL[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:USL[Loc( dtbz:combine << get as matrix(), "D" || it )[1]] <= Column( dt1, items[i] )
<= dtbz:USL[Loc( dtbz:combine << get as matrix(), "D" || it )[1]],
)
)
);*/
Eval(
Substitute(
Expr(
dt1 << New Column( it || "—yield",
formula(
curProject = :Project;
Try( dtbzRow = (dtbz << get rows where( dtbz:Project == curProject & dtbz:item == __it__ ))[1], 0 );
If( dtbzRow > 0,
If( dtbz:LSL[dtbzRow] <= As Column( dt1, __it__ ) <= dtbz:USL[dtbzRow],
1,
0
)
);
)
)
),
Expr( __it__ ), it
)
);
);</LEVELS>
回复:通過/失敗公式如何計算?非常感謝您的快速答复,它有效。
回复:通過/失敗公式如何計算?你好吉姆,還有一個小問題是,當規範表中沒有找到對應的USL和LSL時,應該返回null值,但是這段代碼運行起來返回0。 我不知道發生了什麼事。
回复:通過/失敗公式如何計算?我提供的原始修改假設所有規格限制均可用。為了考慮到丟失限制的可能性,需要更改公式來處理這些情況。下面的 JSL 針對幾種可能的情況進行了調整,但您可能需要添加其他情況,例如:
USL 小於 LSL
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> 0 & Is Missing( dtbz:LSL[dtbzRow] ) == 0 & Is Missing( dtbz:USL[dtbzRow] ) == 0,
If( dtbz:LSL[dtbzRow] <= As Column( dt1, __it__ ) <= dtbz:USL[dtbzRow],
1,
0
),
.
);
)
)
),
Expr( __it__ ), it
)
);
);</LEVELS>回复:通過/失敗公式如何計算?謝謝,但是我有一個問題,為什麼之前的代碼會出現這個問題? 我看前面代碼的邏輯是:如果在SPEC表中找到了,那麼就判斷,沒有找到也沒有代碼,應該是空值啊,為什麼還要判斷呢?
回复:通過/失敗公式如何計算?計算值在行之間保持不變,因此,如果第 2 行中的條件未對計算值進行更改,則為第 1 行計算的值將保持不變。
回复:通過/失敗公式如何計算?謝謝! 我嘗試了一下,確實在之前的代碼運行下,如果在SPEC表中沒有找到,它將按照上一行的dtbzRow進行查找。 明明沒有找到,但是還是壓了上一行的值。 我在例程公式中沒有找到這一點,是否只有當我使用另一個表的查找時才會發生?
回复:通過/失敗公式如何計算?JMP 中的內存變量在更改之前保持不變。下面是一個腳本,它創建一個新列和公式,在第 1 行設置變量“a”,然後在第 10 行更改它。您可以看到“a”的值直到第 10 行才更改,但仍保持在到那時為止的初始設定值。
Names Default To Here( 1 );
dt =
// Open Data Table: Big Class.jmp
// → Data Table( "Big Class" )
Open( "$SAMPLE_DATA/Big Class.jmp" );
// New column: Column 6
Data Table( "Big Class" ) << New Column( "test",
Numeric,
"Continuous",
Format( "Best", 12 )
);
dt:test << set formula(
If( Row() == 1, a = 1 );
If( Row() == 10, a = a + 1 );
:test = a;
);
回复:通過/失敗公式如何計算?明白了,是因為如果在try語句中找不到,就不會賦值給它,導致原來的值,但是一開始的第一行就找不到了,那怎麼辦它分配了?
回复:通過/失敗公式如何計算?我對腳本進行了註釋,以使其更容易閱讀。我還對 Try() 函數進行了細微更改,將其移至向 dtbzRow 提供結果。
看看這是否有助於理解
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> 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
)
);
);</LEVELS>回复:通過/失敗公式如何計算?我明白了,謝謝你的耐心!