cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
The Discovery Summit 2025 Call for Content is open! Submit an abstract today to present at our premier analytics conference.
See how to use to use Text Explorer to glean valuable information from text data at April 25 webinar.
Choose Language Hide Translation Bar
View Original Published Thread

Adding Progress bar in the script

Jackie_
Level VI

Hello ,

 

I have a data table with a million rows and am trying to add a progress bar window in the script. I found this threat (Progress bar) from Craige useful. I am new to this, so I am still trying to understand where to add the code to indicate the progress. Any suggestions? 

 

Code for a Progress bar from @Craige_Hales 

 

progressBarWidth = 500;
progressUpdatesSeconds = 1 / 4; // 1/2 sec updates -> 1300ips,  1/30 -> 1000ips (1/4 compromise speed vs appearance)
cancel = 0; // clear the cancel flag
New Window( "Progressbar demo", //
	Show Menu( 0 ),
	show toolbars( 0 ),
	V List Box( //
		cats = Text Box( "" ), // output from the work function
		t = Text Box( "", <<setwrap( 500 ) ), // status of the progressbar
		H List Box( // Duct tape has a light side and a dark side. So does the progressbar.
			left = Spacer Box( size( 0, 10 ), color( "light green" ) ), //
			right = Spacer Box( size( progressBarWidth, 10 ), color( "dark green" ) ), //
			<<padding( 5, 5, 5, 5 ), // gray wrapper
			<<backgroundcolor( "dark gray" ) //
		), //
		cancelButton = Button Box( "Cancel", cancel = 1 ) // sets the cancel flag
	)
);
Wait( 0 ); // allow the window to open, otherwise the updates are not visible

// progressbar variables
startMicroSeconds = HP Time();
workCalls = 0;
recentUpdateMicroSeconds = HP Time();
runSeconds = (recentUpdateMicroSeconds - startMicroSeconds) / 1e6; // so the loop can start
limitSeconds = 10; // time to run the demo

updateProgress = Function( {fractionComplete},
	leftsize = Round( progressBarWidth * fractionComplete );
	rightsize = progressBarWidth - leftsize;
	left << width( leftsize );
	right << width( rightsize );
	t << settext(
		Eval Insert(
			"^workCalls^ iterations in ^char(runSeconds,6,3)^ seconds -> ^workCalls/runSeconds^ ips"
		)
	);
	t << updatewindow; // this works without the wait	
);

totalCats = 0;
dowork = Function( {},
	x = "";
	For( i = 1, i <= 1000, i += 1, x = x || "." );
	totalCats += 1000;
	cats << settext( Eval Insert( "total concatenations=^totalCats^" ) );
);

While( runSeconds < limitSeconds & !cancel, // change this to represent the work you are doing
	
	// do some work, simulated by concatenating strings...
	dowork();
	
	// update the progressbar
	workCalls += 1;
	nowMicroSeconds = HP Time();
	// how often does it need to update on the screen?
	If( (nowMicroSeconds - recentUpdateMicroSeconds) / 1e6 > progressUpdatesSeconds, 
		// in this example I'm using a fixed time duration of "limitSeconds" to represent the
		// amount of work to be done. And "runSeconds" to represent the amount of work done so far.
		// Usually you'll have something other than time: number of rows in a table perhaps, or
		// number of categories to make reports for. As long as you know how many total and how
		// many completed, you can compute this fraction...
		updateProgress( runSeconds / limitSeconds );  // change this to represent the fraction of work finished
		recentUpdateMicroSeconds = nowMicroSeconds;
		Wait( 0 ); // this wait is needed to let the cancel button work
	);
	runSeconds = (nowMicroSeconds - startMicroSeconds) / 1e6;
);

If( cancel, // test the cancel flag
	Beep(); // audio flag
	left << color( "dark red" ); // visual flag something is awry
	right << color( "red" );
, //
	updateProgress( 1.0 ); // people like to see the bar go to 100%
);
cancelButton << setbuttonname( "Close" ); // visual flag the button function is changed
cancelButton << setscript( (cancelButton << closewindow) ); // and what to do if the button is pressed

JSL to generate plots

 

 

Names Default To Here( 1 );

dt = Open( "$SAMPLE_DATA/Semiconductor Capability.jmp" );

List1 = {"NPN1", "PNP1", "PNP2", "NPN2", "PNP3", "IVP1"};
List2 = {"PNP4", "NPN3", "IVP2", "NPN4", "SIT1"};
List3 = {"INM1", "INM2", "VPM1", "VPM2", "VPM3"};
List4 = {"SNM1", "SPM1", "NPN5", "EP2", "ZD6"};

var expr1 = Expr( Variables() );
For( c = 1, c <= N Items( List1 ), c++,
	x expr1 = Expr(
		X( Position( 1 ), Combine( "Parallel Merged" ) )
	);
	Insert Into( x expr1, List1[c], 1 );
	Insert Into( var expr1, Name Expr( x expr1 ) );
);

