ADD : New feature modify the knowledgebase

master
Kevin Shehu 2022-02-07 11:25:56 +01:00
parent 673f0c09f5
commit 64e7af7f13
18 changed files with 246 additions and 51 deletions

View File

@ -43,17 +43,18 @@ public class BoxCall4Partner {
cName = readFile.ReadFromFile(homeRoot + cName + ".txt");
ArrayList<String> listOfCompanyOutputs = new ArrayList<String>();
String[] arrayOfCompany = cName.split(",");
for (String iterator : arrayOfCompany) {
String[] listOfCompanyDevices = cName.split(",");
for (String companyExternalID : listOfCompanyDevices) {
for (int i = 0; i < jsonarray.length(); i++) {
JSONObject jsonobject = jsonarray.getJSONObject(i);
String jsonExternalID = jsonobject.getString("externalId");
if (iterator.equals(jsonExternalID)) {
String jsonID = jsonobject.getString("id");
JSONObject deviceFromCall = jsonarray.getJSONObject(i);
String deviceExternalID = deviceFromCall.getString("externalId");
if (companyExternalID.equals(deviceExternalID)) {
String backendID = deviceFromCall.getString("id");
// String deviceID = jsonobject.getString("deviceId");
String companyOutput = httpCall.HttpGetCall(devUrl + "devices/" + jsonID + "/sensors" + "?access_token=" + token, token);
listOfCompanyOutputs.add(companyOutput);
writingIntoFile.WriteFile(homeRoot + iterator + ".json", companyOutput);
writingIntoFile.WriteFile(homeRoot + companyExternalID + ".json", companyOutput);
}
}

View File

@ -34,7 +34,6 @@ public class Device {
return setId("70B3D570500042D7");
case "e8c3fca3-c5cd-48e7-9224-0f8c294fa3c0":
return setId("70B3D57050004EF4");
case "f9bb4a5c-f783-4bcf-8c34-0a7c3dd5a632":
return setId("70B3D57050006223");
case "6c9efd4a-db04-453d-8ab8-d480ec97dd26":

View File

@ -1,7 +1,7 @@
package eu.hsrw.ias.ggd;
public class Notification {
private Severity severity = Severity.None;
private Severity severity = Severity.Optimal;
private String type;
private SensorData cause;

View File

@ -1,7 +1,7 @@
package eu.hsrw.ias.ggd;
public enum Severity {
None,
Optimal,
Info,
Warning,
Error,

View File

@ -8,7 +8,7 @@ import eu.hsrw.ias.ggd.Severity;
import eu.hsrw.ias.ggd.Device;
rule "Critical Battery"
rule "CriticalBattery"
when
device: Device(sensorDatas: sensorData)
sensorData: SensorData(tag == "battery", value < 4.0) from sensorDatas
@ -19,7 +19,38 @@ rule "Critical Battery"
HttpPost httpPost = new HttpPost();
final String criticalBatteryOutput = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Critical Battery %s in the following sensor %s \", \"battery\": %s}]}}",greenhouse1, sensorData.getValue(),sensorData.getTag(),sensorData.getValue());
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",criticalBatteryOutput);
insert(new Notification("battery", sensorData, Severity.Info));
insert(new Notification("battery", sensorData, Severity.Critical));
// modify(sensorData){
// setState(Severity.Critical)
// }
end
rule "OptimalBattery"
when
device: Device(sensorDatas: sensorData)
sensorData: SensorData(tag == "battery", value > 4.0) from sensorDatas
then
String greenhouse1="8bdbe6ae-eafb-4e99-bb01-db8784dd9633";
HttpPost httpPost = new HttpPost();
final String optimalBatteryOutput = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Optimal Battery %s in the following sensor %s \", \"battery\": %s}]}}",greenhouse1, sensorData.getValue(),sensorData.getTag(),sensorData.getValue());
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",optimalBatteryOutput);
insert(new Notification("battery", sensorData, Severity.Optimal));
// modify(sensorData){
// setState(Severity.Optimal)
// }
end
// System.out.println(sensorData.getTag()+" "+sensorData.getValue());
// System.out.println(device);
@ -93,6 +124,3 @@ rule "Critical Battery"
finalOutput = String.format("{\"id\":\"70B3D570500042D7-status\",\"data\":{\"measured\":[{ \"status\": \"The status of the device 1 is critical\",}]}}");
System.out.println(finalOutput);
}*/
end

View File

@ -0,0 +1,24 @@
import java.util.HashMap;
import java.util.Map;
import eu.hsrw.ias.ggd.SensorData
import javax.swing.JOptionPane
import HttpCall.HttpPost
import eu.hsrw.ias.ggd.Notification
import eu.hsrw.ias.ggd.Severity;
import eu.hsrw.ias.ggd.Device;
rule "CriticalPrecipitation"
when
device: Device(sensorDatas: sensorData)
sensorData: SensorData(tag == "precipitation", value > 15.5) from sensorDatas
then
String greenhouse1="8bdbe6ae-eafb-4e99-bb01-db8784dd9633";
HttpPost httpPost = new HttpPost();
final String criticalPrecipitationOutput = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Critical Precipitation %s in the following sensor %s \", \"precipitation\": %s}]}}",greenhouse1, sensorData.getValue(),sensorData.getTag(),sensorData.getValue());
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",criticalPrecipitationOutput);
insert(new Notification("precipitation", sensorData, Severity.Warning));
// modify(sensorData){
// setState(Severity.Critical)
// }
end

View File

@ -0,0 +1,7 @@
package rules;
dialect "mvel"
rule "CriticalSoilConductivity"
when
then
end

View File

@ -16,5 +16,24 @@ rule "CriticalSoilMoisture"
HttpPost httpPost = new HttpPost();
final String criticalSoilMoistureOutput = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Critical Soil Moisture %s in the following device %s \", \"soilMoisture\": %s}]}}",greenhouse1, sensorData.getValue(),sensorData.getTag(),sensorData.getValue());
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",criticalSoilMoistureOutput);
final String deviceCritical = String.format("{\"id\":\"%s-status\",\"data\":{\"measured\":[{ \"criticalStatus\": \"The status of %s device is critical\"}]}}",device.IdMapper(device.getId()),device.getId());
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",deviceCritical);
insert(new Notification("soilMoisture", sensorData, Severity.Critical));
end
rule "OptimalSoilMoisture"
when
device: Device(sensorDatas: sensorData)
sensorData: SensorData(tag == "soilMoisture", value > 28.0) from sensorDatas
then
String greenhouse1="8bdbe6ae-eafb-4e99-bb01-db8784dd9633";
HttpPost httpPost = new HttpPost();
final String optimalSoilMoistureOutput = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Optimal Soil Moisture %s in the following device %s \", \"soilMoisture\": %s}]}}",greenhouse1, sensorData.getValue(),sensorData.getTag(),sensorData.getValue());
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",optimalSoilMoistureOutput);
insert(new Notification("soilMoisture", sensorData, Severity.Optimal));
//device.setState(Severity.Optimal);
// modify(device){
// setState(Severity.Optimal)
// }
end

View File

@ -0,0 +1,7 @@
package rules;
dialect "mvel"
rule "CriticalSoilTemperature"
when
then
end

View File

@ -10,7 +10,7 @@ import eu.hsrw.ias.ggd.Device;
rule "CriticalTemperature"
when
device: Device(sensorDatas: sensorData)
sensorData: SensorData(tag == "temperature", value < 10.0 || value >30.0) from sensorDatas
sensorData: SensorData(tag == "temperature", value < 10.0 || value > 30.0) from sensorDatas
then
String greenhouse1="8bdbe6ae-eafb-4e99-bb01-db8784dd9633";
HttpPost httpPost = new HttpPost();
@ -21,3 +21,22 @@ rule "CriticalTemperature"
System.out.println(deviceCritical);
insert(new Notification("temperature", sensorData, Severity.Critical));
end
rule "OptimalTemperature"
when
device: Device(sensorDatas: sensorData)
sensorData: SensorData(tag == "temperature", value > 10.0 && value < 30.0) from sensorDatas
then
String greenhouse1="8bdbe6ae-eafb-4e99-bb01-db8784dd9633";
HttpPost httpPost = new HttpPost();
final String optimalTemperatureOutput = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Optimal Temperature %s in the following device %s \", \"temperature\": %s}]}}",greenhouse1, sensorData.getValue(),sensorData.getTag(),sensorData.getValue());
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",optimalTemperatureOutput);
insert(new Notification("temperature", sensorData, Severity.Optimal));
System.out.println("Optimal");
// modify(sensorData){
// setState(Severity.Optimal)
// }
end

