Environment
A river gauge reports the water level every 15 minutes; the report at 20 h is missing. Here the level rises 20 cm/h to a crest after 12 h and then falls 10 cm/h. The rate is taken of the average of the last 4 reports, so a noisy gauge would not make the warning flicker.
The live chart and its controls need JavaScript. The tables show the Events at the default parameters.
The site cannot run the default parameters: (JavaScript) TypeError: Cannot read properties of undefined (reading 'length')
import io.github.romanhaendler.rbed.*;
import java.time.Duration;
import java.util.Map;
Channel level = Channel.named("level");
Rule floodWarning = Rule.named("FloodWarning")
.when(level.above(300)
.and(level.averageOverSamples(4).rate().above(10 / 3600.0))) // cm/h, as cm/s: rate() is per second
.forDuration(Duration.ofMinutes(30))
.endWhen(level.below(250)).forDuration(Duration.ofHours(2))
.maxGap(Duration.ofMinutes(120));
Rule receding = Rule.named("Receding")
.when(level.falling().and(level.above(300)));
Detector detector = Detector.builder()
.rules(floodWarning, receding)
.build();
for (int quarter = 0; quarter < 72 * 4; quarter++) { // every 15 minutes for 72 h
if (quarter == 20 * 4) continue; // the report at 20 h is missing
double h = quarter / 4.0;
double cm = h <= 12 ? 200 + 20 * h : Math.max(200, 440 - 10 * (h - 12));
detector.push(quarter * 900_000L, Map.of(level, cm));
}
detector.close();
The Rules
- FloodWarning: above 300 cm and still rising faster than 10 cm/h, for 30 minutes; lifted only once below 250 cm for 2 hours. Reports more than 2 hours apart interrupt it.
- Receding: falling while still above 300 cm.
At the defaults, FloodWarning starts at 5.25 h (305 cm), is Confirmed at 5.75 h and Ends at 31.25 h (247.5 cm), the missing report at 20 h being well within 2 hours. Receding runs from 12.25 h (437.5 cm) to 26 h, where the level is exactly 300 cm.
Things to try
- Set Interrupted by a gap over to 15 min, below the 30 minutes between the reports around 20 h: the missing report interrupts the warning, which Ends Truncated at 19.75 h.
Reference
The example is FloodWarningExample, a test with its expected Events, listed in the README's Examples.
Methods used: Channel.named, Rule.named, Rule.when, Expression.above, Condition.and, ChannelExpression.averageOverSamples, ChannelExpression.rate, Rule.forDuration, Rule.endWhen, Expression.below, Rule.maxGap, ChannelExpression.falling, Detector.builder, Detector.Builder.rules, Detector.Builder.build, Detector.push, Detector.close.
The concepts at work, each on a page of its own: Conditions and Expressions, End Conditions and hysteresis, Data gaps.