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

How to script Column Matching Dialog

I have a dialog where I need a user to match pairs of columns. Pretty much like we do in Join Tables.

2022-03-25 11_51_23-Clipboard.png

 

Specific example - I have sets of experimentally measured parameters and sets of their theoretical predictions. This data comes from different sources and colum naming can be arbitrary, so I need users to match theory vs experiment for each parameter.

Is there an example on how to script this part? And how to keep these pairs and how to use them later?

So far I have this, and I'm interested in how to script the box in green frame to reflect matched pairs (like in example above) and how to keep those pairs (list of 2 item lists?) and how to remove\recall them etc.:

2022-03-25 11_42_16-Clipboard.png

And here is the script:

dt = New Table( "Untitled 5",
	Add Rows( 4 ),
	Set Header Height( 46 ),
	New Column( "X", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1, 2, 3, 4] ) ),
	New Column( "A_Theory", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1, 3, 2, 3] ) ),
	New Column( "B_Measured", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [4, 5, 6, 5] ) ),
	New Column( "A_Measured", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1, 4, 3, 4] ) ),
	New Column( "B_Theory", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [4, 5, 3, 4] ) )
);
notImplemented = Expr(
	win = New Window( "Feature Not Implemented Yet", <<Modal, Button Box( "OK" ) )
);

gui = Expr(
	H List Box(V List Box(Panel Box("Theory",Col List Box(All, Nlines(5))),Panel Box("Experiment", Col List Box(All, Nlines(5)))), Panel box("Theory vs Experiment Matching",H List Box(Button Box("Match", notImplemented), List Box({}, Nlines(12)))) )
	
);


fileLoad = New Window( "Example",
	Show Menu( 0 ),
	Show Toolbars( 0 ),
	gui
);

 

 

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
jthi
Super User

Re: How to script Column Matching Dialog

If I would have to guess, join platform uses Listbox in which it appends new values when you add column pairs.

Names Default To Here(1);

dt = New Table("Untitled 5",
	Add Rows(4),
	Set Header Height(46),
	New Column("X", Numeric, "Continuous", Format("Best", 12), Set Values([1, 2, 3, 4])),
	New Column("A_Theory", Numeric, "Continuous", Format("Best", 12), Set Values([1, 3, 2, 3])),
	New Column("B_Measured", Numeric, "Continuous", Format("Best", 12), Set Values([4, 5, 6, 5])),
	New Column("A_Measured", Numeric, "Continuous", Format("Best", 12), Set Values([1, 4, 3, 4])),
	New Column("B_Theory", Numeric, "Continuous", Format("Best", 12), Set Values([4, 5, 3, 4]))
);
notImplemented = Expr(
	a = clb1 << get selected;
	b = clb2 << get selected;
	lb << Append(a[1] || "=" || b[1]);
);

gui = Expr(
	H List Box(
		V List Box(
			Panel Box("Theory", 
				clb1 = Col List Box(All, Nlines(5))
			), 
			Panel Box("Experiment", 
				clb2 = Col List Box(All, Nlines(5))
			)
		),
		Panel Box("Theory vs Experiment Matching", 
			H List Box(
				Button Box("Match", notImplemented), 
				lb = List Box({}, Nlines(12))
			)
		)
	)
);

fileLoad = New Window("Example", Show Menu(0), Show Toolbars(0), gui);

//{col1, col2} = Words((lb << get items)[1], "=");

jthi_0-1648235071389.png

 

I just quickly threw together the script so use better naming than I did for variables, prevent selection of multiple values in col list boxes and remove hard-coded limits of column indexing. When you need the values you can get then with << get items to the list box reference, which will give you a list of items. Then use Words() to further split that into different parts.

-Jarmo

View solution in original post

miguello
Level VI

Re: How to script Column Matching Dialog

Ok, it works this way:

 

notImplemented = Expr(
	a = (clb1 << get selected)[1];
	b = (clb2 << get selected)[1];
	lb << Append(a || "=" || b);
    matchedList[N Items( matchedList ) + 1] = Eval List ({a, b});
    //Insert Into(matchedList, Eval List(columnPair));
    Show(matchedList);
);

View solution in original post

5 REPLIES 5
jthi
Super User

Re: How to script Column Matching Dialog

If I would have to guess, join platform uses Listbox in which it appends new values when you add column pairs.

Names Default To Here(1);

dt = New Table("Untitled 5",
	Add Rows(4),
	Set Header Height(46),
	New Column("X", Numeric, "Continuous", Format("Best", 12), Set Values([1, 2, 3, 4])),
	New Column("A_Theory", Numeric, "Continuous", Format("Best", 12), Set Values([1, 3, 2, 3])),
	New Column("B_Measured", Numeric, "Continuous", Format("Best", 12), Set Values([4, 5, 6, 5])),
	New Column("A_Measured", Numeric, "Continuous", Format("Best", 12), Set Values([1, 4, 3, 4])),
	New Column("B_Theory", Numeric, "Continuous", Format("Best", 12), Set Values([4, 5, 3, 4]))
);
notImplemented = Expr(
	a = clb1 << get selected;
	b = clb2 << get selected;
	lb << Append(a[1] || "=" || b[1]);
);

gui = Expr(
	H List Box(
		V List Box(
			Panel Box("Theory", 
				clb1 = Col List Box(All, Nlines(5))
			), 
			Panel Box("Experiment", 
				clb2 = Col List Box(All, Nlines(5))
			)
		),
		Panel Box("Theory vs Experiment Matching", 
			H List Box(
				Button Box("Match", notImplemented), 
				lb = List Box({}, Nlines(12))
			)
		)
	)
);

