|
@@ -527,6 +527,7 @@ public class SensorUtil extends TrackUtil {
|
|
|
* @return ResultSet object represents last observation for given unit-sensor pair
|
|
* @return ResultSet object represents last observation for given unit-sensor pair
|
|
|
* @throws SQLException
|
|
* @throws SQLException
|
|
|
*/
|
|
*/
|
|
|
|
|
+ /* !!! REWRITE !!! */
|
|
|
@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"
|
|
@@ -540,11 +541,33 @@ public class SensorUtil extends TrackUtil {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param unitId
|
|
|
|
|
+ * @param sensorId
|
|
|
|
|
+ * @return
|
|
|
|
|
+ * @throws SQLException
|
|
|
|
|
+ */
|
|
|
|
|
+ public List<ObservationValue> getSensorLastObservationNew(long unitId, long sensorId) throws SQLException {
|
|
|
|
|
+ String query = "SELECT last_value, last_obs FROM public.units_to_sensors"
|
|
|
|
|
+ + " WHERE unit_id="+unitId
|
|
|
|
|
+ + " AND sensor_id = "+sensorId+";";
|
|
|
|
|
+ ResultSet res = stmt.executeQuery(query);
|
|
|
|
|
+ List<ObservationValue> obsList = new LinkedList<ObservationValue>();
|
|
|
|
|
+ if(res != null) {
|
|
|
|
|
+ while (res.next()) {
|
|
|
|
|
+ obsList.add(new ObservationValue(res.getDouble("last_value"), res.getString("last_obs")));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return obsList;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
* Method gets list of last observations from all connected sensors for given unit
|
|
* Method gets list of last observations from all connected sensors for given unit
|
|
|
* @param unitId - identifier of unit
|
|
* @param unitId - identifier of unit
|
|
|
* @return list of UnitSensorObservation objects represents last observations from all connected sensors to given unit
|
|
* @return list of UnitSensorObservation objects represents last observations from all connected sensors to given unit
|
|
|
* @throws SQLException
|
|
* @throws SQLException
|
|
|
*/
|
|
*/
|
|
|
|
|
+ /* !!! REWRITE !!! */
|
|
|
@SuppressWarnings("unchecked")
|
|
@SuppressWarnings("unchecked")
|
|
|
public List<UnitSensorObservation> getUnitSensorsLastObservations(long unitId) throws SQLException{
|
|
public List<UnitSensorObservation> getUnitSensorsLastObservations(long unitId) throws SQLException{
|
|
|
String query = "SELECT time_stamp, gid, observed_value, o.sensor_id, o.unit_id"
|
|
String query = "SELECT time_stamp, gid, observed_value, o.sensor_id, o.unit_id"
|
|
@@ -557,12 +580,38 @@ public class SensorUtil extends TrackUtil {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param unitId
|
|
|
|
|
+ * @return
|
|
|
|
|
+ * @throws SQLException
|
|
|
|
|
+ */
|
|
|
|
|
+ public List<UnitSensorObservation> getUnitSensorsLastObservationsNew(long unitId) throws SQLException{
|
|
|
|
|
+ String query = "SELECT unit_id, sensor_id, last_value, last_obs"
|
|
|
|
|
+ + " FROM public.units_to_sensors"
|
|
|
|
|
+ + " WHERE unit_id="+unitId+";";
|
|
|
|
|
+ ResultSet res = stmt.executeQuery(query);
|
|
|
|
|
+ List<UnitSensorObservation> obsList = new LinkedList<UnitSensorObservation>();
|
|
|
|
|
+ if(res != null) {
|
|
|
|
|
+ while (res.next()) {
|
|
|
|
|
+ obsList.add(new UnitSensorObservation(
|
|
|
|
|
+ res.getString("last_obs"),
|
|
|
|
|
+ res.getDouble("last_value"),
|
|
|
|
|
+ res.getLong("sensor_id"),
|
|
|
|
|
+ res.getLong("unit_id")
|
|
|
|
|
+ ));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return obsList;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
* Method gets list of last observations from all connected sensors to all units belonging to given group
|
|
* Method gets list of last observations from all connected sensors to all units belonging to given group
|
|
|
* @param groupName - name of group
|
|
* @param groupName - name of group
|
|
|
* @return list of UnitSensorObservation objects represents last observations from all connected sensors to all units
|
|
* @return list of UnitSensorObservation objects represents last observations from all connected sensors to all units
|
|
|
* belonging to given group
|
|
* belonging to given group
|
|
|
* @throws SQLException
|
|
* @throws SQLException
|
|
|
*/
|
|
*/
|
|
|
|
|
+ /* !!! REWRITE !!! */
|
|
|
@SuppressWarnings("unchecked")
|
|
@SuppressWarnings("unchecked")
|
|
|
public List<UnitSensorObservation> getUnitsSensorsLastObservations(String groupName) throws SQLException{
|
|
public List<UnitSensorObservation> getUnitsSensorsLastObservations(String groupName) throws SQLException{
|
|
|
String query = "SELECT time_stamp, gid, observed_value, o.sensor_id, o.unit_id"
|
|
String query = "SELECT time_stamp, gid, observed_value, o.sensor_id, o.unit_id"
|
|
@@ -579,6 +628,34 @@ public class SensorUtil extends TrackUtil {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param groupName
|
|
|
|
|
+ * @return
|
|
|
|
|
+ * @throws SQLException
|
|
|
|
|
+ */
|
|
|
|
|
+ public List<UnitSensorObservation> getUnitsSensorsLastObservationsNew(String groupName) throws SQLException{
|
|
|
|
|
+ String query = "SELECT unit_id, sensor_id, last_value, last_obs"
|
|
|
|
|
+ + " FROM public.units_to_sensors"
|
|
|
|
|
+ + " WHERE unit_id IN (SELECT unit_id"
|
|
|
|
|
+ + " FROM units_to_groups utg, groups g"
|
|
|
|
|
+ + " WHERE utg.group_id = g.id"
|
|
|
|
|
+ + " AND g.group_name = '"+groupName+"');";
|
|
|
|
|
+
|
|
|
|
|
+ ResultSet res = stmt.executeQuery(query);
|
|
|
|
|
+ List<UnitSensorObservation> obsList = new LinkedList<UnitSensorObservation>();
|
|
|
|
|
+ if(res != null) {
|
|
|
|
|
+ while (res.next()) {
|
|
|
|
|
+ obsList.add(new UnitSensorObservation(
|
|
|
|
|
+ res.getString("last_obs"),
|
|
|
|
|
+ res.getDouble("last_value"),
|
|
|
|
|
+ res.getLong("sensor_id"),
|
|
|
|
|
+ res.getLong("unit_id")
|
|
|
|
|
+ ));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return obsList;
|
|
|
|
|
+ }
|
|
|
|
|
+ /**
|
|
|
* Method gets list of last observations of given connected sensor of all units belonging to given group.
|
|
* Method gets list of last observations of given connected sensor of all units belonging to given group.
|
|
|
* @param groupName - name of group
|
|
* @param groupName - name of group
|
|
|
* @param sensorId - identifier of sensor
|
|
* @param sensorId - identifier of sensor
|
|
@@ -586,6 +663,7 @@ public class SensorUtil extends TrackUtil {
|
|
|
* belonging to given group
|
|
* belonging to given group
|
|
|
* @throws SQLException
|
|
* @throws SQLException
|
|
|
*/
|
|
*/
|
|
|
|
|
+ /* !!! REWRITE !!! */
|
|
|
@SuppressWarnings("unchecked")
|
|
@SuppressWarnings("unchecked")
|
|
|
public List<UnitSensorObservation> getUnitsSensorsLastObservations(String groupName, long sensorId) throws SQLException{
|
|
public List<UnitSensorObservation> getUnitsSensorsLastObservations(String groupName, long sensorId) throws SQLException{
|
|
|
String query = "SELECT time_stamp, gid, observed_value, o.sensor_id, o.unit_id"
|
|
String query = "SELECT time_stamp, gid, observed_value, o.sensor_id, o.unit_id"
|
|
@@ -601,4 +679,35 @@ public class SensorUtil extends TrackUtil {
|
|
|
ResultSet res = stmt.executeQuery(query);
|
|
ResultSet res = stmt.executeQuery(query);
|
|
|
return (List<UnitSensorObservation>) generateObjectList(new UnitSensorObservation(), res);
|
|
return (List<UnitSensorObservation>) generateObjectList(new UnitSensorObservation(), res);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param groupName
|
|
|
|
|
+ * @param sensorId
|
|
|
|
|
+ * @return
|
|
|
|
|
+ * @throws SQLException
|
|
|
|
|
+ */
|
|
|
|
|
+ public List<UnitSensorObservation> getUnitsSensorsLastObservationsNew(String groupName, long sensorId) throws SQLException{
|
|
|
|
|
+ String query = "SELECT unit_id, sensor_id, last_value, last_obs"
|
|
|
|
|
+ + " FROM public.units_to_sensors"
|
|
|
|
|
+ + " WHERE unit_id IN (SELECT unit_id"
|
|
|
|
|
+ + " FROM units_to_groups utg, groups g"
|
|
|
|
|
+ + " WHERE utg.group_id = g.id"
|
|
|
|
|
+ + " AND g.group_name = '"+groupName+"')"
|
|
|
|
|
+ + "AND sensor_id = "+sensorId+";";
|
|
|
|
|
+
|
|
|
|
|
+ ResultSet res = stmt.executeQuery(query);
|
|
|
|
|
+ List<UnitSensorObservation> obsList = new LinkedList<UnitSensorObservation>();
|
|
|
|
|
+ if(res != null) {
|
|
|
|
|
+ while (res.next()) {
|
|
|
|
|
+ obsList.add(new UnitSensorObservation(
|
|
|
|
|
+ res.getString("last_obs"),
|
|
|
|
|
+ res.getDouble("last_value"),
|
|
|
|
|
+ res.getLong("sensor_id"),
|
|
|
|
|
+ res.getLong("unit_id")
|
|
|
|
|
+ ));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return obsList;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|