forked from kevin.shehu/GGD
		
	ADD: New rules for the rule Engine
FIX: ApiCall.java REWORK : JSON_Unpack
This commit is contained in:
		
							
								
								
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @@ -2,7 +2,7 @@ | |||||||
| ### Java template | ### Java template | ||||||
| # Compiled class file | # Compiled class file | ||||||
| *.class | *.class | ||||||
|  | UserCredentials.java | ||||||
| *.iml | *.iml | ||||||
|  |  | ||||||
| # Log file | # Log file | ||||||
| @@ -26,3 +26,4 @@ | |||||||
| # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | ||||||
| hs_err_pid* | hs_err_pid* | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										6
									
								
								.idea/jpa-buddy.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								.idea/jpa-buddy.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,6 @@ | |||||||
|  | <?xml version="1.0" encoding="UTF-8"?> | ||||||
|  | <project version="4"> | ||||||
|  |   <component name="JpaBuddyIdeaProjectConfig"> | ||||||
|  |     <option name="defaultUnitInitialized" value="true" /> | ||||||
|  |   </component> | ||||||
|  | </project> | ||||||
							
								
								
									
										10
									
								
								.idea/runConfigurations.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								.idea/runConfigurations.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,10 @@ | |||||||
|  | <?xml version="1.0" encoding="UTF-8"?> | ||||||
|  | <project version="4"> | ||||||
|  |   <component name="RunConfigurationProducerService"> | ||||||
|  |     <option name="ignoredProducers"> | ||||||
|  |       <set> | ||||||
|  |         <option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" /> | ||||||
|  |       </set> | ||||||
|  |     </option> | ||||||
|  |   </component> | ||||||
|  | </project> | ||||||
							
								
								
									
										6
									
								
								pom.xml
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								pom.xml
									
									
									
									
									
								
							| @@ -42,6 +42,12 @@ | |||||||
