Jump to content

Rolling time periods that extend into the past


Recommended Posts

  • Seeq Team

Seeq is able to do many time periods, but what if you want to compare a time period from now, with similar periods in the past? An example of this could be comparing the 24 hour period before now, with the previous 24 hour period, and the one before etc. Add in that you want this period to be rolling and it becomes more complex.

Example:

 

The time now is 3PM, you want to look at the period of yesterday 3PM till today 3PM, and compare with similar 24 hour periods over the last 30 days. Then you want to do it again every 5 minutes with up to date time periods, so 3:05PM with the pervious 24 hours and similar periods for the last 30 days.

 

 

The way to do this involves several steps, but basically the solution is to look at the time now from Midnight past, then move a daily periodic condition by this time, which is ever changing. 

 

Once you have executed this formula you can use the resulting capsules for aggregations on the rolling time periods extending into the past.

You can paste the following formula directly into Seeq Formula tool, no need for any signals to be added.

 

 

$days = days("Europe/London")
$daynow = condition(1d, capsule(now()-24h, now())) //isolate the current daily capsule
$timesince = timeSince($days, 1min) //time since midnight in minutes
$timesincediscrete = $timesince.aggregate(endValue(true), $daynow, endKey(), 40h) //make discrete

//Now going to use the discrete data point for time since midnight to make that time go into the past to cover 
// every daily capsule that is going to be moved in time, I am using 30 days, but change this to cover your own use case

$movetimesincetopast = $timesincediscrete.move(-30 days)

//now to join the current timesince midnight to the one moved into the past
//we also have to resample the result to ensure data points are available for every capsule. The maxinterpolation should be greater
//than your timescale, in my case greater than the 30 days used above

$combined = $timesincediscrete.combineWith($movetimesincetopast).setMaxInterpolation(40 days).setunits('mins')
$combinedresampled = $combined.resample(1min)

//Now to transform our daily capsules to move the start of the capsules by the current time from midnight, note we can 
//only move the start as if we also move the end it will result in an error as the resulting capsules would no longer 
//be contained by the original capsules
$transform =
$days

     .transform($capsule -> {
                $newStartKey = $capsule.startKey() + $combinedresampled.valueAt($capsule.startKey())
                capsule($newStartKey, $capsule.endKey())
                })
                

 

//Finally we can use the start of the transformed capsules to create new 24 hour capsules, these will continually update on a refresh, or update frequency assigned in workbench

//Use the 'step to current time' button in the display pane to see the start/end times of the capsules update in the capsule pane


$finalcapsules = $transform.afterstart(24 hours)

Return $finalcapsules

 

 

Notes:

If you extend this over a large time period/very high frequency refresh, you will cause significant calculations to be performed, slowing your Seeq system

The resulting capsules will always be uncertain, as the time period is ever changing.

Whilst I have used 'Days' & '24h', you can alter the formula for any time periods, but bear in mind that very short periods will cause significant calculations if over a relatively long time period into the past.
 

 

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...