cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
lehaofeng
Level V

如何根据用户输入的值自动的改变制表平台里的合格率?

谢谢各位大佬,我是一个新手,求问,如何把用户输入的比较符号,还有数值,纳入JSL计算,我用eval(parse()),始终实现不了,谢谢。

names default to here(1);
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

New Window( "合格率报表",
	Data Filter Context Box(
		H List Box(
			dfsb = Current Data Table() << Data Filter( Local ), 
			
			Platform(
				
				Current Data Table(),
				V List Box(
					Outline Box( "请输入所有参数规格限",
						Lineup Box( N Col( 3 ), Spacing( 5 ),
							Panel Box( "age",
								Lineup Box( N Col( 3 ), Spacing( 5 ),
									Text Box( "upper " ),
									dluf = Combo Box( {"<=", "<"} ),
									dlu = Number Edit Box(15),
									Text Box( "lower " ),
									dlbf = Combo Box( {">=", ">"} ),
									dlb = Number Edit Box(-3)
								)
							),
							Panel Box( "height",
								Lineup Box( N Col( 3 ), Spacing( 5 ),
									Text Box( "upper " ),
									dauf = Combo Box( {"<=", "<"} ),
									dau = Number Edit Box(),
									Text Box( "lower " ),
									dabf = Combo Box( {">=", ">"} ),
									dab = Number Edit Box()
								)
							),
							Panel Box( "weight",
								Lineup Box( N Col( 3 ), Spacing( 5 ),
									Text Box( "upper " ),
									dbuf = Combo Box( {"<=", "<"} ),
									dbu = Number Edit Box(),
									Text Box( "lower " ),
									dbbf = Combo Box( {">=", ">"} ),
									dbb = Number Edit Box()
								)
							),
							Button Box( "确定", 
							          //获取规格限数字
								ageu = dlu << get;
								agel = dlb << get;
								heiu = dau << get;
								heil = dab << get;
								weiu = dbu << get;
								weil = dbb << get;
							          //获取规格限数字是否包含
								aguf = ((dluf << XPath( "//ComboBox" )) << get selected)[1];
								aglf = ((dlbf << XPath( "//ComboBox" )) << get selected)[1];
								heuf = ((dauf << XPath( "//ComboBox" )) << get selected)[1];
								helf = ((dabf << XPath( "//ComboBox" )) << get selected)[1];
								weuf = ((dbuf << XPath( "//ComboBox" )) << get selected)[1];
								welf = ((dbbf << XPath( "//ComboBox" )) << get selected)[1];
							)
						)
					),
						dt << Tabulate(
						Set Format(
							Mean(
								:Name( "age" )(6, "Best"),
								:Name( "height" )(6, "Best"),
								:Name( "weight")(6, "Best"), 
		
			                    Analysis Columns(									
									Transform Column( "age rate", eval(parse("if(:age"||aglf|| char(agel)|| ":age"||aguf||char(ageu)||",1,0)")) ,  
			
				Format( 9, 2, "Percent" )
								)),
								
								Analysis Columns(
									Transform Column( "height rate", Formula( eval(parse("if(:height"||helf|| char(heil)|| ":height"||heuf||char(heiu)||",1,0)")) ) ), 
				//强行修改格式
									Format( 9, 2, "Percent" )
								),
								Analysis Columns( Transform Column( "weight rate", Formula( eval(parse("if(:weight"||welf|| char(weil)|| ":weight"||weuf||char(weiu)||",1,0)")) ) ), Format( 9, 2, "Percent" ) )
							),
							N( 9, "Best" )
						),
						Add Table(
							Column Table(
			//具体固定统计列
								Analysis Columns( :Name( "age" ), :Name( "weight" ), :Name( "height" ) ),
								Statistics( Mean, Range )
							), 
		//调整样本量列的实际位置
							Column Table( Statistics( N ) ),
							column table(Analysis Columns(
									Transform Column( "rate age", Formula( eval(parse("if(:age"||aguf|| char(agel)|| ":age"||aguf||char(ageu)||",1,0)"))) ) ),Statistics( Mean )
								),
							Column Table(
								Analysis Columns( Transform Column( "height rate", Formula( eval(parse("if(:height"||helf|| char(heil)|| ":height"||heuf||char(heiu)||",1,0)")) ) ) ),
								Statistics( Mean )
							),
							Column Table(
								Analysis Columns( Transform Column( "weight rate", Formula( eval(parse("if(:weight"||welf|| char(weil)|| ":weight"||weuf||char(weiu)||",1,0)")) ) ) ),
								Statistics( Mean )
							), 
		//临时固定类别列,且可以通过拖拽进行增删
							Row Table( Grouping Columns( :sex ) )
						)
					);
					)))))
