|
@@ -65,7 +65,7 @@ public class SensorUtil extends TrackUtil {
|
|
|
* @throws SQLException
|
|
* @throws SQLException
|
|
|
*/
|
|
*/
|
|
|
@SuppressWarnings("unchecked")
|
|
@SuppressWarnings("unchecked")
|
|
|
- public List<Sensor> getSensors() throws SQLException {
|
|
|
|
|
|
|
+ public List<Sensor> getSensors() throws SQLException {
|
|
|
String queryObservations = "SELECT * FROM sensors ORDER BY sensors.sensor_id;";
|
|
String queryObservations = "SELECT * FROM sensors ORDER BY sensors.sensor_id;";
|
|
|
ResultSet res = stmt.executeQuery(queryObservations);
|
|
ResultSet res = stmt.executeQuery(queryObservations);
|
|
|
return (List<Sensor>) generateObjectList(new Sensor(), res);
|
|
return (List<Sensor>) generateObjectList(new Sensor(), res);
|
|
@@ -73,19 +73,20 @@ public class SensorUtil extends TrackUtil {
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Method selects list of sensor types stored in DB
|
|
* Method selects list of sensor types stored in DB
|
|
|
- * @return
|
|
|
|
|
|
|
+ * @return List of Sensors with sensor_type and category of sensor_id (pattern YYXXX0000)
|
|
|
* @throws SQLException
|
|
* @throws SQLException
|
|
|
*/
|
|
*/
|
|
|
public List<Sensor> getSensorTypes() throws SQLException{
|
|
public List<Sensor> getSensorTypes() throws SQLException{
|
|
|
- String query = "select distinct(sensor_type) sensor_type from sensors order by sensor_type;";
|
|
|
|
|
- ResultSet res = stmt.executeQuery(query);
|
|
|
|
|
- List<Sensor> senTypeList = new LinkedList<Sensor>();
|
|
|
|
|
- if(res != null) {
|
|
|
|
|
- while(res.next()) {
|
|
|
|
|
- senTypeList.add(new Sensor(res.getString("sensor_type")));
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- return senTypeList;
|
|
|
|
|
|
|
+ String query = "SELECT distinct on(sensor_type) sensor_type, (sensor_id/10000)*10000 as sensor_id"
|
|
|
|
|
+ + " FROM sensors ORDER BY sensor_type;";
|
|
|
|
|
+ ResultSet res = stmt.executeQuery(query);
|
|
|
|
|
+ List<Sensor> senTypeList = new LinkedList<Sensor>();
|
|
|
|
|
+ if(res != null) {
|
|
|
|
|
+ while(res.next()) {
|
|
|
|
|
+ senTypeList.add(new Sensor(res.getLong("sensor_id"), res.getString("sensor_type")));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return senTypeList;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -306,14 +307,14 @@ public class SensorUtil extends TrackUtil {
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Method gets all Phenomenons in DB
|
|
* Method gets all Phenomenons in DB
|
|
|
- * @return
|
|
|
|
|
|
|
+ * @return List of Phenomenon
|
|
|
* @throws SQLException
|
|
* @throws SQLException
|
|
|
*/
|
|
*/
|
|
|
@SuppressWarnings("unchecked")
|
|
@SuppressWarnings("unchecked")
|
|
|
- public List<Phenomenon> getPhenomenons() throws SQLException {
|
|
|
|
|
|
|
+ public List<Phenomenon> getPhenomenons() throws SQLException {
|
|
|
String queryObservations = "SELECT * FROM phenomenons ORDER BY phenomenon_id;";
|
|
String queryObservations = "SELECT * FROM phenomenons ORDER BY phenomenon_id;";
|
|
|
ResultSet res = stmt.executeQuery(queryObservations);
|
|
ResultSet res = stmt.executeQuery(queryObservations);
|
|
|
- if (res.next()) {
|
|
|
|
|
|
|
+ if (res!= null) {
|
|
|
return (List<Phenomenon>) generateObjectList(new Phenomenon(), res);
|
|
return (List<Phenomenon>) generateObjectList(new Phenomenon(), res);
|
|
|
} else
|
|
} else
|
|
|
return null;
|
|
return null;
|
|
@@ -528,7 +529,7 @@ public class SensorUtil extends TrackUtil {
|
|
|
* @throws SQLException
|
|
* @throws SQLException
|
|
|
*/
|
|
*/
|
|
|
@SuppressWarnings("unchecked")
|
|
@SuppressWarnings("unchecked")
|
|
|
- public List<ObservationValue> getSensorLastObservation(long unitId, long sensorId) throws SQLException {
|
|
|
|
|
|
|
+ public List<ObservationValue> getSensorLastObservation(long unitId, long sensorId) throws SQLException {
|
|
|
String query = "SELECT time_stamp, gid, observed_value"
|
|
String query = "SELECT time_stamp, gid, observed_value"
|
|
|
+ " FROM units_to_sensors uts"
|
|
+ " FROM units_to_sensors uts"
|
|
|
+ " LEFT JOIN observations o ON uts.last_obs = o.time_stamp"
|
|
+ " LEFT JOIN observations o ON uts.last_obs = o.time_stamp"
|