Calculation issue: how to skip unwanted value?

Hello,

I need help in creating a calculation that will eliminate unwanted signals. In the history of signals from the machine, there are cases in which there is an activity signal -1, then a value of 0 appears and then -1 again. The difference between these events lasts a few seconds, and it is actually one event, but for unknown reasons the signal is interrupted at the automation level. I need to create a calculation that skips the 0 value between two -1 values if the interval between them is 5 seconds. For example:

Instead of history:

0

-1

0

-1

0

 

I want to have:

0

-1

0
screen.jpg