1 ACCEPTED SOLUTION

Accepted Solutions

Re: 如何根据用户输入的值自动的改变制表平台里的合格率?

There are several approaches. The following is an example that uses the eval insert function.

This page is also helpful to understand expression.

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

create tabulate = Expr(
	Parse(
		Eval Insert(
			"\[
	tabulate box = dt << Tabulate(
		Set Format(
			Mean(
				:Name( "age" )(6, "Best"),
				:Name( "height" )(6, "Best"),
				:Name( "weight" )(6, "Best"), 
  
				Analysis Columns(
					Transform Column(
						"age rate",
						Formula ( if(:age ^aglf^ ^agel^ & :age ^aguf^ ^ageu^ ,1,0) ),  
   
						Format( 9, 2, "Percent" )
					)
				), 
        
				Analysis Columns(
					Transform Column(
						"height rate",
						Formula(  if(:height ^helf^ ^heil^ & :height ^heuf^ ^heiu^ ,1,0) )
					), 
    //强行修改格式
					Format( 9, 2, "Percent" )
				),
				Analysis Columns(
					Transform Column(
						"weight rate",
						Formula(  if(:weight ^welf^ ^weil^ & :weight ^weuf^ ^weiu^ ,1,0) ) 
					),
					Format( 9, 2, "Percent" )
				)
			),
			N( 9, "Best" )
		),
		Add Table(
			Column Table(
   //具体固定统计列
				Analysis Columns( :Name( "age" ), :Name( "weight" ), :Name( "height" ) ),
				Statistics( Mean, Range )
			), 
  //调整样本量列的实际位置
			Column Table( Statistics( N ) ),
			column table(
				Analysis Columns(
					Transform Column(
						"rate age",
						Formula(  if(:age ^aguf^ ^agel^ & :age ^aguf^ ^ageu^ ,1,0) ) 
					)
				),
				Statistics( Mean )
			),
			Column Table(
				Analysis Columns(
					Transform Column(
						"height rate",
						Formula(  if(:height ^helf^ ^heil^ & :height ^heuf^ ^heiu^ ,1,0) ) 
					)
				),
				Statistics( Mean )
			),
			Column Table(
				Analysis Columns(
					Transform Column(
						"weight rate",
						Formula( if(:weight ^welf^ ^weil^ & :weight ^weuf^ ^weiu^ ,1,0) ) 
					)
				),
				Statistics( Mean )
			), 
  //临时固定类别列,且可以通过拖拽进行增删
			Row Table( Grouping Columns( :sex ) )
		)
	)
]\"
		)
	)
);

