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

Stacking timestamps?

I have a data table that has time increments from 0-->n for each step for a series of several steps. 

 

Wondering if there's a bkm to script to make each step time start at the end time of the previous step.

aka:

currently: step1, time = 0--> 7, step2, time = 0-->12

goal: step1, time=0-->7, step2, time7-->19

 

Advice?

 

Columns: 

sensor Label | Value | time | Step

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Stacking timestamps?

Here is a sample data table and a simple script that will adjust the time when the step changes.  The script first displays the data table for 10 seconds, so you can see what the original table looks like, and then it goes ahead and runs the little script to adjust the time values.

Names Default To Here( 1 );
dt = New Table( "example",
	Add Rows( 42 ),
	New Column( "time",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values(
			[0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 0, 1,
			2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
		)
	),
	New Column( "Step",
		Character,
		"Nominal",
		Set Values(
			{"Step1", "Step1", "Step1", "Step1", "Step1", "Step1", "Step1", "Step1",
			"Step2", "Step2", "Step2", "Step2", "Step2", "Step2", "Step2", "Step2",
			"Step2", "Step2", "Step2", "Step2", "Step2", "Step3", "Step3", "Step3",
			"Step3", "Step3", "Step3", "Step3", "Step3", "Step3", "Step3", "Step3",
			"Step3", "Step3", "Step3", "Step3", "Step3", "Step3", "Step3", "Step3",
			"Step3", "Step3"}
		)
	)
);

wait(10);

For Each Row(
	If( Row() == 1,
		adder = 0,
		If( Lag( :step ) != :step,
			adder = :time[Row() - 1]
		)
	);
	:time = :time + adder;
);
Jim

View solution in original post

7 REPLIES 7
txnelson
Super User

Re: Stacking timestamps?

Here is a sample data table and a simple script that will adjust the time when the step changes.  The script first displays the data table for 10 seconds, so you can see what the original table looks like, and then it goes ahead and runs the little script to adjust the time values.

Names Default To Here( 1 );
dt = New Table( "example",
	Add Rows( 42 ),
	New Column( "time",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values(
			[0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 0, 1,
			2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
		)
	),
	New Column( "Step",
		Character,
		"Nominal",
		Set Values(
			{"Step1", "Step1", "Step1", "Step1", "Step1", "Step1", "Step1", "Step1",
			"Step2", "Step2", "Step2", "Step2", "Step2", "Step2", "Step2", "Step2",
			"Step2", "Step2", "Step2", "Step2", "Step2", "Step3", "Step3", "Step3",
			"Step3", "Step3", "Step3", "Step3", "Step3", "Step3", "Step3", "Step3",
			"Step3", "Step3", "Step3", "Step3", "Step3", "Step3", "Step3", "Step3",
			"Step3", "Step3"}
		)
	)
);

wait(10);

For Each Row(
	If( Row() == 1,
		adder = 0,
		If( Lag( :step ) != :step,
			adder = :time[Row() - 1]
		)
	);
	:time = :time + adder;
);
Jim
aliegner1
Level IV

Re: Stacking timestamps?

this works great! I am noticing just a small issue. at the time increment where the step changes, it is repeating the time value, rather than incrementing. I'm still trying to understand the LAG function. Any tips?

 

aliegner1_1-1607631260606.png

 

 

Finally, any tips for adding in x-axis markers into the script to label the blocks of the trace?

I can create new columns for local min/max based on step#, but not sure how to script that into an axis label.

aliegner1_2-1607631432803.png

 

aliegner1_0-1607631184743.png

 

txnelson
Super User

Re: Stacking timestamps?

Concerning your first issue, your requirement for the increment between steps was

     goal: step1, time=0-->7, step2, time7-->19

Note, the time value was the same for the last value in the first step, as well as the first time in the second step.

If you want to increment between the steps, just change the adder value to whatever the additional increment is desired

adder = :time[Row() - 1] + 1

 I do not understand what you are asking for when you say "adding in x-axis markers into the script to label the blocks of the trace".

Finally, All of the functions, such as Lag() are documented in the Scripting Index, available under the Help pull down menu.

Jim
aliegner1
Level IV

Re: Stacking timestamps?

sorry for the miscommunication.
I was trying to mean:
I'm trying to script in axis labels on the x-axis corresponding to the step time max or mins. I'm trying to figure out the summarize script or assigning a variables = colMax (time by step) but having trouble getting the syntax to work.

txnelson
Super User

Re: Stacking timestamps?

Take a look at adding reference lines on the x axis to mark the points on the X axis for the steps min and max
Jim
aliegner1
Level IV

Re: Stacking timestamps?

Thank you.
I created a summary table, then assigned variables to specific ("column")[row#] locations then assigned reference lines equal to those variable names.
UersK
Level III

Re: Stacking timestamps?

Thanks!