GGD/target/classes/rules/Battery.drl

41 lines
2.2 KiB
Plaintext
Raw Normal View History

import java.util.List;
import java.util.HashMap;
import java.util.Map;
import java.util.Iterator;
import eu.hsrw.ias.ggd.ScheduledTask
import eu.hsrw.ias.ggd.SensorData
import javax.swing.JOptionPane
import HttpCall.HttpPost
import Files.ReadFile
import Credentials.UserCredentials;
rule "Low Battery Level"
when
// This is like declaring a variable tMap where is Map and contains a key with name battery
$tMap: HashMap( containsKey("battery") == 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
HttpPost httpPost = new HttpPost();
String fixedIdG1="8bdbe6ae-eafb-4e99-bb01-db8784dd9633";
if (level < 7.2 && k.equals("battery") ) {
JOptionPane.showMessageDialog(null,"Low Battery : "+level+"! Please swap the battery soon of the following sensor:"+tag,"Low Battery Level",JOptionPane.INFORMATION_MESSAGE);
final String data = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Low Battery %s in the following sensor: %s \", \"battery\": %s}]}}", fixedIdG1,level, tag,level);
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",data);
System.out.println("Low Battery"+level+"in the following sensor"+tag);
}
// else {
// JOptionPane.showMessageDialog(null,"Battery OK : "+level+"! in the following sensor :"+tag,"Battery OK",JOptionPane.INFORMATION_MESSAGE);
// final String data1 = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Battery OK %s in the following sensor: %s \", \"battery\": %s}]}}", fixedIdG1,level, tag,level);
//// httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",data1);
// System.out.println(data1);
// }
// System.out.println($tMap);
// System.out.println(e.getKey() + " " + String.valueOf(level)+" " + tag+" "+id);
end