nw = New Window( "合格率报表",
	Data Filter Context Box(
		H List Box(
			dfsb = Current Data Table() << Data Filter( Local ), 
   
			Platform(
    
				Current Data Table(),
				V List Box(
					Outline Box( "请输入所有参数规格限",
						Lineup Box( N Col( 3 ), Spacing( 5 ),
							Panel Box( "age",
								Lineup Box( N Col( 3 ), Spacing( 5 ),
									Text Box( "upper " ),
									dluf = Combo Box( {"<=", "<"} ),
									dlu = Number Edit Box( 15 ),
									Text Box( "lower " ),
									dlbf = Combo Box( {">=", ">"} ),
									dlb = Number Edit Box( -3 )
								)
							),
							Panel Box( "height",
								Lineup Box( N Col( 3 ), Spacing( 5 ),
									Text Box( "upper " ),
									dauf = Combo Box( {"<=", "<"} ),
									dau = Number Edit Box( 15 ),
									Text Box( "lower " ),
									dabf = Combo Box( {">=", ">"} ),
									dab = Number Edit Box( 1 )
								)
							),
							Panel Box( "weight",
								Lineup Box( N Col( 3 ), Spacing( 5 ),
									Text Box( "upper " ),
									dbuf = Combo Box( {"<=", "<"} ),
									dbu = Number Edit Box( 15 ),
									Text Box( "lower " ),
									dbbf = Combo Box( {">=", ">"} ),
									dbb = Number Edit Box( 1 )
								)
							),
							Button Box( "确定", 
                 //获取规格限数字
								ageu = dlu << get;
								agel = dlb << get;
								heiu = dau << get;
								heil = dab << get;
								weiu = dbu << get;
								weil = dbb << get;
                 //获取规格限数字是否包含
								aguf = ((dluf << XPath( "//ComboBox" )) << get selected)[1];
								aglf = ((dlbf << XPath( "//ComboBox" )) << get selected)[1];
								heuf = ((dauf << XPath( "//ComboBox" )) << get selected)[1];
								helf = ((dabf << XPath( "//ComboBox" )) << get selected)[1];
								weuf = ((dbuf << XPath( "//ComboBox" )) << get selected)[1];
								welf = ((dbbf << XPath( "//ComboBox" )) << get selected)[1];
								Try( tabulate box << delete );
								tabulate << append( Eval( create tabulate ) );
							)
						)
					), 
//
					tabulate = V List Box();
//
				)
			)
		)
	)
);

View solution in original post

3 REPLIES 3

Re: 如何根据用户输入的值自动的改变制表平台里的合格率?

There are several approaches. The following is an example that uses the eval insert function.

This page is also helpful to understand expression.

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

create tabulate = Expr(
	Parse(
		Eval Insert(
			"\[
	tabulate box = dt << Tabulate(
		Set Format(
			Mean(
				:Name( "age" )(6, "Best"),
				:Name( "height" )(6, "Best"),
				:Name( "weight" )(6, "Best"), 
  
				Analysis Columns(
					Transform Column(
						"age rate",
						Formula ( if(:age ^aglf^ ^agel^ & :age ^aguf^ ^ageu^ ,1,0) ),  
   
						Format( 9, 2, "Percent" )
					)
				), 
        
				Analysis Columns(
					Transform Column(
						"height rate",
						Formula(  if(:height ^helf^ ^heil^ & :height ^heuf^ ^heiu^ ,1,0) )
					), 
    //强行修改格式
					Format( 9, 2, "Percent" )
				),
				Analysis Columns(
					Transform Column(
						"weight rate",
						Formula(  if(:weight ^welf^ ^weil^ & :weight ^weuf^ ^weiu^ ,1,0) ) 
					),
					Format( 9, 2, "Percent" )
				)
			),
			N( 9, "Best" )
		),
		Add Table(
			Column Table(
   //具体固定统计列
				Analysis Columns( :Name( "age" ), :Name( "weight" ), :Name( "height" ) ),
				Statistics( Mean, Range )
			), 
  //调整样本量列的实际位置
			Column Table( Statistics( N ) ),
			column table(
				Analysis Columns(
					Transform Column(
						"rate age",
						Formula(  if(:age ^aguf^ ^agel^ & :age ^aguf^ ^ageu^ ,1,0) ) 
					)
				),
				Statistics( Mean )
			),
			Column Table(
				Analysis Columns(
					Transform Column(
						"height rate",
						Formula(  if(:height ^helf^ ^heil^ & :height ^heuf^ ^heiu^ ,1,0) ) 
					)
				),
				Statistics( Mean )
			),
			Column Table(
				Analysis Columns(
					Transform Column(
						"weight rate",
						Formula( if(:weight ^welf^ ^weil^ & :weight ^weuf^ ^weiu^ ,1,0) ) 
					)
				),
				Statistics( Mean )
			), 
  //临时固定类别列,且可以通过拖拽进行增删
			Row Table( Grouping Columns( :sex ) )
		)
	)
]\"
		)
	)
);