View File

@ -16,5 +16,5 @@ rule "DielectricPermittivity"
HttpPost httpPost = new HttpPost();
final String dielectricPermittivityOutput = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Critical dielectricPermittivity %s in the following sensor %s \", \"dielectricPermittivityOutput\": %s}]}}",greenhouse1, sensorData.getValue(),sensorData.getTag(),sensorData.getValue());
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",dielectricPermittivityOutput);
insert(new Notification("dielectricPermittivity", sensorData, Severity.Info));
insert(new Notification("dielectricPermittivity", sensorData, Severity.Warning));
end

View File

@ -0,0 +1,15 @@
import eu.hsrw.ias.ggd.Notification;
import eu.hsrw.ias.ggd.Severity
import HttpCall.HttpPost;
import eu.hsrw.ias.ggd.Device;
rule "Green House Optimal"
when
warning: Notification(severity == Severity.Optimal)
then
HttpPost httpPost = new HttpPost();
final String optimalGreenhouse = String.format("{\"id\":\"germes-greenhouse-status\",\"data\":{\"measured\":[{ \"status\": \"The status of the greenhouse is optimal\"}]}}");
// httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",optimalGreenhouse);
System.out.println("Green House optimal, because of: '"+warning.getType()+"'");
end

View File

@ -2,14 +2,14 @@ import eu.hsrw.ias.ggd.Notification;
import eu.hsrw.ias.ggd.Severity
import HttpCall.HttpPost;
rule "Green House Critical"
when
warning: Notification(severity > Severity.Info)
then
HttpPost httpPost = new HttpPost();
final String criticalGreenhouse = String.format("{\"id\":\"germes-greenhouse-status\",\"data\":{\"measured\":[{ \"status\": \"The status of the greenhouse is critical\"}]}}");
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",criticalGreenhouse);
System.out.println(criticalGreenhouse);
System.out.println("Green House critical, because of: '"+warning.getType()+"'");
end
//rule "Green House Critical"
//when
// warning: Notification(severity > Severity.Warning)
//then
// HttpPost httpPost = new HttpPost();
// final String criticalGreenhouse = String.format("{\"id\":\"germes-greenhouse-status\",\"data\":{\"measured\":[{ \"status\": \"The status of the greenhouse is critical\"}]}}");
// httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",criticalGreenhouse);
// System.out.println(criticalGreenhouse);
// System.out.println("Green House critical, because of: '"+warning.getType()+"'");
//
//end

