Hi all, I’m trying to build the example 2.14 in Drools Fusion at follow
link:
http://downloads.jboss.com/drools/docs/5.0.1.26597.FINAL/drools-fusion/ht...
two notes:
• Important: Sliding Windows are only available when running the engine in
STREAM mod (paragraph 2.6 – Sliding window )
• Drools generalized the concept of a stream as an "entry point" into the
engine. An entry point is for drools a gate from which facts come. The facts
may be regular facts or special facts like events. (paragraph 2.3 - Stream
support )
1) Presupposing that the SensorReading object is an event, why in order to
develop the example 2.14 the SensorReading object it didn’t use a
entrypoint? I have developed it in this way:
my regoleStream.drl file rule:
declare SensorReading
@role( event )
@timestamp ( timestamp )
@duration ( timeduration )
end
rule "Alarm"
when
TemperatureThreshold( $max : max )
$lettore: SensorReading( ) from entry-point "entry"
$media: Number( doubleValue >= $max ) from accumulate(
SensorReading( $temp : temperature )
over window:time( 5s ) from entry-point "entry" ,
average( $temp ) )
then
System.err.println("Temp media: " + $media);
end
I have defined my class SensorReading.java and Sensor.java
public class SensorReading {
private double temperature;
private long timestamp;
private long timeduration;
// constructor, getters, setters...
}
public class Sensor {
private Random random = new Random();
public double nextReading() {
return (20.5 + random.nextGaussian());
}
}
my class: DroolsTest is defined in STREAM MODE and PSEUDO CLOCK SESSION
configuration
(see the file DroolsTest.java)
http://www.nabble.com/file/p24406682/exampleSensorReading.zip
exampleSensorReading.zip
I have another question: using the accumulated function in order to
calculate the average, I must use update or an insert for a new reading? in
other words:
entrypoint.update( eventhandle, reading ); or
entrypoint.insert(reading);
Using the statement insert my output it is:
Tempo: 0s T: 21.799588922737122
Temp media: 21.799588922737122
Tempo: 1s T: 22.88313013240042
Temp media: 22.88313013240042
Temp media: 22.34135952756877
Tempo: 2s T: 21.421353538299165
Temp media: 21.42135353829916
Temp media: 22.395871267700002
Temp media: 22.034690864478904
Tempo: 3s T: 19.458193737965093
Temp media: 20.930563588215644
Temp media: 21.661451885266274
Temp media: 21.39056658285045
Tempo: 4s T: 20.8832973982136
Temp media: 20.8832973982136
Temp media: 20.921110350215237
Temp media: 21.50582098785574
Temp media: 21.28911274592308
Tempo: 5s T: 19.97430560962051
Tempo: 6s T: 20.518826117217664
Temp media: 20.518826117217664
Temp media: 20.518826117217664
Temp media: 20.518826117217664
Temp media: 20.51882611721767
Temp media: 20.51882611721765
Temp media: 20.51882611721766
Temp media: 20.518826117217674
Tempo: 7s T: 19.189461637685618
Tempo: 8s T: 19.187724324701474
Tempo: 9s T: 18.158118482083236
Tempo: 10s T: 20.587196329519568
Using the statement update my output it is:
Tempo: 0s T: 20.688079808657893
Temp media: 20.688079808657893
Tempo: 1s T: 21.369835728163952
Temp media: 21.369835728163952
Tempo: 2s T: 21.975416358939214
Temp media: 21.975416358939214
Tempo: 3s T: 21.6785090963422
Temp media: 21.6785090963422
Tempo: 4s T: 19.93979461762877
Tempo: 5s T: 20.355758074646886
Temp media: 20.355758074646886
Tempo: 6s T: 21.76122923383071
Temp media: 21.76122923383071
The output that I would wish to obtain (after 5 sec) is the following one:
Tempo: 0s T: 21.799588922737122
Tempo: 1s T: 22.88313013240042
Tempo: 2s T: 21.421353538299165
Tempo: 3s T: 19.458193737965093
Tempo: 4s T: 20.8832973982136
Tempo: 5s T: 19.97430560962051
Temp media: 21.xxxxxxx (fire only if avg is > 20)
You thoughts that my error has had:
A) I use in wrong way the API, in phase of configuration of rule the engine
B) is an logical error of my rule
C) I mistake me and the sliding windows they can’t be used as I would wish
--
View this message in context:
http://www.nabble.com/How-work-the-sliding-windows--tp24406682p24406682.html
Sent from the drools - user mailing list archive at
Nabble.com.