# Capsule duration

## Recommended Posts

Hi all,

Does anyone have any idea for the following statement?

"Select A, If Duration of B>D and D>C
or Select A if B started before D and C"

or anything to select all capsules of A by comparison of capsule (B-C-D) durations.

##### Share on other sites

I got a solution based on this starting point:

The following formula compares the durations of the first capsules for conditions B,C and D bounded by each capsule of condition A and sets a property on capsules of condition A indicating if these should be shown. The keep function on the end only displays capsules where the property is set to true

```\$a.transform(\$a_capsule -> {

\$b_capsule = \$b.toGroup(\$a_capsule).first()
\$c_capsule = \$c.toGroup(\$a_capsule).first()
\$d_capsule = \$d.toGroup(\$a_capsule).first()
\$show_a = (\$b_capsule.duration() > \$d_capsule.duration() and  \$d_capsule.duration() > \$c_capsule.duration())
\$a_capsule.setProperty('show', \$show_a)
}, 40h).keep('show', isequalTo(true) )```

Changing capsule duration of B gets no capsule for result, which is expected:

If you want to show another capsule for the last case, you can adjust the formula to generate another condition with the property show set to the inverse and select one of the conditions based on that value. Therefore you have to do the transform twice:

```\$tempCondition1 = \$a.transform(\$a_capsule -> {

\$b_capsule = \$b.toGroup(\$a_capsule).first()
\$c_capsule = \$c.toGroup(\$a_capsule).first()
\$d_capsule = \$d.toGroup(\$a_capsule).first()
\$show_a = (\$b_capsule.duration() > \$d_capsule.duration() and  \$d_capsule.duration() > \$c_capsule.duration())
\$a_capsule.setProperty('show', \$show_a)
}, 40h)

\$tempCondition2 = \$tempCondition1.transform(\$a_capsule -> {
\$d_capsule = \$d.toGroup(\$a_capsule).first()
\$d_capsule.setProperty('show', not \$a_capsule.property('show'))
}, 40h)

\$tempCondition1.keep('show', isequalTo(true)) or \$tempCondition2.keep('show', isequalTo(true))```

As a result capsules for condition D are shown:

Changing duration of capsule B to its original value show capsules of A as the result:

Hope this helps.

Regards,

Thorsten

## Create an account

Register a new account

×