GGD/target/classes/rules/Precipitation.drl

34 lines
1.6 KiB
Plaintext

import java.util.List;
import java.util.HashMap;
import java.util.Map;
import java.util.Iterator;
import eu.hsrw.ias.ggd.ScheduledTask;
import javax.swing.JOptionPane
import HttpCall.HttpPost;
import eu.hsrw.ias.ggd.SensorData
rule "Precipitation"
when
$tMap: HashMap( containsKey("precipitation") == true )
//In this part we are iterating through the entire map
e: Map.Entry(k:key, v:value) from $tMap.entrySet()
// for(e <- $tMap) {
SensorData(level: value ) from v
SensorData(tag: sensorTag) from v
SensorData(id: deviceId) from v
then
String fixedIdG1="8bdbe6ae-eafb-4e99-bb01-db8784dd9633";
HttpPost httpPost = new HttpPost();
if (level > 14.5 && k.equals("precipitation") ) {
JOptionPane.showMessageDialog(null,"High water level : "+level+" in the following sensor"+tag,"Precipitation",JOptionPane.INFORMATION_MESSAGE);
final String data = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"High water level %s\", \"precipitation\": %s}]}}", fixedIdG1, level,level);
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",data);
System.out.println("High water level"+level +" in the following sensor:"+tag);
}
// System.out.println(k);
// System.out.println(level);
// System.out.println(tag);
// System.out.println(id);
end