fileLoad = New Window("Example", Show Menu(0), Show Toolbars(0), gui);

//{col1, col2} = Words((lb << get items)[1], "=");

jthi_0-1648235071389.png

 

I just quickly threw together the script so use better naming than I did for variables, prevent selection of multiple values in col list boxes and remove hard-coded limits of column indexing. When you need the values you can get then with << get items to the list box reference, which will give you a list of items. Then use Words() to further split that into different parts.

-Jarmo
miguello
Level VI

Re: How to script Column Matching Dialog

Let me try that.

And then to do something with these columns later (for instance, plot Fit Y by X for each pair) - is it OK to keep them as a list of lists? 

columnPairs = {{A_Theory, A_Experiment}, {B_Theory, B_Experiment}};

 and then iterate through them or there's a better option?

 

 

miguello
Level VI

Re: How to script Column Matching Dialog

One more question. I modified the script this way:

 

Names Default To Here(1);
matchedList = {};

dt = New Table("Untitled 5",
	Add Rows(4),
	Set Header Height(46),
	New Column("X", Numeric, "Continuous", Format("Best", 12), Set Values([1, 2, 3, 4])),
	New Column("A_Theory", Numeric, "Continuous", Format("Best", 12), Set Values([1, 3, 2, 3])),
	New Column("B_Measured", Numeric, "Continuous", Format("Best", 12), Set Values([4, 5, 6, 5])),
	New Column("A_Measured", Numeric, "Continuous", Format("Best", 12), Set Values([1, 4, 3, 4])),
	New Column("B_Theory", Numeric, "Continuous", Format("Best", 12), Set Values([4, 5, 3, 4]))
);
notImplemented = Expr(
	a = (clb1 << get selected)[1];
	b = (clb2 << get selected)[1];
	lb << Append(a || "=" || b);
        Insert Into(matchedList, {a, b});
        Show(matchedList);
);

gui = Expr(
	H List Box(
		V List Box(
			Panel Box("Theory", 
				clb1 = Col List Box(All, Nlines(5))
			), 
			Panel Box("Experiment", 
				clb2 = Col List Box(All, Nlines(5))
			)
		),
		Panel Box("Theory vs Experiment Matching", 
			H List Box(
				Button Box("Match", notImplemented), 
				lb = List Box({}, Nlines(12))
			)
		)
	)
);

fileLoad = New Window("Example", Show Menu(0), Show Toolbars(0), gui);

And I'm getting this:

matchedList = {a, b, a, b};

While I was expecting this:

matchedList = {{"A_Theory", "A_Measured"}, {"B_Theory", "B_Measured"}}

Or something along those line so I could iterate through pairs.

What am I doing wrong?

 

miguello
Level VI

Re: How to script Column Matching Dialog

Ok, it works this way:

 

notImplemented = Expr(
	a = (clb1 << get selected)[1];
	b = (clb2 << get selected)[1];
	lb << Append(a || "=" || b);
    matchedList[N Items( matchedList ) + 1] = Eval List ({a, b});
    //Insert Into(matchedList, Eval List(columnPair));
    Show(matchedList);
);
jthi
Super User

Re: How to script Column Matching Dialog

Depending on how your application will work, it might be better not to append values to a list until user press run / ok button, as users might want to remove values from the list box (not currently possible).

 

I added Run button and runExpr to this example (if you don't have JMP16, you can modify Transform Each into a For loop which will append values to a list), remove button and clearing of col list box selections when Match is pressed:

Names Default To Here(1);
matchedList = {};

dt = New Table("Untitled 5",
	Add Rows(4),
	Set Header Height(46),
	New Column("X", Numeric, "Continuous", Format("Best", 12), Set Values([1, 2, 3, 4])),
	New Column("A_Theory", Numeric, "Continuous", Format("Best", 12), Set Values([1, 3, 2, 3])),
	New Column("B_Measured", Numeric, "Continuous", Format("Best", 12), Set Values([4, 5, 6, 5])),
	New Column("A_Measured", Numeric, "Continuous", Format("Best", 12), Set Values([1, 4, 3, 4])),
	New Column("B_Theory", Numeric, "Continuous", Format("Best", 12), Set Values([4, 5, 3, 4]))
);

notImplemented = Expr(
	a = (clb1 << get selected)[1];
	b = (clb2 << get selected)[1];
	clb1 << Clear selection;
	clb2 << Clear selection;
	lb << Append(a || "=" || b);
);

notImplemented2 = Expr(
	lb << Remove Selected;
);

runExpr = Expr(
	lb << get items;
	lb_values = Transform Each({val}, lb << get items, Words(val, "="));
	show(lb_values);
);

gui = Expr(
	H List Box(
		V List Box(
			Panel Box("Theory", 
				clb1 = Col List Box(All, Nlines(5))
			), 
			Panel Box("Experiment", 
				clb2 = Col List Box(All, Nlines(5))
			)
		),
		Panel Box("Theory vs Experiment Matching", 
			H List Box(
				Lineup box(N Col(1),
					Button Box("Match", notImplemented),
					Button Box("Remove", notImplemented2),
				),
				lb = List Box({}, Nlines(12))
			)
		),
		Panel Box("Actions",
			Button Box("Run",
				runExpr;
			)
		)
	)
);
fileLoad = New Window("Example", Show Menu(0), Show Toolbars(0), gui);
-Jarmo