Jump to content

Signal-Based Capsule Adjustments


Recommended Posts

  • Members

Seeq has functions to allow easy manipulation of the starts and ends of capsules, including functions like afterStart(), move(), and afterEnd(). One limitation of these functions is that they expect scalar inputs, which means all capsules in the condition have to be adjusted by the same amount (e.g. move all capsules 1 hour into the future).

There are cases when you want to adjust each capsule dynamically, for instance using the value of a signal to determine how to adjust the capsule.

Solution:

This post will show how to accomplish a dynamic / signal-based version of afterStart(). This approach can be modified slightly to recreate other capsule adjustment functions.

Assume I have an arbitrary condition 'Condition', and signal 'Capsule Adjustment Signal'. I want to find the first X hours after each capsule start, where X is the value of 'Capsule Adjustment Signal' at the capsule start. I can do this with the below formula.

image.png

$condition
     .afterStart(3h) // has to be longer than an output capsule will ever be
     .transform($capsule -> {
                $newStartKey = $capsule.startKey()
                $newEndKey = $capsule.startKey() + $signal.valueAt($capsule.startKey())
                capsule($newStartKey, $newEndKey)
                })

This formula only takes two inputs: $condition, and $signal. This formula goes through each capsule in the condition, and manipulates its start and end keys. In this case, the start key is the same as the original, but the new end key is set to the original start key plus the value of my signal. This formula produces the following purple condition:

image.png

Some notes on this formula:

  • The output capsules must be within the original capsules. Therefore, I have included .afterStart(3h) in the formula. This ensures the original capsules will always be larger than the outputted capsules. If you don't do this, you may see the following warning on your item, which indicates the formula is throwing away capsules:

image.png

  • Your capsule adjustment signal must have units of time

To accomplish other capsule adjustments, look at changing the definitions of the $newStartKey and $newEndKey variables to suit your needs.

  • Like 2
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
 Share

×
×
  • Create New...