Hi @AvgLlama27 ,
I got some good success with the script attached - I don't think you could easily do this with a formula column. The script below works by:
1) Taking 'Slices' of a set width (number of rows) per serial number - in the example below it samples 600 rows
2) Find the maximum value for that 'slice'
3) Store the maximum value alongside the first and last 'elapsed time' and 'time stamp' values for the first and last row.
You will have to adapt the 'windowsize' variable and mess around to find a good fit, but a quick go at 600 rows worked well.
Before
After
Cheers,
Ben
// Get the current data table
dt = Current Data Table();
Windowsize = 600; //Set this to the 'width' you want to evaluate
// Initialize an empty table to store the results
dt_summary = New Table( "Summary Table",
New Column( "Serial No", Character ),
New Column( "Batch No", Numeric ),
New Column( "Max Value", Numeric ),
New Column( "Min Elapsed Time", Numeric ),
New Column( "Max Elapsed Time", Numeric ),
New Column( "Start Timestamp", "Numeric", "Nominal", Format("m/d/y h:m:s", 23, 0) ),
New Column( "End Timestamp", "Numeric", "Nominal", Format("m/d/y h:m:s", 23, 0) )
);
// Iterate over unique "Serial No"/identifier column
serials = Associative Array( dt:SerialNo ) << Get Keys();//removes duplicate values
//Run a loop to pull out the max row values for each 'window'
For( i = 1, i <= N Items( serials ), i++,
serial = serials[i];
// Get rows for the current Serial No
rows = dt << Get Rows Where( dt:SerialNo == serial );
// Loop through every [windowsize] rows
For( j = 1, j <= N Items( rows ), j += windowsize,
// Determine the range of rows for the current batch
batch_rows = rows[j :: Min( j + (windowsize-1), N Items( rows ) )];
// Get the max value for this batch
max_val = Max( dt:VOCVoltage[batch_rows] );
// Get the range of 'Elapsed Time'
min_elapsed_time = Min( dt:"Elapsed Time,hours"n[batch_rows] );
max_elapsed_time = Max( dt:"Elapsed Time,hours"n[batch_rows] );
// Get the start and end 'Timestamp'
start_timestamp = dt:Timestamp[batch_rows[1]];
end_timestamp = dt:Timestamp[batch_rows[N Items( batch_rows )]];
// Add a row to the summary table
dt_summary << Add Rows( 1 );
dt_summary:Serial No[N Row( dt_summary )] = serial;
dt_summary:Batch No[N Row( dt_summary )] = Ceiling( j / windowsize );
dt_summary:Max Value[N Row( dt_summary )] = max_val;
dt_summary:Min Elapsed Time[N Row( dt_summary )] = min_elapsed_time;
dt_summary:Max Elapsed Time[N Row( dt_summary )] = max_elapsed_time;
dt_summary:Start Timestamp[N Row( dt_summary )] = start_timestamp ;
dt_summary:End Timestamp[N Row( dt_summary )] = end_timestamp ;
);
);
// Show the summary table
dt_summary << Show Window;
“All models are wrong, but some are useful”