ADD: New rules for the rule Engine

ADD : devUrl
FIX : README.md
This commit is contained in:
2021-11-29 11:18:15 +01:00
parent 141d474ef3
commit 2180026612
46 changed files with 385 additions and 21 deletions

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule">
<kbase name="rules" packages="rules">
<ksession name="ksession-rule"/>
</kbase>
</kmodule>

View File

@@ -0,0 +1,3 @@
groupId=com.javainuse
artifactId=drools-hello-world
version=0.0.1-SNAPSHOT

View File

@@ -0,0 +1,41 @@
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

View File

@@ -0,0 +1,33 @@
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 "DielectricPermittivity"
when
$tMap: HashMap( containsKey("dielectricPermittivity") == 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("dielectricPermittivity") ) {
JOptionPane.showMessageDialog(null,"High dielectricPermittivity : "+level+" in the following sensor"+tag,"dielectricPermittivity",JOptionPane.INFORMATION_MESSAGE);
final String data = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"High dielectricPermittivity %s\", \"dielectricPermittivity\": %s}]}}", fixedIdG1, level,level);
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",data);
System.out.println("High dielectricPermittivity"+level +" in the following sensor:"+tag);
}
System.out.println(k);
System.out.println(level);
System.out.println(tag);
System.out.println(id);
end

View File

@@ -0,0 +1,7 @@
package rules;
rule "ExternalTemperature"
when
then
end

View File

@@ -0,0 +1,33 @@
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

View File

@@ -0,0 +1,39 @@
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 "Optimal EC levels in the soil"
when
$tMap: HashMap( containsKey("soilConductivity") == 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 <= 0.57 && level >= 0.11 && k.equals("soilConductivity") ) {
JOptionPane.showMessageDialog(null,"Optimal EC levels in the soil : "+level+" in the following sensor"+tag,"Soil Conductivity",JOptionPane.INFORMATION_MESSAGE);
final String data = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Optimal EC levels in the soil %s\", \"soilConductivity\": %s}]}}", fixedIdG1, level,level);
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",data);
System.out.println("Optimal EC levels in the soil"+level +" in the following sensor:"+tag);
}
// else {
// JOptionPane.showMessageDialog(null,"Non Optimal EC levels in the soil : "+level+" in the following sensor:"+tag,"Soil Conductivity",JOptionPane.INFORMATION_MESSAGE);
// final String data1 = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Non Optimal EC levels in the soil %s\", \"soil Conductivity\": %s}]}}", fixedIdG1, level,level);
//// httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",data1);
// System.out.println(data1);
// }
end

View File

@@ -0,0 +1,40 @@
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 "Soil Moisture"
when
$tMap: HashMap( containsKey("soilMoisture") == 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 <= 30 && k.equals("soilMoisture") ) {
JOptionPane.showMessageDialog(null,"Be Careful the soil is dry : "+level+" in the following sensor :"+tag +"in the device:"+id,"Soil Moisture",JOptionPane.INFORMATION_MESSAGE);
final String dataInfo = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Be Careful the soil sensor %s is dry: %s \", \"soilMoisture\": %s}]}}", fixedIdG1,tag,level,level);
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",dataInfo);
System.out.println("Soil is dry"+level+" in the following sensor"+tag);
}
else if (level <= 80 && k.equals("soilMoisture") ) {
JOptionPane.showMessageDialog(null,"Optimal moisture in the soil : "+level+" in the following sensor"+tag,"Soil Moisture",JOptionPane.INFORMATION_MESSAGE);
final String data = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Be Careful the soil sensor %s is wet: %s\", \"soilMoisture\": %s}]}}", fixedIdG1,tag,level,level);
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",data);
System.out.println("Optimal moisture in the soil"+level+" in the following sensor"+tag);
}
end

View File

@@ -0,0 +1,29 @@
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 "SoilTemperature"
when
$tMap: HashMap( containsKey("soilTemperature") == true )
e: Map.Entry(k:key, v:value) from $tMap.entrySet()
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 < 22 && k.equals("soilTemperature") ) {
JOptionPane.showMessageDialog(null,"Low soil temperature : "+level+" in the following sensor: "+tag+"in the following device id: "+id,"soil Temperature",JOptionPane.INFORMATION_MESSAGE);
final String data = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Low soil temperature %s in the following sensor: %s \", \"soilTemperature\": %s}]}}", fixedIdG1,level, tag,level);
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",data);
System.out.println("Low soil Temperature"+level+" in the following sensor "+tag);
}
end

View File

@@ -0,0 +1,40 @@
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 "Temperature Check"
when
// This is like declaring a variable tMap where is Map and contains a key with name battery
$tMap: HashMap( containsKey("temperature") == 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 > 80 && k.equals("temperature") ) {
JOptionPane.showMessageDialog(null,"High Temperature : "+level+" in the following sensor: "+tag+"in the following device id: "+id,"Temperature",JOptionPane.INFORMATION_MESSAGE);
final String data = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"High Temperature %s in the following sensor: %s \", \"temperature\": %s}]}}", fixedIdG1,level, tag,level);
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",data);
System.out.println("High Temp");
}
else if(level < 20 && k.equals("temperature")){
JOptionPane.showMessageDialog(null,"Low Temperature : "+level+" in the following sensor: "+tag+"in the following device id: "+id,"Temperature",JOptionPane.INFORMATION_MESSAGE);
final String data1 = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Low Temperature %s in the following sensor: %s \", \"temperature\": %s}]}}",fixedIdG1,level, tag,level);
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",data1);
System.out.println("Low Temp "+tag);
}
end