Jump to content

Merge/join capsules within a condition


Micah Veith

Recommended Posts

Hi All,

I'm trying to merge/join a group of capsules when they occur within another capsule/condition. For example, I would like to merge capsule A when they occur within capsule B. C is the desired output.

Input A:   |--A--|   |---A---|       |--A--|        |-A-|      |---A---|       |--A--|   |---A---|

Input B: |-------------B-----------------|                |----------------B-----------------| 

Output:   |-------------C-------------|                      |---------------C-------------|

It seems like it should be relatively simple but I can't figure out how to achieve this. 

Any help is appreciated!

Edited by Micah Veith
Reworded
Link to comment
Share on other sites

  • Micah Veith changed the title to Merge/join capsules within a condition

Hi Micah,

you can do this with a transform:

$inputB.transform($capsule -> {
  $capsulesOfInputA = $inputA.removeLongerThan(1wk).toGroup($capsule)
  $start = $capsulesOfInputA.first().startKey()
  $end = $capsulesOfInputA.last().endKey()
  capsule(max($start, $capsule.startKey()), min($end, $capsule.endKey()))
})

As the capsules for the output can only be as long as the capsules of Input B, I am using max() and min() to reduce the capsule length if capsules of Input A overlap with the beginning or end of a capsule of Input B (see first result).

image.thumb.png.9580b8e23857bf5f20d14249ef881c16.png

Regards,

Thorsten

 

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...