var expr2 = Expr( Variables() );
For( c = 1, c <= N Items( List2 ), c++,
	x expr2 = Expr(
		X( Position( 1 ), Combine( "Parallel Merged" ) )
	);
	Insert Into( x expr2, List2[c], 1 );
	Insert Into( var expr2, Name Expr( x expr2 ) );
);

var expr3 = Expr( Variables() );
For( c = 1, c <= N Items( List3 ), c++,
	x expr3 = Expr(
		X( Position( 1 ), Combine( "Parallel Merged" ) )
	);
	Insert Into( x expr3, List3[c], 1 );
	Insert Into( var expr3, Name Expr( x expr3 ) );
);

var expr4 = Expr( Variables() );
For( c = 1, c <= N Items( List4 ), c++,
	x expr4 = Expr(
		X( Position( 1 ), Combine( "Parallel Merged" ) )
	);
	Insert Into( x expr4, List4[c], 1 );
	Insert Into( var expr4, Name Expr( x expr4 ) );
);


lists = {"List1", "List2", "List3", "List4"};
var = {};
gbv = {};

For( i = 1, i <= 4, i++,
	Insert Into( var, Name Expr( Eval( Parse( "var expr" || Char( i ) ) ) ) );
	Insert Into( gbv, Parse( "vvv" || Char( i ) ) );
);

nw = New Window( "Plots",
	Show Menu( 0 ),
	show toolbars( 0 ),
	H List Box(

		Check Box(
			{"Summary"}, 
						
			<<Set Function(
				Function( {self}, 
							
					sel = self << get selected();
					If( N Items( sel ) > 0,
						For( i = 1, i <= N Items( lists ), i++,
							If( N Items( Eval( Parse( lists[i] ) ) ) > 0,
								nw[lists[i], Outline Box( 1 )] << append(
										 
					
									V Scroll Box(
										size( 580 ),
										Border Box( Left( 5 ), Right( 5 ), Top( 5 ), Bottom( 5 ), Sides( 15 ),
											Tabulate(
												Show Control Panel( 0 ),
												Set Format( Uniform Format( 10, 2 ) ),
												Add Table(
													Column Table( Statistics( Mean, Std Dev ) ),
													Row Table(
														Analysis Columns(
															Eval( Parse( lists[i] ) )
								
														)
													)
												), 
						
						
						
												SendToReport(
													Dispatch( {}, "Tabulate", OutlineBox, {Set Title( "Summary Stats" )} )
	
					
												)
											)
										)
									)
											
											
										
										
									
								) << Visibility( "Visible" );
			
							)
						);
								
					,
					/// Xpath syntax

	nw << XPath( "//Outlinebox[@helpKey = 'Summary Stats']" ) << delete;
							
								
								
								
								
					);
				);
						
			)
	
	
	
		),
		V List Box( tb = Tab Box() )
	)
);

For( i = 1, i <= N Items( lists ), i++,
	tb << Add(
		lists[i],
		V List Box(
			H List Box(
				Eval(
					Eval Expr(
						gb = dt << Graph Builder(
							Size( 1117, 781 ),
							Show Control Panel( 0 ), 
						
							Expr( Name Expr( var[i] ) ),
							Elements(
								Histogram(
									X( 1 ),
									X( 2 ),
									X( 3 ),
									X( 4 ),
									X( 5 ),
									X( 6 ),
									X( 7 ),
									X( 8 ),
									X( 9 ),
									X( 10 ),
									X( 11 ),
									X( 12 ),
									X( 13 ),
									X( 14 ),
									X( 15 ),
									X( 16 ), 
									
									Legend( 2 ), 
							
								),
								Box Plot(
									X( 1 ),
									X( 2 ),
									X( 3 ),
									X( 4 ),
									X( 5 ),
									X( 6 ),
									X( 7 ),
									X( 8 ),
									X( 9 ),
									X( 10 ),
									X( 11 ),
									X( 12 ),
									X( 13 ),
									X( 14 ),
									X( 15 ),
									X( 16 ), 
									
									Legend( 3 ),
									Outliers( 0 )
								)
							)
						)
					)
				),
				sumsta = Outline Box( 
					
					lists[i],
					<<visibility( "Collapse" )
						
						
				)
					
				
			)
		)
	);

				
	
	
	
);

 

2 REPLIES 2
SDF1
Super User


Re: Adding Progress bar in the script

Hi @Jackie_ ,

 

  A typical place to put something like a progress bar update would be at the start (or end) of an iterative loop, like a For() loop or a While() loop. So that at the start of each iteration, the progress window is updated to reflect the changes. You can find a solution with some description and discussion here.

 

Hope this helps!,

DS

Jackie_
Level VI


Re: Adding Progress bar in the script

Thanks.