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

Is this a bug or i am missing someting?

I have a table (here simplified and called “TestBug.jsl” attached ) that is used to generate some random numbers and then make a calculation based on the table variable, let call this my “simulator table” as each time i re-calculate it this would be one simulation that i want to repeat many times.

 

then i have the following script to automate running the same simulation many times with different input and concatenate the resulting tables in a "result" table.

To test simply run the script with the TestBug.jsl as current data table,

 

Names Default To Here(1);

VarList={1,2,3,4};

New Namespace(
	"MyNS"
);

MyNS:Simulator = Current Data Table();
MyNS:FinalT=MyNS:Simulator<<subset(	Output Table( "final table" ),
	Copy formula( 0 ),
	All rows,
	Selected columns only( 0 )	
);
MyNS:FinalT<< Select All Rows;
MyNS:FinalT<< Delete Rows;

advancementWin=new window("Progress",
TBsizes= text box(),
);
for(is=1,is<=length(VarList),is++,	
	myVarVal=VarList[is];
	TBsizes<<set text("Simulating:"|| char(myVarVal)||"(" || char(is)||"/" || char(length(VarList))||")");
	
	MyNS:Simulator << Suppress Formula Eval( 1 ); //i need this as in the final version i make more changes and i want to avoid recalc of the random each change 
	MyNS:Simulator<<set table variable("myvar",myVarVal);
	
	MyNS:Simulator << Suppress Formula Eval( 0 );
	MyNS:Simulator<< Rerun Formulas();

	MyNS:Final=MyNS:FinalT<<Concatenate(MyNS:Simulator, Append to first table);
);

advancementWin<<Closewindow();

Basically the script iterates and changes the table variables in the simulator table according to an input list and the resulting numbers concatenated in a “result table” (without carrying the formulas but just the numbers)

 

So what the script does initially is to create an empty result table that has the same columns as my "simulator", then iteratively changes the table variable in the “simulator” and concatenate it to the “result” table

 

However for some reason every time I change the value of the “simulator” variable, a new column is created as of the second iteration in the “result” table with the same name of the variable and filling it in with the value in a strange pattern (see picture)

 

Basically it adds the value of the variable at the previous iteration in the active columns for the new concatenated rows and the value of the final iteration to all the other rows…

This is just annoying for a few iterations but makes the whole process very slow/crashing for many iterations.

if i skip the "concatenate" or the "set table variable" the columns are not added. 

I cannot understand what i am doing wrong.

2 ACCEPTED SOLUTIONS

Accepted Solutions
jthi
Super User

Re: Is this a bug or i am missing someting?

Those get added there due to the table variable. You could for example drop the table variable from your subset table after creation and then after each concatenate

View more...
Names Default To Here(1);

VarList = {1, 2, 3, 4};

New Namespace(
	"MyNS"
);

MyNS:Simulator = Datatable("TestBug");
MyNS:FinalT = MyNS:Simulator << subset(
	Output Table("final table"),
	Copy formula(0),
	All rows,
	Selected columns only(0)
);
MyNS:FinalT << Select All Rows;
MyNS:FinalT << Delete Rows;
Try(MyNS:FinalT << Delete Table Variable("myvar"));

advancementWin = New Window("Progress", TBsizes = Text Box(), );
For(is = 1, is <= Length(VarList), is++,
	myVarVal = VarList[is];
	TBsizes << set text(
		"Simulating:" || Char(myVarVal) || "(" || Char(is) || "/" || Char(Length(VarList)) ||
		")"
	);
	
	MyNS:Simulator << Suppress Formula Eval(1); //i need this as in the final version i make more changes and i want to avoid recalc of the random each change 
	MyNS:Simulator << set table variable("myvar", myVarVal);
	
	MyNS:Simulator << Suppress Formula Eval(0);
	MyNS:Simulator << Rerun Formulas();

	MyNS:FinalT << Concatenate(MyNS:Simulator, Append to first table);
	Try(MyNS:FinalT << Delete Table Variable("myvar"));
);

advancementWin << Closewindow();

 

-Jarmo

View solution in original post

peri_a
Level III

Re: Is this a bug or i am missing someting?

Thanks. this solves my issue.

 

If i understand correctly 

If you concatenate two tables with different values for the variables a new column is added to "track the value it had in the original tables" 

i can see why one wants to do that but is a strange behavior that is confusing

 

Your trick solves the problem, but for completeness i had to move the 

Try(MyNS:FinalT << Delete Table Variable("myvar"));

before the concatenation

View solution in original post

2 REPLIES 2
jthi
Super User

Re: Is this a bug or i am missing someting?

Those get added there due to the table variable. You could for example drop the table variable from your subset table after creation and then after each concatenate

View more...
Names Default To Here(1);

VarList = {1, 2, 3, 4};

New Namespace(
	"MyNS"
);

MyNS:Simulator = Datatable("TestBug");
MyNS:FinalT = MyNS:Simulator << subset(
	Output Table("final table"),
	Copy formula(0),
	All rows,
	Selected columns only(0)
);
MyNS:FinalT << Select All Rows;
MyNS:FinalT << Delete Rows;
Try(MyNS:FinalT << Delete Table Variable("myvar"));

advancementWin = New Window("Progress", TBsizes = Text Box(), );
For(is = 1, is <= Length(VarList), is++,
	myVarVal = VarList[is];
	TBsizes << set text(
		"Simulating:" || Char(myVarVal) || "(" || Char(is) || "/" || Char(Length(VarList)) ||
		")"
	);
	
	MyNS:Simulator << Suppress Formula Eval(1); //i need this as in the final version i make more changes and i want to avoid recalc of the random each change 
	MyNS:Simulator << set table variable("myvar", myVarVal);
	
	MyNS:Simulator << Suppress Formula Eval(0);
	MyNS:Simulator << Rerun Formulas();

	MyNS:FinalT << Concatenate(MyNS:Simulator, Append to first table);
	Try(MyNS:FinalT << Delete Table Variable("myvar"));
);

advancementWin << Closewindow();

 

-Jarmo
peri_a
Level III

Re: Is this a bug or i am missing someting?

Thanks. this solves my issue.

 

If i understand correctly 

If you concatenate two tables with different values for the variables a new column is added to "track the value it had in the original tables" 

i can see why one wants to do that but is a strange behavior that is confusing

 

Your trick solves the problem, but for completeness i had to move the 

Try(MyNS:FinalT << Delete Table Variable("myvar"));

before the concatenation

Recommended Articles