KnowledgeBaseConfiguration config = KnowledgeBaseFactory
.newKnowledgeBaseConfiguration();
config.setOption(EventProcessingOption.STREAM);
KnowledgeBase kbase = KnowledgeBaseFactory
.newKnowledgeBase(config);
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
StatefulKnowledgeSession ksession = kbase
.newStatefulKnowledgeSession();
How do I approach setting it, is it possible within DRL file? Could you give some hint?
Please see below (not sure if there are no errors in it)
declare Event
@role( event )
end
rule "check sliding window"
when
$e : Event(source == "Temp3", value != "N/A")
Number( doubleValue > 0 ) from accumulate(
Event( source == "Temp3", $temp : value ) over window:time( 10m ),
average( $temp ) )
then
System.out.println("Sliding window");
end
--
You received this message because you are subscribed to a topic in the Google Groups "OpenRemote" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/openremotecommunity/lzFYq-0bDZQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to openremotecommu...@googlegroups.com.
Visit this group at https://groups.google.com/group/openremotecommunity.
To view this discussion on the web visit https://groups.google.com/d/msgid/openremotecommunity/b589877f-0a0f-49d3-891a-f7963d86a6db%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
declare Event
@role( event )
@expires( 5m )
end
declare window AvgTemp3Window
Event( source == "Temp3", value != "N/A" )
over window:time( 1m )
end
function String _TimeStamp(){
Date now = new Date();
SimpleDateFormat dateFormatter = new SimpleDateFormat("d H:mm:ss");
return(dateFormatter.format(now));
}
rule "check fusion"
when
$b1:Event( source == "Temp3" )
then
String v = $b1.getValue().toString();
System.out.println(_TimeStamp() + " -- OK. Temp is: "+v);
end
rule "check sliding window"
when
accumulate( $temp : Event() from window AvgTemp3Window,
$avg : average( Double.parseDouble($temp.getValue().toString()) ),
$cnt : count( $temp ) )
then
System.out.println(_TimeStamp() + " -- Sliding window. Avg is: " + String.valueOf($avg) + " Count is: " + String.valueOf($cnt));
declare CustomEvent
@role(event)
@expires(5m)
source: String
value: double
end
rule InsertTempValues
when
Event($source: source matches "Temp\\d+", $value: value)
then
insert(new CustomEvent($source, Double.parseDouble($value.toString())));
end
package org.openremote.controller.model.event
global org.openremote.controller.statuscache.CommandFacade execute;
global org.openremote.controller.statuscache.SwitchFacade switches;
import org.openremote.controller.protocol.*;
import java.text.DecimalFormat;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.io.*;
import java.util.Properties;
import javax.naming.*;
import org.joda.time.DateTime;
import java.util.Timer;
import java.util.TimerTask;
import java.lang.Float;
import java.lang.Number;
import java.util.concurrent.TimeUnit;
declare CustomEvent
@role(event)
@expires(2m)
source: String
value: String
end
declare window AvgTemp3Window
CustomEvent()
over window:time( 1m )
end
function String _TimeStamp(){
Date now = new Date();
SimpleDateFormat dateFormatter = new SimpleDateFormat("d H:mm:ss");
return(dateFormatter.format(now));
}
rule "InsertTempValues"
when
Event($source: source matches "Temp\\d+", $value : value!= "N/A")
then
insert(new CustomEvent( String.valueOf($source), String.valueOf($value) ));
end
rule "Read temp"
when
$b1:Event( source == "Temp3" )
then
String v = $b1.getValue().toString();
System.out.println(_TimeStamp() + " -- OK. Temp is: "+v);
end
rule "Check sliding window"
when
accumulate( $temp : CustomEvent() from window AvgTemp3Window,
$avg : average( Double.parseDouble($temp.getValue().toString()) ),
$cnt : count( $temp ) )
then
System.out.println(_TimeStamp() + " -- Sliding window. Avg is: " + String.valueOf($avg) + " Count is: " + String.valueOf($cnt));
end