|             <artifactId>json-simple</artifactId> |             <artifactId>json-simple</artifactId> | ||||||
|             <version>1.1.1</version> |             <version>1.1.1</version> | ||||||
|         </dependency> |         </dependency> | ||||||
|  |         <!-- https://mvnrepository.com/artifact/com.google.code.gson/gson --> | ||||||
|  |         <dependency> | ||||||
|  |             <groupId>com.google.code.gson</groupId> | ||||||
|  |             <artifactId>gson</artifactId> | ||||||
|  |             <version>2.8.6</version> | ||||||
|  |         </dependency> | ||||||
|  |  | ||||||
|         <dependency> |         <dependency> | ||||||
|             <groupId>org.json</groupId> |             <groupId>org.json</groupId> | ||||||
|   | |||||||
| @@ -1 +1 @@ | |||||||
| T2JK7TpbwuBYDkJx41m4tdL6AUH6sLrTzVolA9mSLsi7A6FtHWFJv2sXVl8IYGQo | 3jINGNigY2BcAHzSTU3K5734i1LvZzZq7ogMAVp4DYy4JkZtjzh0gHIdoqLeIV3n | ||||||
| @@ -23,7 +23,7 @@ public class HttpGet { | |||||||
| //                        .setHeader("access_token", token) | //                        .setHeader("access_token", token) | ||||||
|                     .setHeader("Content-Type", "application/json") |                     .setHeader("Content-Type", "application/json") | ||||||
|                     .setHeader("Accept", "application/json") |                     .setHeader("Accept", "application/json") | ||||||
|                     .header("Authority", "https://api.whysor.com/") |                     .header("Authority", "https://api.dev.whysor.com/") | ||||||
|                     .build(); |                     .build(); | ||||||
|  |  | ||||||
|         } catch (URISyntaxException e) { |         } catch (URISyntaxException e) { | ||||||
|   | |||||||
| @@ -12,17 +12,17 @@ import java.util.ArrayList; | |||||||
| // Get sensor from device for each partner | // Get sensor from device for each partner | ||||||
| public class BoxCall4Partner { | public class BoxCall4Partner { | ||||||
|  |  | ||||||
|     public String FetchBox(String companyName, String token) throws Exception { |     public ArrayList<String> FetchBox(String companyName, String token) throws Exception { | ||||||
|  |  | ||||||
|         switch (companyName) { |         switch (companyName) { | ||||||
|             case "Germes": |             case "Germes": | ||||||
|                 return String.valueOf(onCallMethod("Germes", token)); |                 return onCallMethod("Germes", token); | ||||||
|             case "Heufs": |             case "Heufs": | ||||||
|                 return String.valueOf(onCallMethod("Heufs", token)); |                 return onCallMethod("Heufs", token); | ||||||
|             case "Jacobs": |             case "Jacobs": | ||||||
|                 return String.valueOf(onCallMethod("Jacobs", token)); |                 return onCallMethod("Jacobs", token); | ||||||
|             case "Nica": |             case "Nica": | ||||||
|                 return String.valueOf(onCallMethod("Nica", token)); |                 return onCallMethod("Nica", token); | ||||||
|         } |         } | ||||||
|         return null; |         return null; | ||||||
|     } |     } | ||||||
| @@ -34,6 +34,7 @@ public class BoxCall4Partner { | |||||||
|         WriteFile writingIntoFile = new WriteFile(); |         WriteFile writingIntoFile = new WriteFile(); | ||||||
|  |  | ||||||
|         String baseURL = userCredentials.getBaseURL(); |         String baseURL = userCredentials.getBaseURL(); | ||||||
|  |         String devUrl = userCredentials.getDevUrl(); | ||||||
|         String homeRoot = UserCredentials.getHomeRoot(); |         String homeRoot = UserCredentials.getHomeRoot(); | ||||||
|  |  | ||||||
|         String outputGeneral = GeneralCall4AllDevices.FetchAll(token); |         String outputGeneral = GeneralCall4AllDevices.FetchAll(token); | ||||||
| @@ -43,27 +44,21 @@ public class BoxCall4Partner { | |||||||
|         ArrayList<String> listOfCompanyOutputs = new ArrayList<String>(); |         ArrayList<String> listOfCompanyOutputs = new ArrayList<String>(); | ||||||
|  |  | ||||||
|         String[] arrayOfCompany = cName.split(","); |         String[] arrayOfCompany = cName.split(","); | ||||||
|         int loopTerminator = 0; |  | ||||||
|         for (String iterator : arrayOfCompany) { |         for (String iterator : arrayOfCompany) { | ||||||
|             for (int i = 0; i < jsonarray.length(); i++) { |             for (int i = 0; i < jsonarray.length(); i++) { | ||||||
|                 JSONObject jsonobject = jsonarray.getJSONObject(i); |                 JSONObject jsonobject = jsonarray.getJSONObject(i); | ||||||
|                 String jsonExternalID = jsonobject.getString("externalId"); |                 String jsonExternalID = jsonobject.getString("externalId"); | ||||||
|  |  | ||||||
|                 if (iterator.equals(jsonExternalID)) { |                 if (iterator.equals(jsonExternalID)) { | ||||||
|                     String jsonID = jsonobject.getString("id"); |                     String jsonID = jsonobject.getString("id"); | ||||||
|                     String companyOutput = httpCall.HttpGetCall(baseURL + "devices/" + jsonID + "/sensors" + "?access_token=" + token, token); | //                    String deviceID = jsonobject.getString("deviceId"); | ||||||
|  |                     String companyOutput = httpCall.HttpGetCall(devUrl + "devices/" + jsonID + "/sensors" + "?access_token=" + token, token); | ||||||
|                     listOfCompanyOutputs.add(companyOutput); |                     listOfCompanyOutputs.add(companyOutput); | ||||||
|                     writingIntoFile.WriteFile(homeRoot + i + " " + cName + ".json", companyOutput); |                     writingIntoFile.WriteFile(homeRoot + iterator + ".json", companyOutput); | ||||||
|                     System.out.println(listOfCompanyOutputs); |  | ||||||
|                     loopTerminator++; |  | ||||||
|                     System.out.println(loopTerminator + " " + arrayOfCompany.length + " " + jsonarray.length() + " " + iterator); |  | ||||||
|                 } |  | ||||||
|                 if (loopTerminator == arrayOfCompany.length) { |  | ||||||
|                     return listOfCompanyOutputs; |  | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         return null; |         return listOfCompanyOutputs; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
| @@ -14,9 +14,10 @@ public class GeneralCall4AllDevices { | |||||||
|  |  | ||||||
|         String baseURL = userCredentials.getBaseURL(); |         String baseURL = userCredentials.getBaseURL(); | ||||||
|         String homeRoot = UserCredentials.getHomeRoot(); |         String homeRoot = UserCredentials.getHomeRoot(); | ||||||
|  |         String devUrl = userCredentials.getDevUrl(); | ||||||
|         HttpGet httpCall = new HttpGet(); |         HttpGet httpCall = new HttpGet(); | ||||||
|  |  | ||||||
|         String fetchAll = httpCall.HttpGetCall(baseURL + extension + "?access_token=" + token, token); |         String fetchAll = httpCall.HttpGetCall(devUrl + extension + "?access_token=" + token, token); | ||||||
|         writingIntoFile.WriteFile(homeRoot + extension + "Output.json", fetchAll); |         writingIntoFile.WriteFile(homeRoot + extension + "Output.json", fetchAll); | ||||||
|  |  | ||||||
|         return fetchAll; |         return fetchAll; | ||||||
|   | |||||||
| @@ -33,37 +33,42 @@ public class ReadSensors4Partner { | |||||||
|         WriteFile writingIntoFile = new WriteFile(); |         WriteFile writingIntoFile = new WriteFile(); | ||||||
|  |  | ||||||
|         String baseURL = userCredentials.getBaseURL(); |         String baseURL = userCredentials.getBaseURL(); | ||||||
|  |         String devUrl = userCredentials.getDevUrl(); | ||||||
|         String homeRoot = UserCredentials.getHomeRoot(); |         String homeRoot = UserCredentials.getHomeRoot(); | ||||||
|  |  | ||||||
|         BoxCall4Partner boxCall4Partner = new BoxCall4Partner(); |  | ||||||
|         String outputBox = boxCall4Partner.FetchBox(cName,token); |  | ||||||
|         String outputBoxFixed=outputBox.replace("[[","[") + outputBox.replace("]]","]");// To convert in Jsonarray we need to remove the array list brackets |  | ||||||
|         JSONArray jsonArray = new JSONArray(outputBoxFixed); |  | ||||||
|         System.out.println("FINAL WORKING ARRAY:"+jsonArray); |  | ||||||
|         ArrayList<String> list=new ArrayList<String>(); |         ArrayList<String> list=new ArrayList<String>(); | ||||||
|         int loopTerminator = 0; |  | ||||||
|         char par = '"'; |         char par = '"'; | ||||||
|  |  | ||||||
|  |         BoxCall4Partner boxCall4Partner = new BoxCall4Partner(); | ||||||
|  |         ArrayList<String> outputBox = boxCall4Partner.FetchBox(cName,token); | ||||||
|  |         for (int i=0;i<outputBox.size();i++){ | ||||||
|  |             JSONArray jsonArray = new JSONArray(outputBox.get(i)); | ||||||
|             for(int j=0; j<jsonArray.length(); j++){ |             for(int j=0; j<jsonArray.length(); j++){ | ||||||
|  |  | ||||||
|                 JSONObject jsonobject = jsonArray.getJSONObject(j); |                 JSONObject jsonobject = jsonArray.getJSONObject(j); | ||||||
|                 String jsonID = jsonobject.getString("id"); |                 String jsonID = jsonobject.getString("id"); | ||||||
|                 String jsonTag = jsonobject.getString("tag"); |                 String jsonTag = jsonobject.getString("tag"); | ||||||
|                 String finalTag = ","+par+"sensorTag"+par+":"+jsonTag+"}]"; |                 String deviceID = jsonobject.getString("deviceId"); | ||||||
|  |                 String finalTag = ","+par+"deviceId"+par+":"+deviceID+","+par+"sensorTag"+par+":"+jsonTag+"}]"; | ||||||
|  |  | ||||||
|  |                 String sensorOutput = httpCall.HttpGetCall(devUrl + "sensors/" + jsonID + "/read" + "?access_token=" + token, token); | ||||||
|  |                 if (sensorOutput.contains("error")){ | ||||||
|  |                     System.out.println(sensorOutput); | ||||||
|  |                 } | ||||||
|  |                 else { | ||||||
|  |                     String modification = sensorOutput.replace("}]",""); | ||||||
|  |                     String finalSensorOutput = modification+finalTag; | ||||||
|  |                     list.add(finalSensorOutput); | ||||||
|  |  | ||||||
|  |                     writingIntoFile.WriteFile(homeRoot + jsonID + ".json", sensorOutput + jsonTag+","+deviceID); | ||||||
|  |                 } | ||||||
|  |  | ||||||
|                 String sensorOutput = httpCall.HttpGetCall(baseURL + "sensors/" + jsonID + "/read" + "?access_token=" + token, token); |  | ||||||
|                 String modification = sensorOutput.replace("}]",""); |  | ||||||
|                 String finalSensorOutput = modification+finalTag; |  | ||||||
|                 list.add(finalSensorOutput); |  | ||||||
|  |  | ||||||
|                 writingIntoFile.WriteFile(homeRoot + jsonID + ".json", sensorOutput + jsonTag); |  | ||||||
|                 loopTerminator++; |  | ||||||
|                 if(loopTerminator == jsonArray.length()){ |  | ||||||
|                     return list; |  | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|  |  | ||||||
|  |  | ||||||
|             return null; |             return list; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
| @@ -27,6 +27,8 @@ public class ApiCall { | |||||||
|         WriteFile writingIntoFile = new WriteFile(); |         WriteFile writingIntoFile = new WriteFile(); | ||||||
|         Date now; // to display current time |         Date now; // to display current time | ||||||
|         now = new Date(); |         now = new Date(); | ||||||
|  |         HashMap<String, | ||||||
|  |                 SensorData> finalOutput = new HashMap(); | ||||||
|         if (token.equals(oldId)) { |         if (token.equals(oldId)) { | ||||||
|             //do nothing |             //do nothing | ||||||
|         } else { |         } else { | ||||||
| @@ -43,24 +45,18 @@ public class ApiCall { | |||||||
|         } |         } | ||||||
|         ReadSensors4Partner readSensors4Partner = new ReadSensors4Partner(); |         ReadSensors4Partner readSensors4Partner = new ReadSensors4Partner(); | ||||||
|         ArrayList<String> outputValue = (readSensors4Partner.FetchSensor4Box("Germes", token)); |         ArrayList<String> outputValue = (readSensors4Partner.FetchSensor4Box("Germes", token)); | ||||||
|         String workingArray = String.valueOf(outputValue).replace("[{", "{").replace("}]", "}"); |         for(int i=0;i<outputValue.size();i++){ | ||||||
|  |             JSONArray jsonArray = new JSONArray(outputValue.get(i)); | ||||||
|         JSONArray jsonArray = new JSONArray(workingArray); |             for(int j=0; j<jsonArray.length(); j++){ | ||||||
|  |                 JSONObject jsonobject = jsonArray.getJSONObject(j); | ||||||
|         HashMap<String, |                 double value = jsonobject.getDouble("value"); | ||||||
|                 SensorData> finalOutput = new HashMap(); |                 String sensorTag = jsonobject.getString("sensorTag"); | ||||||
|  |                 String sensorId = jsonobject.getString("sensorId"); | ||||||
|         for (int j = 0; j < jsonArray.length(); j++) { |                 String deviceId = jsonobject.getString("deviceId"); | ||||||
|  |  | ||||||
|             JSONObject jsonobject = jsonArray.getJSONObject(j); |  | ||||||
|             double value = jsonobject.getDouble("value"); |  | ||||||
|             String sensorTag = jsonobject.getString("sensorTag"); |  | ||||||
|             String sensorId = jsonobject.getString("sensorId"); |  | ||||||
|  |  | ||||||
|             finalOutput.put(sensorTag, new SensorData(sensorId, value)); |  | ||||||
|  |  | ||||||
|  |                 finalOutput.put(sensorTag, new SensorData(deviceId, value,sensorId)); | ||||||
|  |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return finalOutput; |         return finalOutput; | ||||||
|  |  | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -7,7 +7,7 @@ public class MainExe { | |||||||
|  |  | ||||||
|         Timer time = new Timer(); // Instantiate Timer Object |         Timer time = new Timer(); // Instantiate Timer Object | ||||||
|         ScheduledTask scheduledTask = new ScheduledTask(); // Instantiate SheduledTask class |         ScheduledTask scheduledTask = new ScheduledTask(); // Instantiate SheduledTask class | ||||||
|         time.schedule(scheduledTask, 0, 1000 * 60 * 5  ); // Create Repetitively task for every 2 min |         time.schedule(scheduledTask, 0, 1000 * 60 * 1  ); // Create Repetitively task for every 2 min | ||||||
|     } |     } | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -10,9 +10,10 @@ public class SecurityToken { | |||||||
|         //CONFIG PARAMETERS: |         //CONFIG PARAMETERS: | ||||||
|         //BEGIN------------CONFIG PARAMETERS BELOW TO YOUR ENVIRONMENT--------------------------------------- |         //BEGIN------------CONFIG PARAMETERS BELOW TO YOUR ENVIRONMENT--------------------------------------- | ||||||
|         String baseURL = "https://api.whysor.com/users/login"; |         String baseURL = "https://api.whysor.com/users/login"; | ||||||
|         final String body = String.format("{\"email\": \"%s\", \"password\": \"%s\", \"domain\": \"my.yookr.org\"}", username, password); |         String devURL = "https://api.dev.whysor.com/users/login"; | ||||||
|  |         final String body = String.format("{\"email\": \"%s\", \"password\": \"%s\", \"domain\": \"my.dev.yookr.org\"}", username, password); | ||||||
|         HttpPost httpMethodPost = new HttpPost(); |         HttpPost httpMethodPost = new HttpPost(); | ||||||
|         return httpMethodPost.HttpCallPost(baseURL, body); |         return httpMethodPost.HttpCallPost(devURL, body); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -4,10 +4,12 @@ public class SensorData { | |||||||
|  |  | ||||||
|     private String sensorId; |     private String sensorId; | ||||||
|     private double value; |     private double value; | ||||||
|  |     private String deviceId; | ||||||
|  |  | ||||||
|     public SensorData(String sensorId, double value) { |     public SensorData(String sensorId, double value,String deviceId) { | ||||||
|         this.sensorId = sensorId; |         this.sensorId = sensorId; | ||||||
|         this.value = value; |         this.value = value; | ||||||
|  |         this.deviceId = deviceId; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public String getSensorTag() { |     public String getSensorTag() { | ||||||
| @@ -25,4 +27,9 @@ public class SensorData { | |||||||
|     public void setValue(double value) { |     public void setValue(double value) { | ||||||
|         this.value = value; |         this.value = value; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public String getDeviceId() {return  deviceId;} | ||||||
|  |  | ||||||
|  |     public void setDeviceId(String deviceTag){ this.deviceId = deviceTag; | ||||||
|  |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,3 +1,4 @@ | |||||||
|  | package rules; | ||||||
| import java.util.List; | import java.util.List; | ||||||
| import java.util.HashMap; | import java.util.HashMap; | ||||||
| import java.util.Map; | import java.util.Map; | ||||||
| @@ -19,18 +20,23 @@ when | |||||||
|     // for(e <- $tMap) { |     // for(e <- $tMap) { | ||||||
|     SensorData(level: value ) from v |     SensorData(level: value ) from v | ||||||
|     SensorData(tag: sensorTag) from v |     SensorData(tag: sensorTag) from v | ||||||
| //    level = v.getValue() |     SensorData(id: deviceId) from v | ||||||
|  |  | ||||||
|  then |  then | ||||||
|  |         HttpPost httpPost = new HttpPost(); | ||||||
|         if (level < 2.8 && k.equals("battery") ) { |         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); |              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\", \"battery\": \"%s\"}]}}", tag, level,level); |              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 httpPost = new HttpPost(); |  | ||||||
|              httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",data); |              httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",data); | ||||||
|              System.out.println(data); |              System.out.println("Low Battery"+level+"in the following sensor"+tag); | ||||||
|          } |          } | ||||||
|  | //         else { | ||||||
|         System.out.println(e.getKey() + "-" + String.valueOf(level)+"-" + tag); | //             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 | end | ||||||
							
								
								
									
										7
									
								
								src/main/resources/rules/DielectricPermittivity.drl
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								src/main/resources/rules/DielectricPermittivity.drl
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,7 @@ | |||||||
|  | package rules; | ||||||
|  | dialect  "mvel" | ||||||
|  |  | ||||||
|  | rule "DielectricPermittivity" | ||||||
|  |     when | ||||||
|  |     then | ||||||
|  | end | ||||||
							
								
								
									
										7
									
								
								src/main/resources/rules/ExternalTemperature.drl
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								src/main/resources/rules/ExternalTemperature.drl
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,7 @@ | |||||||
|  | package rules; | ||||||
|  |  | ||||||
|  |  | ||||||
|  | rule "ExternalTemperature" | ||||||
|  |     when | ||||||
|  |     then | ||||||
|  | end | ||||||
							
								
								
									
										7
									
								
								src/main/resources/rules/Precipitation.drl
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								src/main/resources/rules/Precipitation.drl
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,7 @@ | |||||||
|  | package rules; | ||||||
|  | dialect  "mvel" | ||||||
|  |  | ||||||
|  | rule "Precipitation" | ||||||
|  |     when | ||||||
|  |     then | ||||||
|  | end | ||||||
| @@ -3,17 +3,36 @@ import java.util.HashMap; | |||||||
| import java.util.Map; | import java.util.Map; | ||||||
| import java.util.Iterator; | import java.util.Iterator; | ||||||
| import eu.hsrw.ias.ggd.ScheduledTask; | import eu.hsrw.ias.ggd.ScheduledTask; | ||||||
| import javax.swing.JOptionPane; | import javax.swing.JOptionPane | ||||||
|  | import HttpCall.HttpPost; | ||||||
|  | import eu.hsrw.ias.ggd.SensorData | ||||||
|  |  | ||||||
| rule "Optimal EC levels in the soil" | rule "Optimal EC levels in the soil" | ||||||
|  |  | ||||||
| when | when | ||||||
|      $map : Map (this["soilConductivity"]<0.57 && this["soilConductivity"]>0.11) |      $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 |  then | ||||||
|   System.out.println("Optimal EC levels in the soil : "+$map.get("soilConductivity")); |     String fixedIdG1="8bdbe6ae-eafb-4e99-bb01-db8784dd9633"; | ||||||
|   JOptionPane.showMessageDialog(null,"Optimal EC levels in the soil : "+$map.get("soilConductivity"),"Soil Conductivity",JOptionPane.INFORMATION_MESSAGE); |     String fixedTag="soil Conductivity"; | ||||||
|  |     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\", \"soil conductivity\": %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 | end | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
| @@ -4,26 +4,37 @@ import java.util.Map; | |||||||
| import java.util.Iterator; | import java.util.Iterator; | ||||||
| import eu.hsrw.ias.ggd.ScheduledTask; | import eu.hsrw.ias.ggd.ScheduledTask; | ||||||
| import javax.swing.JOptionPane; | import javax.swing.JOptionPane; | ||||||
| rule "Dry Soil Moisture" | import HttpCall.HttpPost; | ||||||
|  | import eu.hsrw.ias.ggd.SensorData | ||||||
|  |  | ||||||
|  |  | ||||||
|  | rule "Soil Moisture" | ||||||
|  |  | ||||||
| when | when | ||||||
|      $map : Map (this["soilMoisture"]<40) |           $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 |  then | ||||||
|   System.out.println("It is recommended to have a Soil Moisture higher than : "+$map.get("soilMoisture")); |             HttpPost httpPost = new HttpPost(); | ||||||
|   JOptionPane.showMessageDialog(null,"It is recommended to have a Soil Moisture higher than : "+$map.get("soilMoisture"),"Dry Soil Moisture",JOptionPane.INFORMATION_MESSAGE); |             String fixedIdG1="8bdbe6ae-eafb-4e99-bb01-db8784dd9633"; | ||||||
|  |             String fixedTag="soil Moisture"; | ||||||
| end |             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); | ||||||
| rule "Wet Soil Mositure" |                  final String dataInfo = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Be Careful the soil sensor %s is dry: %s  \", \"soil moisture\": %s}]}}", fixedIdG1,fixedTag,level,level); | ||||||
| when |                  httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",dataInfo); | ||||||
|      $map : Map (this["soilMoisture"]>70) |                  System.out.println("Soil is dry"+level+" in the following sensor"+tag); | ||||||
|  |              } | ||||||
|  then |              else  if (level <= 80 && k.equals("soilMoisture") ) { | ||||||
|   System.out.println("Be careful the soil is extremly wet :"+$map.get("soilMoisture")+ "please dont apply water"); |                  JOptionPane.showMessageDialog(null,"Optimal moisture in the soil : "+level+" in the following sensor"+tag,"Soil Moisture",JOptionPane.INFORMATION_MESSAGE); | ||||||
|     JOptionPane.showMessageDialog(null,"Be careful the soil is extremly wet :"+$map.get("soilMoisture")+ "please dont apply water","Wet Soil Moisture",JOptionPane.INFORMATION_MESSAGE); |                  final String data = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Be Careful the soil sensor %s is wet: %s\", \"soil moisture\": %s}]}}", fixedIdG1,fixedTag,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 | end | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										29
									
								
								src/main/resources/rules/SoilTemperature.drl
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								src/main/resources/rules/SoilTemperature.drl
									
									
									
									
									
										Normal 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 \", \"soil temperature\": %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 | ||||||
							
								
								
									
										40
									
								
								src/main/resources/rules/Temperature.drl
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								src/main/resources/rules/Temperature.drl
									
									
									
									
									
										Normal 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 | ||||||
		Reference in New Issue
	
	Block a user