nw = New Window( "合格率报表",
	Data Filter Context Box(
		H List Box(
			dfsb = Current Data Table() << Data Filter( Local ), 
   
			Platform(
    
				Current Data Table(),
				V List Box(
					Outline Box( "请输入所有参数规格限",
						Lineup Box( N Col( 3 ), Spacing( 5 ),
							Panel Box( "age",
								Lineup Box( N Col( 3 ), Spacing( 5 ),
									Text Box( "upper " ),
									dluf = Combo Box( {"<=", "<"} ),
									dlu = Number Edit Box( 15 ),
									Text Box( "lower " ),
									dlbf = Combo Box( {">=", ">"} ),
									dlb = Number Edit Box( -3 )
								)
							),
							Panel Box( "height",
								Lineup Box( N Col( 3 ), Spacing( 5 ),
									Text Box( "upper " ),
									dauf = Combo Box( {"<=", "<"} ),
									dau = Number Edit Box( 15 ),
									Text Box( "lower " ),
									dabf = Combo Box( {">=", ">"} ),
									dab = Number Edit Box( 1 )
								)
							),
							Panel Box( "weight",
								Lineup Box( N Col( 3 ), Spacing( 5 ),
									Text Box( "upper " ),
									dbuf = Combo Box( {"<=", "<"} ),
									dbu = Number Edit Box( 15 ),
									Text Box( "lower " ),
									dbbf = Combo Box( {">=", ">"} ),
									dbb = Number Edit Box( 1 )
								)
							),
							Button Box( "确定", 
                 //获取规格限数字
								ageu = dlu << get;
								agel = dlb << get;
								heiu = dau << get;
								heil = dab << get;
								weiu = dbu << get;
								weil = dbb << get;
                 //获取规格限数字是否包含
								aguf = ((dluf << XPath( "//ComboBox" )) << get selected)[1];
								aglf = ((dlbf << XPath( "//ComboBox" )) << get selected)[1];
								heuf = ((dauf << XPath( "//ComboBox" )) << get selected)[1];
								helf = ((dabf << XPath( "//ComboBox" )) << get selected)[1];
								weuf = ((dbuf << XPath( "//ComboBox" )) << get selected)[1];
								welf = ((dbbf << XPath( "//ComboBox" )) << get selected)[1];
								Try( tabulate box << delete );
								tabulate << append( Eval( create tabulate ) );
							)
						)
					), 
//
					tabulate = V List Box();
//
				)
			)
		)
	)
);
lehaofeng
Level V

Re: 如何根据用户输入的值自动的改变制表平台里的合格率?

非常感谢,能够请教一下吗?为什么“||"要换成 “&”?

Re: 如何根据用户输入的值自动的改变制表平台里的合格率?

It seems that your orginal formula is like this "If(:age >= 8:age < 20, 1, 0);".
I thought you needed an and operator in the formula. "If(:age >= 8 & :age < 20, 1, 0);".

If you use the eval insert function, you don't need to add "||" in this example.

 

aglf = ">=";
agel = 8;
aguf = "<";
ageu = 20;

example1 = eval insert("if(:age ^aglf^ ^agel^ & :age ^aguf^ ^ageu^ ,1,0)");
Show( example1 );