0

I’m trying to ID when my thermometers are going offline using this pattern:

Pattern "missing temps" (temp : &float ∈ any):
     @temp is nil 5..;

It works, except that if there are more than 5 values missing I get a separate match for every missing value over 5.

So if I have:

50 50 nil nil nil nil nil nil nil 50 51

I get 3 matches:

nil nil nil nil nil

nil nil nil nil nil nil

nil nil nil nil nil nil nil

If a thermometer goes offline for a long time, the notifications will get totally out of control. Why is it doing this? How can I stop the redundant matches?

Community
  • 1
  • 1
quw
  • 2,844
  • 1
  • 26
  • 35

1 Answers1

1

From Barrage's POV, the multiple matches aren't redundant; it's doing what it's supposed to do by restarting the pattern match on every value. It just so happens that your pattern here can match over the same series of values multiple times.

But of course in this case that behavior is not so helpful. It's a simple fix though:

Pattern "missing temps" (temp : &float ∈ any):
    @temp is nil 5.. [longest];

The [longest] tells Barrage that, once the minimum five consecutive nils have been encountered:

  • Hold off on considering the step 'matched' until the next event has been checked

and

  • Do not finish the step match until the next event would make the step fail.

So for your example:

50 50 nil nil nil nil nil nil nil 50 51

The step would not match until after the longest possible series of nil values:

nil nil nil nil nil nil nil

And if you had twenty consecutive nil values instead, the step wouldn't match until it had repeated over all twenty nils.

So just add [longest] to the end of the step and your pattern should do what you want.

Erin
  • 26
  • 2