FINALIZED : FULLY WORKING

TODO : DATA MANIPULATION
master
Kevin Shehu 2021-06-23 23:35:42 +02:00
parent e357d53584
commit 5b21bd77d5
15 changed files with 110 additions and 75 deletions

View File

@ -11,7 +11,35 @@
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_14_PREVIEW" default="false" project-jdk-name="14.0.1" project-jdk-type="JavaSDK">
<component name="ProjectPlainTextFileTypeManager">
<file url="file://$PROJECT_DIR$/src/main/java/Data/0 0004A30B00227D68,70B3D5705000E019.json" />
<file url="file://$PROJECT_DIR$/src/main/java/Data/12 70B3D57050004682,70B3D570500046AB,70B3D57050004D14.json" />
<file url="file://$PROJECT_DIR$/src/main/java/Data/12 70B3D57050004682,70B3D57050004D14.json" />
<file url="file://$PROJECT_DIR$/src/main/java/Data/13 70B3D57050004223,70B3D570500042D7,70B3D57050004EEF,70B3D57050006223,70B3D5705000623C.json" />
<file url="file://$PROJECT_DIR$/src/main/java/Data/13 70B3D57050004223,70B3D570500042D7,70B3D57050004EF4,70B3D57050006223,70B3D5705000623C.json" />
<file url="file://$PROJECT_DIR$/src/main/java/Data/13ebfdd7-8a4f-4410-97ee-e51d6fccd569.json" />
<file url="file://$PROJECT_DIR$/src/main/java/Data/14 70B3D57050004223,70B3D570500042D7,70B3D57050004EF4,70B3D57050006223,70B3D5705000623C.json" />
<file url="file://$PROJECT_DIR$/src/main/java/Data/15 70B3D57050004223,70B3D570500042D7,70B3D57050004EEF,70B3D57050006223,70B3D5705000623C.json" />
<file url="file://$PROJECT_DIR$/src/main/java/Data/15 70B3D57050004223,70B3D570500042D7,70B3D57050004EF4,70B3D57050006223,70B3D5705000623C.json" />
<file url="file://$PROJECT_DIR$/src/main/java/Data/23d6a70b-befb-4895-b138-20e08d2a195c.json" />
<file url="file://$PROJECT_DIR$/src/main/java/Data/26bc66de-66af-4430-ace4-ea4eac6f8c95.json" />
<file url="file://$PROJECT_DIR$/src/main/java/Data/389d6a48-cc10-4160-ba53-2b3cd80622d6.json" />
<file url="file://$PROJECT_DIR$/src/main/java/Data/3eb4f776-8eca-4354-a3d8-d4b988b387ad.json" />
<file url="file://$PROJECT_DIR$/src/main/java/Data/4 70B3D57050004223,70B3D570500042D7,70B3D57050004EEF,70B3D57050006223,70B3D5705000623C.json" />
<file url="file://$PROJECT_DIR$/src/main/java/Data/4 70B3D57050004223,70B3D570500042D7,70B3D57050004EF4,70B3D57050006223,70B3D5705000623C.json" />
<file url="file://$PROJECT_DIR$/src/main/java/Data/6 70B3D57050004682,70B3D570500046AB,70B3D57050004D14.json" />
<file url="file://$PROJECT_DIR$/src/main/java/Data/6 70B3D57050004682,70B3D57050004D14.json" />
<file url="file://$PROJECT_DIR$/src/main/java/Data/64a3d8c3-027c-4125-afeb-f53bbd0b7cc3.json" />
<file url="file://$PROJECT_DIR$/src/main/java/Data/6b5ae232-2ada-49e5-8f79-4dbfc276dc7a.json" />
<file url="file://$PROJECT_DIR$/src/main/java/Data/7 0004A30B00227D68,70B3D5705000E019.json" />
<file url="file://$PROJECT_DIR$/src/main/java/Data/7669429f-94e4-4e4f-a0cc-56e96523ded5.json" />
<file url="file://$PROJECT_DIR$/src/main/java/Data/8 70B3D57050004223,70B3D570500042D7,70B3D57050004EEF,70B3D57050006223,70B3D5705000623C.json" />
<file url="file://$PROJECT_DIR$/src/main/java/Data/8 70B3D57050004223,70B3D570500042D7,70B3D57050004EF4,70B3D57050006223,70B3D5705000623C.json" />
<file url="file://$PROJECT_DIR$/src/main/java/Data/bdc213b0-50c4-4085-867a-c724fd454670.json" />
<file url="file://$PROJECT_DIR$/src/main/java/Data/devicesOutput.json" />
<file url="file://$PROJECT_DIR$/src/main/java/Data/e01b1f84-41c9-4cbf-8690-9b3552c8bc6d.json" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_16" project-jdk-name="14.0.1" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

