How to get the row number of colored cells in a column and assign it a tag (say "1") in a newly created column?I used Color Out of Spec Values() to color spec fails in my measurement data. I have multiple columns with measurement data and the out of spec values for each column get colored according to the spec for each parameter column.
For each parameter column I want to create an adjacent column which assigns a "1" when the cell is colored otherwise "0".
How to achieve this via JSL?
Automation and ScriptingWindowsRe: How to get the row number of colored cells in a column and assign it a tag (say "1") in a newly created column?wow, great idea - via the column script!
The cool thing about JMP:
The Workarounds : )
The not-so-cool thing in JMP:
The Workarounds for the workarounds.
To directly get the out-of-spec values without the detour via Color, please vote: :folded_hands: is in spec (value)
Re: How to get the row number of colored cells in a column and assign it a tag (say "1") in a newly created column?Don't use For loop and use << move selected columns to move your columns after your specified column
View more...
Names Default To Here(1);
get_colored_cells = Function({dt, colname}, {Default Local},
colscript = Column(dt, colname) << Get Script;
l = Substitute(Name Expr(colscript), Expr(New Column()), List());
colored_cells = {};
Try(
colors = l["Color Cells"];
If(Type(colors[1]) == "List",
jmptrickery = 1,
jmptrickery = 0
);
For Each({color}, colors,
If(jmptrickery,
Insert Into(colored_cells, color[2]),
Insert Into(colored_cells, color)
)
);
);
Return(Matrix(colored_cells));
);
create_failed_column_after = function({dt, colname}, {Default Local},
curname = Column(dt, colname) << get name;
failed_rows = get_colored_cells(dt, colname);
row_vals = J(1, N Rows(dt), 0);
row_vals[failed_rows] = 1;
new_col = dt << New Column((curname || "_FAIL"), Numeric, Nominal, Values(row_vals));
dt << Move Selected Columns(new_col, After(Column(dt, colname)));
return(new_col);
);
dt = Open("$SAMPLE_DATA/Semiconductor Capability.jmp");
col_names = dt << Get Column Group("Processes");
dt << show window(0);
wait(0);
ps = dt << Process Screening(
Process Variables(Eval(col_names)),
Spec Limits Dialog("No (skip columns with no spec limits)")
);
ps << Color Out Of Spec Values(1);
ps << Close Window;
dt << Clear Select << Clear Column Selection;
For Each({colref}, col_names,
colname = colref << get name;
create_failed_column_after(dt, colname);
);
dt << show window(1);
wait(0);
Re: How to get the row number of colored cells in a column and assign it a tag (say "1") in a newly created column?@jthi Thanks. I have adapted your script to use with a dataset matching closely to mine. It works fine for one column name but not when I loop over column names. Also, how do I place each newly created column beside (on the right of) the column on which the operation is performed within the loop?
Names Default To Here( 1 );
Clear Log();
dt = Open( "$SAMPLE_DATA/Semiconductor Capability.jmp" );
col_names = dt << Get Column Group( "Processes" );
ps = dt << Process Screening(
Process Variables( Eval( col_names ) ),
Spec Limits Dialog( "No (skip columns with no spec limits)" ),
);
ps << Color Out Of Spec Values (1);
t = ps << Get Window Title; //Show( t );
ps << Close Window;
dt << Clear Select << Clear Column Selection;
get_colored_cells = Function({dt, colname}, {Default Local},
colscript = Column(dt, colname) << Get Script;
l = Substitute(Name Expr(colscript), Expr(New Column()), List());
colored_cells = {};
Try(
colors = l["Color Cells"];
If(Type(colors[1]) == "List",
jmptrickery = 1;
,
jmptrickery = 0;
);
For Each({color}, colors,
If(jmptrickery,
Insert Into(colored_cells, color[2]);
,
Insert Into(colored_cells, color);
);
);
);
return(Matrix(colored_cells));
);
measColNames = dt << get column names(Numeric,Continuous ); show (measColNames[1]);
For( i = 1, i <= N Items( measColNames), i++,
rows = J( 1, N Rows( dt ), 0 );
colored_rows = get_colored_cells( dt, measColNames[i]);
rows[colored_rows] = 1;
dt << New Column( "PassFail"||measColNames[i], Numeric, Nominal, Values( rows ) );
);
//colname = "NPN1";
///// for single column
/*rows = J(1, N Rows(dt), 0);
colored_rows = get_colored_cells(dt, colname);
rows[colored_rows] = 1;
dt << New Column("result", Numeric, Nominal, Values(rows));*/
Re: How to get the row number of colored cells in a column and assign it a tag (say "1") in a newly created column?This gives idea how you can handle the situation for one column
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
a = {1, 3, 5};
b = {2, 4, 6};
c = {7, 8, 9};
:height << color cells({{"Red", a}, {"blue", b}, {"yellow", c}});
:weight << color cells({{"Red", a}});
:age << color cells({{"Red", a}, {"blue", b}});
get_colored_cells = Function({dt, colname}, {Default Local},
colscript = Column(dt, colname) << Get Script;
l = Substitute(Name Expr(colscript), Expr(New Column()), List());
colored_cells = {};
Try(
colors = l["Color Cells"];
If(Type(colors[1]) == "List",
jmptrickery = 1;
,
jmptrickery = 0;
);
For Each({color}, colors,
If(jmptrickery,
Insert Into(colored_cells, color[2]);
,
Insert Into(colored_cells, color);
);
);
);
return(Matrix(colored_cells));
);
colname = "age";
// for single column
rows = J(1, N Rows(dt), 0);
colored_rows = get_colored_cells(dt, colname);
rows[colored_rows] = 1;
dt << New Column("result", Numeric, Nominal, Values(rows));
you can then create additional column to color each column when you loop over them