View File

@ -8,7 +8,7 @@ import eu.hsrw.ias.ggd.Severity;
import eu.hsrw.ias.ggd.Device;
rule "Critical Battery"
rule "CriticalBattery"
when
device: Device(sensorDatas: sensorData)
sensorData: SensorData(tag == "battery", value < 4.0) from sensorDatas
@ -19,7 +19,38 @@ rule "Critical Battery"
HttpPost httpPost = new HttpPost();
final String criticalBatteryOutput = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Critical Battery %s in the following sensor %s \", \"battery\": %s}]}}",greenhouse1, sensorData.getValue(),sensorData.getTag(),sensorData.getValue());
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",criticalBatteryOutput);
insert(new Notification("battery", sensorData, Severity.Info));
insert(new Notification("battery", sensorData, Severity.Critical));
// modify(sensorData){
// setState(Severity.Critical)
// }
end
rule "OptimalBattery"
when
device: Device(sensorDatas: sensorData)
sensorData: SensorData(tag == "battery", value > 4.0) from sensorDatas
then
String greenhouse1="8bdbe6ae-eafb-4e99-bb01-db8784dd9633";
HttpPost httpPost = new HttpPost();
final String optimalBatteryOutput = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Optimal Battery %s in the following sensor %s \", \"battery\": %s}]}}",greenhouse1, sensorData.getValue(),sensorData.getTag(),sensorData.getValue());
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",optimalBatteryOutput);
insert(new Notification("battery", sensorData, Severity.Optimal));
// modify(sensorData){
// setState(Severity.Optimal)
// }
end
// System.out.println(sensorData.getTag()+" "+sensorData.getValue());
// System.out.println(device);
@ -93,6 +124,3 @@ rule "Critical Battery"
finalOutput = String.format("{\"id\":\"70B3D570500042D7-status\",\"data\":{\"measured\":[{ \"status\": \"The status of the device 1 is critical\",}]}}");
System.out.println(finalOutput);
}*/
end

View File

@ -9,12 +9,36 @@ import eu.hsrw.ias.ggd.Device;
rule "CriticalSoilMoisture"
when
device: Device(sensorDatas: sensorData)
sensorData: SensorData(tag == "soilMoisture", value < 28.0) from sensorDatas
device: Device(sensorDatas: sensorData)
sensorData: SensorData(tag == "soilMoisture", value < 28.0) from sensorDatas
then
String greenhouse1="8bdbe6ae-eafb-4e99-bb01-db8784dd9633";
HttpPost httpPost = new HttpPost();
final String criticalSoilMoistureOutput = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Critical Soil Moisture %s in the following device %s \", \"soilMoisture\": %s}]}}",greenhouse1, sensorData.getValue(),sensorData.getTag(),sensorData.getValue());
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",criticalSoilMoistureOutput);
final String deviceCritical = String.format("{\"id\":\"%s-status\",\"data\":{\"measured\":[{ \"criticalStatus\": \"The status of %s device is critical\"}]}}",device.IdMapper(device.getId()),device.getId());
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",deviceCritical);
insert(new Notification("soilMoisture", sensorData, Severity.Critical));
// modify(device){
// setState(Severity.Critical)
// }
end
rule "OptimalSoilMoisture"
when
device: Device(sensorDatas: sensorData)
sensorData: SensorData(tag == "soilMoisture", value > 28.0) from sensorDatas
then
String greenhouse1="8bdbe6ae-eafb-4e99-bb01-db8784dd9633";
HttpPost httpPost = new HttpPost();
final String optimalSoilMoistureOutput = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Optimal Soil Moisture %s in the following device %s \", \"soilMoisture\": %s}]}}",greenhouse1, sensorData.getValue(),sensorData.getTag(),sensorData.getValue());
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",optimalSoilMoistureOutput);
insert(new Notification("soilMoisture", sensorData, Severity.Optimal));
//device.setState(Severity.Optimal);
// modify(device){
// setState(Severity.Optimal)
// }
end