24
pom.xml
View File

@ -3,10 +3,13 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<properties>
<runtime.version>7.48.0.Final</runtime.version>
</properties>
<groupId>org.example</groupId>
<artifactId>GGD</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
@ -17,12 +20,13 @@
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<runtime.version>7.48.0.Final</runtime.version>
</properties>
<dependencies>
<dependency>
<groupId>info.picocli</groupId>
<artifactId>picocli</artifactId>
@ -50,25 +54,25 @@
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-core</artifactId>
<version>7.48.0.Final</version>
<version>${runtime.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.drools/drools-compiler -->
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-compiler</artifactId>
<version>7.48.0.Final</version>
<version>${runtime.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.drools/drools-decisiontables -->
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-decisiontables</artifactId>
<version>7.48.0.Final</version>
<version>${runtime.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.drools/kiebase-inclusion -->
<dependency>
<groupId>org.drools</groupId>
<artifactId>kiebase-inclusion</artifactId>
<version>7.48.0.Final</version>
<version>${runtime.version}</version>
<scope>runtime</scope>
</dependency>
@ -76,14 +80,14 @@
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-api</artifactId>
<version>7.48.0.Final</version>
<version>${runtime.version}</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.kie/kie-ci -->
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-ci</artifactId>
<version>7.48.0.Final</version>
<version>${runtime.version}</version>
</dependency>
<!-- <repositories>-->
<!-- <repository>-->

View File

@ -1,8 +1,11 @@
import Credentials.UserCredentials;
import Files.WriteFile;
import JSON_Unpack.ReadSensors4Partner;
import Knowledgebase.SensorReadings;
import org.json.JSONArray;
import org.json.JSONObject;
import java.lang.reflect.Array;
import java.util.ArrayList;
public class ApiCall {
@ -33,11 +36,29 @@ public class ApiCall {
}
}
ReadSensors4Partner readSensors4Partner = new ReadSensors4Partner();
String y = (readSensors4Partner.FetchSensor4Box("Germes",token));
SensorReadings sensorReadings = new SensorReadings();
String outputValue = (readSensors4Partner.FetchSensor4Box("Germes",token));
System.out.println(outputValue);
String outputValueFixed=outputValue.replace("[[","[") +outputValue.replace("[{","{")+outputValue.replace("}]","}")+ outputValue.replace("]]","]");
System.out.println(outputValueFixed);
JSONArray jsonArray = new JSONArray(outputValueFixed);
System.out.println(jsonArray.length());
for(int j=0; j<jsonArray.length(); j++) {
JSONObject jsonobject = jsonArray.getJSONObject(j);
String sensorTag = jsonobject.getString("sensortag");
int value = jsonobject.getInt("value");
System.out.println(sensorTag+":"+value);
sensorReadings.setSensorTag(sensorTag);
sensorReadings.setValue(value);
return y;
}
return null;
}
}

View File

@ -1 +1 @@
70B3D57050004223,70B3D570500042D7,70B3D57050004EEF,70B3D57050006223,70B3D5705000623C
70B3D57050004223,70B3D570500042D7,70B3D57050004EF4,70B3D57050006223,70B3D5705000623C

View File

@ -1 +1 @@
70B3D57050004682,70B3D570500046AB,70B3D57050004D14
70B3D57050004682,70B3D57050004D14

View File

@ -1 +1 @@
PlixJiy6sktkQZcj1WJVqLZCR4abCgnNaMlG2DYGZ2ga75aOA00E9jTzBmSC88tw
CyGrh8jKqXXZCBgLzG6gnI6lMWGdzCjGW3LP9sPrH6FEu2M19UcOBF9PZaTJH963

View File

@ -36,8 +36,8 @@ public class BoxCall4Partner {
String baseURL = userCredentials.getBaseURL();
String homeRoot = userCredentials.getHomeRoot();
String outputGeneral = null;
outputGeneral = GeneralCall4All.FetchAll(token);
String outputGeneral = GeneralCall4All.FetchAll(token);
JSONArray jsonarray = new JSONArray(outputGeneral);
cName = readFile.ReadFromFile(homeRoot +cName +".txt");
@ -55,10 +55,13 @@ public class BoxCall4Partner {
String companyOutput = httpCall.HttpGet(baseURL + "devices/" + jsonID + "/sensors" + "?access_token=" + token, token);
listOfCompanyOutputs.add(companyOutput);
writingIntoFile.WriteFile(homeRoot +i+" "+ cName + ".json", companyOutput);
System.out.println(listOfCompanyOutputs);
loopTerminator++;
System.out.println(loopTerminator + " "+arrayOfCompany.length+" "+jsonarray.length()+" "+iterator);
}
if(loopTerminator == arrayOfCompany.length ){
System.out.println("Entered ");
return listOfCompanyOutputs;
}

View File

@ -12,9 +12,6 @@ import java.util.ArrayList;
///url/sensors/id/read
public class ReadSensors4Partner {
public String FetchSensor4Box(String companyName, String token) throws Exception {
switch (companyName) {
@ -40,19 +37,22 @@ public class ReadSensors4Partner {
BoxCall4Partner boxCall4Partner = new BoxCall4Partner();
String outputBox = boxCall4Partner.FetchBox(cName,token);
String outputBoxFixed=outputBox.replace("[[","[") + outputBox.replace("]]","]"); //to make the
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("The working array:"+jsonArray);
ArrayList<String> list=new ArrayList<String>();
int loopTerminator = 0;
char par = '"';
for(int j=0; j<jsonArray.length(); j++){
JSONObject jsonobject = jsonArray.getJSONObject(j);
String jsonID = jsonobject.getString("id");
String jsonTag = jsonobject.getString("tag");
String sensorOutput = httpCall.HttpGet(baseURL + "sensors/" + jsonID + "/read" + "?access_token=" + token, token);
list.add(sensorOutput);
String sensorTag= par+"sensortag"+par+":"+jsonTag+"}]";
String makingList=sensorOutput.replace("}]","") ;
list.add(makingList+","+sensorTag); // This modification of the list is done for the purpse of converting this list to a jsonarray.
writingIntoFile.WriteFile(homeRoot + jsonID + ".json", sensorOutput + jsonTag);
loopTerminator++;
if(loopTerminator == jsonArray.length()){

View File

@ -1,4 +0,0 @@
package JSON_Unpack;
public class Reading4AllSensors {
}

View File

@ -1,6 +1,7 @@
package Knowledgebase;
import org.kie.api.KieServices;
import org.kie.api.KieServices.Factory;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
import org.kie.api.runtime.rule.FactHandle;
@ -17,10 +18,12 @@ public class DroolsTest {
Product product = new Product();
product.setType("gold");
System.out.println(product.getDiscount());
FactHandle fact1;
fact1 = kSession.insert(product);
System.out.println(fact1);
kSession.fireAllRules();
System.out.println("The discount for the jewellery product "

View File

@ -1,31 +0,0 @@
package Knowledgebase;
public class Plants {
private String plantType;
private String sensorTag;
private double outputValue;
public String getPlantType() {
return plantType;
}
public void setPlantType(String plantType) {
this.plantType = plantType;
}
public String getSensorTag() {
return sensorTag;
}
public void setSensorTag(String sensorTag) {
this.sensorTag = sensorTag;
}
public double getOutputValue() {
return outputValue;
}
public void setOutputValue(double outputValue) {
this.outputValue = outputValue;
}
}

View File

@ -0,0 +1,22 @@
package Knowledgebase;
public class SensorReadings {
private String sensorTag;
private double value;
public String getSensorTag() {
return sensorTag;
}
public void setSensorTag(String sensorTag) {
this.sensorTag = sensorTag;
}
public double getValue() {
return value;
}
public void setValue(double value) {
this.value = value;
}
}

View File

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

View File

@ -10,5 +10,5 @@ rule "Offer for Gold"
when
productObject: Product(type=="gold")
then
productObject.setDiscount(25);
productObject.setDiscount(10);
end

View File

@ -1,14 +0,0 @@
import Knowledgebase.Product
rule "Offer for Diamond"
when
productObject: Product(type=="diamond")
then
productObject.setDiscount(15);
end
rule "Offer for Gold"
when
productObject: Product(type=="gold")
then
productObject.setDiscount(25);
end