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

## Retrieve average amount of time spend above a limit within time series data

Hi,

I was wondering if there would be an easy way to retrieve the average amount of time (in hours or minutes) that a signal stays above a certain limit within time series data. I have added an example data set in the attachment.

I added some preliminary SD limits which i calculated based on the mean baseline of the data.

So what would be the avarge amount of time for the signal to return back below 2SD, 3SD or 5SD?

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Super User

## Re: Retrieve average amount of time spend above a limit within time series data

It is a pretty simple formula that will calculate the durations.

And then I just ran a distribution to see the shape of the data, and to get the mean.

In my example below, I only create one new column that determines the duration time spent over 1 SD.  The formula is pretty straight forward so using it to calculate the 2SD etc. should be expandable from the first formula.

Here is the JSL to do the calculation and display.  This can easily be done interactively.

``````Names Default To Here( 1 );
dt = Current Data Table();

dt << New Column( "sd1 Duration",
Numeric,
"Continuous",
Format( "hr:m:s", 13, 0 ),
Input Format( "hr:m:s", 0 ),
Formula(
If( Row() == 1,
start = 0;
sdLimit = Col Mean( :Count ) + Col Std Dev( :Count );
);
theTime = .;
If( :Count <= sdLimit & start > 0,
theTime = :"Date/Time"n - start;
start = 0;
);
If( :Count > sdLimit & start == 0,
start = :"Date/Time"n
);
theTime;
),
Set Selected
);

Distribution(
Continuous Distribution( Column( :sd1 Duration ), Horizontal Layout( 1 ), Vertical( 0 ) ),
SendToReport(
Dispatch(
{"sd1 Duration"},
"1",
ScaleBox,
{Min( -2009.13865683119 ), Max( 143459.453400931 ), Interval( "Hour" ), Inc( 10 ),
Minor Ticks( 1 )}
),
Dispatch(
{"sd1 Duration"},
"Distrib Histogram",
FrameBox,
{DispatchSeg( Hist Seg( 1 ), Bin Span( 2, 0 ) )}
)
)
);``````
Jim
2 REPLIES 2
Super User

## Re: Retrieve average amount of time spend above a limit within time series data

It is a pretty simple formula that will calculate the durations.

And then I just ran a distribution to see the shape of the data, and to get the mean.

In my example below, I only create one new column that determines the duration time spent over 1 SD.  The formula is pretty straight forward so using it to calculate the 2SD etc. should be expandable from the first formula.

Here is the JSL to do the calculation and display.  This can easily be done interactively.

``````Names Default To Here( 1 );
dt = Current Data Table();

dt << New Column( "sd1 Duration",
Numeric,
"Continuous",
Format( "hr:m:s", 13, 0 ),
Input Format( "hr:m:s", 0 ),
Formula(
If( Row() == 1,
start = 0;
sdLimit = Col Mean( :Count ) + Col Std Dev( :Count );
);
theTime = .;
If( :Count <= sdLimit & start > 0,
theTime = :"Date/Time"n - start;
start = 0;
);
If( :Count > sdLimit & start == 0,
start = :"Date/Time"n
);
theTime;
),
Set Selected
);

Distribution(
Continuous Distribution( Column( :sd1 Duration ), Horizontal Layout( 1 ), Vertical( 0 ) ),
SendToReport(
Dispatch(
{"sd1 Duration"},
"1",
ScaleBox,
{Min( -2009.13865683119 ), Max( 143459.453400931 ), Interval( "Hour" ), Inc( 10 ),
Minor Ticks( 1 )}
),
Dispatch(
{"sd1 Duration"},
"Distrib Histogram",
FrameBox,
{DispatchSeg( Hist Seg( 1 ), Bin Span( 2, 0 ) )}
)
)
);``````
Jim
Level III

Thanks Jim!