View File

@ -10,14 +10,38 @@ import eu.hsrw.ias.ggd.Device;
rule "CriticalTemperature"
when
device: Device(sensorDatas: sensorData)
sensorData: SensorData(tag == "temperature", value < 10.0 || value >30.0) from sensorDatas
sensorData: SensorData(tag == "temperature", value < 10.0 || value > 30.0) from sensorDatas
then
String greenhouse1="8bdbe6ae-eafb-4e99-bb01-db8784dd9633";
HttpPost httpPost = new HttpPost();
final String criticalTemperatureOutput = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Critical Temperature %s in the following device %s \", \"temperature\": %s}]}}",greenhouse1, sensorData.getValue(),sensorData.getTag(),sensorData.getValue());
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",criticalTemperatureOutput);
final String deviceCritical = String.format("{\"id\":\"%s-status\",\"data\":{\"measured\":[{ \"criticalStatus\": \"The status of %s device is critical\",}]}}",device.IdMapper(device.getId()),device.getId());
final String deviceCritical = String.format("{\"id\":\"%s-status\",\"data\":{\"measured\":[{ \"criticalStatus\": \"The status of %s device is critical\"}]}}",device.IdMapper(device.getId()),device.getId());
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",deviceCritical);
System.out.println(deviceCritical);
insert(new Notification("temperature", sensorData, Severity.Critical));
// modify(device){
// setState(Severity.Critical)
// }
end
rule "OptimalTemperature"
when
device: Device(sensorDatas: sensorData)
sensorData: SensorData(tag == "temperature", value > 10.0 && value < 30.0) from sensorDatas
then
String greenhouse1="8bdbe6ae-eafb-4e99-bb01-db8784dd9633";
HttpPost httpPost = new HttpPost();
final String optimalTemperatureOutput = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Optimal Temperature %s in the following device %s \", \"temperature\": %s}]}}",greenhouse1, sensorData.getValue(),sensorData.getTag(),sensorData.getValue());
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",optimalTemperatureOutput);
insert(new Notification("temperature", sensorData, Severity.Optimal));
System.out.println("Optimal");
// modify(sensorData){
// setState(Severity.Optimal)
// }
end

View File

@ -16,5 +16,5 @@ rule "DielectricPermittivity"
HttpPost httpPost = new HttpPost();
final String dielectricPermittivityOutput = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Critical dielectricPermittivity %s in the following sensor %s \", \"dielectricPermittivityOutput\": %s}]}}",greenhouse1, sensorData.getValue(),sensorData.getTag(),sensorData.getValue());
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",dielectricPermittivityOutput);
insert(new Notification("dielectricPermittivity", sensorData, Severity.Info));
insert(new Notification("dielectricPermittivity", sensorData, Severity.Warning));
end

View File

@ -2,14 +2,14 @@ import eu.hsrw.ias.ggd.Notification;
import eu.hsrw.ias.ggd.Severity
import HttpCall.HttpPost;
rule "Green House Critical"
when
warning: Notification(severity > Severity.Info)
then
HttpPost httpPost = new HttpPost();
final String criticalGreenhouse = String.format("{\"id\":\"germes-greenhouse-status\",\"data\":{\"measured\":[{ \"status\": \"The status of the greenhouse is critical\",}]}}");
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",criticalGreenhouse);
System.out.println(criticalGreenhouse);
System.out.println("Green House critical, because of: '"+warning.getType()+"'");
end
//rule "Green House Critical"
//when
// warning: Notification(severity > Severity.Warning)
//then
// HttpPost httpPost = new HttpPost();
// final String criticalGreenhouse = String.format("{\"id\":\"germes-greenhouse-status\",\"data\":{\"measured\":[{ \"status\": \"The status of the greenhouse is critical\"}]}}");
// httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",criticalGreenhouse);
// System.out.println(criticalGreenhouse);
// System.out.println("Green House critical, because of: '"+warning.getType()+"'");
//
//end