在Tabbox循環中控製圖表您好,我正在開發一個自動腳本,用於根據參數列表輸出控製圖。我有一個堆疊數據表,如下所示

我試圖從中生成控製圖。就腳本而言,到目前為止,我有這個
Rcols = dt_final << Get Column Names();
id = dt_final << get kets;
tb = tabbox();
for(i, i<=nitems(id), i++,
cols = Rcols;
dt = dt_final << subset(by(id[i]));
dt << sort(by(dt, :DATE_TIME_START), Order(Ascending), Replace Table);
ccExpr = Expr(Control Chart(
Sample Label( column(dt,:DATE_TIME_START) ),
KSigma( 3 ),
For( i = 1, i <= N Items( cols ), i++,
insert into(ccExpr, EvalExpr(Chart Col( Column( dt_final, Expr(cols[i]) ), Levey Jennings )))
);
cc = Eval(EvalExpr(
platform(dt_final,
Expr(
nameexpr(ccExpr)
)
)
));
);
tb << Append(group, cc);
// Create the display window
));
nw = New Window( "Control Charts", Outlinebox("Control Charts By Process ID", tb));我知道我可能不是最好的解決方法,但這最終是我需要做的:
- 子集dt_final由分組
- 將日期列更改為數字 - >連續 - >時間 - > m / d / yh:m(僅用於均勻性)
- 按date_time_start對子集進行排序
- 為每列生成levey jennings控製圖並將其附加到tabbox
- 並且因為不是每個組都有所有列刪除沒有數據的圖表
這裡仍然缺少一些步驟,就像更改日期數據類型一樣,但是,如果有人可以在這個循環上給我一些方向。
謝謝。
Re:在Tabbox循環中控製圖表對不起,這是因為原始腳本在腳本中都有cols和Rcols(它們都是相同的)。 我刪除了cols但忘記更新腳本中構建控製圖列列表的部分。 我的記憶中仍然有cols,所以它起作用了。 我將在我之前的回復中更新腳本來修復它。
Re:在Tabbox循環中控製圖表哇,這很棒,我很欣賞所有裝修,謝謝你。當我嘗試運行它時,我確實收到一個錯誤,我不確定它意味著什麼,希望你可以幫助我理解它。
錯誤
訪問或評估'下標',cols [/ * ### * / j]的下標範圍
Re:在Tabbox循環中控製圖表[更新]修正了腳本中的錯誤。
這似乎符合您的所有標準,但我認為您最終會發現更清潔,因為您沒有為每個ID創建一大堆表。 您可以使用每個選項卡上的控製圖的Where()子句來對每個ID進行子集化,而不是對錶進行子集化。
dt_final = Current Data Table();
//Sort by Grouping and Start Time
dt_final << Sort(
By( :GROUPING, :DATE_TIME_START ),
Order( Ascending, Ascending ),
Output Table( "Final Sorted" ),
Replace Table
);
//List of Columns and Individual IDs
Rcols = dt_final << Get Column Names();
id = Associative Array(dt_final:GROUPING) << get keys;
//Initialize the window
nw = New Window("Control Charts",
Outlinebox("Control Charts By Process ID",
tb = tabbox();
)
);
//Create expression for control charts - use same expression for each subset of the data table
//We'll substitute different values for GroupID and col_list for each grouping
ccExpr = "Control Chart(
Sample Label( :DATE_TIME_START ),
KSigma( 3 ), col_list, Where(:GROUPING == \!"GroupID\!"))";
//Loop through each ID and add control charts to a new tab
for(i=1, i <= N Items(id), i++,
//If column has data, add it to the control chart report
cols_temp = ""; //will hold list of control charts for the current ID
//Loop through each column, determine if column has data for current ID
For( j = 3, j <= N Items( Rcols ), j++,
If(Sum(!Is Missing(Column(dt_final, j)[dt_final << Get Rows Where(:GROUPING == id[i])])) > 0,
cols_temp = cols_temp || Eval Insert("\[, Chart Col( Column( "^Rcols[j]^" ), Levey Jennings )]\");
)
);
//Substitute in the current ID for GroupID in ccExpr
ccExpr_temp = Substitute(ccExpr, "GroupID", id[i]);
//Substitute in the list of control chart columns for col_list in ccExpr
ccExpr_temp = Substitute(ccExpr_temp, "col_list", cols_temp);
//Add results to the tab box by parsing the string ccExpr_temp into an expression and evaluating it
tb << Add(id[i], platform(dt_final, Eval(Parse(ccExpr_temp))));
);
這裡有很多要解釋的,所以請告訴我你有什麼問題。
Re:在Tabbox循環中控製圖表是的,當然,這是一個數據表,我擦掉了名字。
Re:在Tabbox循環中控製圖表你可以發布一個表(如果需要可以清理它)我們可以用你的腳本嗎?
我注意到的第一件事是“<< get kets”。 那應該是“獲取鑰匙”嗎?如果是這樣,您需要將其與數組一起使用,而不是數據表。 我猜你只想要一個GROUPING所有唯一值的列表。 你可以這樣做:
id = Associative Array(dt_final:GROUPING << Get Values) << Get Keys;
我在你的腳本中看到了很多,但是如果沒有可以使用的表,我就不會嘗試調試它。