|
|
@ -8,6 +8,8 @@ import java.io.IOException;
|
|
|
|
import java.net.MalformedURLException;
|
|
|
|
import java.net.MalformedURLException;
|
|
|
|
import java.sql.Connection;
|
|
|
|
import java.sql.Connection;
|
|
|
|
import java.sql.SQLException;
|
|
|
|
import java.sql.SQLException;
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.concurrent.Executors;
|
|
|
|
import java.util.concurrent.Executors;
|
|
|
|
import java.util.concurrent.ScheduledExecutorService;
|
|
|
|
import java.util.concurrent.ScheduledExecutorService;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
@ -41,6 +43,7 @@ public class DataStoreBot {
|
|
|
|
this.storeEntry(entry);
|
|
|
|
this.storeEntry(entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public void storeEntry(JSONObject entry) throws IOException {
|
|
|
|
public void storeEntry(JSONObject entry) throws IOException {
|
|
|
|
|
|
|
|
|
|
|
|
System.out.println("entry => ");
|
|
|
|
System.out.println("entry => ");
|
|
|
|
System.out.println(entry);
|
|
|
|
System.out.println(entry);
|
|
|
|
//get country
|
|
|
|
//get country
|
|
|
@ -50,12 +53,34 @@ public class DataStoreBot {
|
|
|
|
String sensorID = String.valueOf(
|
|
|
|
String sensorID = String.valueOf(
|
|
|
|
((JSONObject) entry.get("sensor")).get("id")
|
|
|
|
((JSONObject) entry.get("sensor")).get("id")
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
int sensorID2 = Integer.parseInt(sensorID);
|
|
|
|
|
|
|
|
|
|
|
|
//get timestamp
|
|
|
|
//get timestamp
|
|
|
|
String timestamp = (String) entry.get("timestamp");
|
|
|
|
String timestamp = (String) entry.get("timestamp");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//get value informations (6)
|
|
|
|
|
|
|
|
JSONArray value_array = (JSONArray) entry.get("sensordatavalues");
|
|
|
|
|
|
|
|
System.out.println("----------------------------");
|
|
|
|
|
|
|
|
Iterator iterator = value_array.iterator();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject firstArr = (JSONObject) iterator.next();
|
|
|
|
|
|
|
|
String value_type_p1 = (String) firstArr.get("value_type");
|
|
|
|
|
|
|
|
int id_p1 = (int) (long) firstArr.get("id");
|
|
|
|
|
|
|
|
float value_p1 = Float.parseFloat((String) firstArr.get("value")) ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject secondArr = (JSONObject) iterator.next();
|
|
|
|
|
|
|
|
String value_type_p2 = (String) secondArr.get("value_type");
|
|
|
|
|
|
|
|
int id_p2 = (int) (long) secondArr.get("id");
|
|
|
|
|
|
|
|
float value_p2 = Float.parseFloat((String) firstArr.get("value")) ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Json to String
|
|
|
|
|
|
|
|
String allJSON = String.valueOf(entry);
|
|
|
|
|
|
|
|
|
|
|
|
String path = this.storePath + country + "-" + sensorID + "-" + timestamp + ".json";
|
|
|
|
String path = this.storePath + country + "-" + sensorID + "-" + timestamp + ".json";
|
|
|
|
path = path.replace(":", "-").replace(" ", "-");
|
|
|
|
path = path.replace(":", "-").replace(" ", "-");
|
|
|
|
this.store.storeJSON(path, entry);
|
|
|
|
this.store.storeJSON(path, entry);
|
|
|
|
|
|
|
|
//System.out.println(country + sensorID2 + timestamp + value_type_p1 + id_p1 + value_p1 + value_type_p2 + id_p2 + value_p2 + allJSON);
|
|
|
|
|
|
|
|
this.db.storeInDB(country, sensorID2, timestamp, value_type_p1, id_p1, value_p1, value_type_p2, id_p2, value_p2, allJSON);
|
|
|
|
|
|
|
|
//String country, int sensorID, String timeStamp, String value_type_p1, int id_p1, float value_p1, String value_type_p2, int id_p2, float value_p2, String allJSON
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|