Micah Veith Posted December 4, 2022 Posted December 4, 2022 (edited) 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 December 4, 2022 by Micah Veith Reworded
Thorsten Vogt Posted December 5, 2022 Posted December 5, 2022 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). Regards, Thorsten
Micah Veith Posted December 5, 2022 Author Posted December 5, 2022 Hi Thorsten, Thanks for that, that worked well. Appreciate the help! Regards, Micah
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now