Etalis tutorial

47 views
Skip to first unread message

Tim Deweert

unread,
Apr 23, 2016, 11:59:55 AM4/23/16
to ETALIS
Hi, I just installed Etalis and I'm trying to understand how it works. I've read the manual but didn't get that much wiser.
I have a class called HeartRate with the following fields:

int heartrate;
String heartratesTimestamp;
String macAddress;

I would like to write a rule that when the heartrate is above 180, the rule fires. Could someone give me a link to a tutorial on jtalis or better
write this rule so that I can build further on it for other rules?

Tim Deweert

unread,
Apr 30, 2016, 12:26:01 PM4/30/16
to ETALIS
After a lot of searching, I found it myself.

PrologEngineWrapper<?> engine = new JPLEngineWrapper();
context
= new JtalisContextImpl(engine);

context
.addEventTrigger("rule1/_");

context
.registerOutputProvider(new myOutputProvider());

// Heart rate raises above 180
context
.addDynamicRule("rule1(RATE,MAC) <- heartrate(RATE,MAC) where " + "(RATE > 180, MAC == 'AAAAAAAA11111111')");

context
.registerOutputProvider(new DefaultOutputProvider() {
 
 @Override
 public void outputEvent(EtalisEvent event) {
 String eventName = event.getName();
 String macAddress = event.getStringProperty(1);
 switch (eventName) {
 case "rule1":
 System.out.println("Message from " + macAddress + ": Heart rate is to high!");
 break;
 case "rule2":
 System.out.println("Message from " + macAddress + ": Heart rate is to low!");
 break;
 }
 }
 
});
EtalisEvent event = new EtalisEvent("heartrate", heartrate.getHeartrate(), heartrate.getMacAddress());
 
event.setTimeStarts(DateConverter.convertISODateToTimestamp(heartrate.getHeartratesTimestamp(), 0));
 
event.setTimeEnds(DateConverter.convertISODateToTimestamp(heartrate.getHeartratesTimestamp(), 1));
 context
.pushEvent(event);



Reply all
Reply to author
Forward
0 new messages