|
|
@@ -733,7 +733,6 @@ public class MapLogRepository implements SensLogRepository {
|
|
|
public Future<List<UnitTelemetry>> findObservationsByEventId(
|
|
|
long eventId, OffsetDateTime from, OffsetDateTime to, ZoneId zone, int offset, int limit
|
|
|
) {
|
|
|
-
|
|
|
String whereTimestampClause;
|
|
|
Tuple tupleParams;
|
|
|
if (from != null && to != null) {
|
|
|
@@ -877,14 +876,14 @@ public class MapLogRepository implements SensLogRepository {
|
|
|
}
|
|
|
|
|
|
String sql = "SELECT tel.unit_id, tel.time_stamp, $5 AS zone_id, " + // ::timestamp with time zone at time zone $5 AS time_stamp
|
|
|
- "ST_X (ST_Transform (tel.the_geom, 4326)) AS long, " +
|
|
|
- "ST_Y (ST_Transform (tel.the_geom, 4326)) AS lat, " +
|
|
|
- "ST_Z (ST_Transform (tel.the_geom, 4326)) AS alt " +
|
|
|
- "FROM maplog.obs_telemetry AS tel " +
|
|
|
- "JOIN maplog.unit u on u.unit_id = tel.unit_id " +
|
|
|
- "JOIN maplog.unit_to_campaign utc on tel.unit_id = utc.unit_id " +
|
|
|
- "WHERE utc.camp_id = $1 AND utc.unit_id = $2 AND " + whereTimestampClause + " " +
|
|
|
- "ORDER BY tel.time_stamp OFFSET $3 LIMIT $4;";
|
|
|
+ "ST_X (ST_Transform (tel.the_geom, 4326)) AS long, " +
|
|
|
+ "ST_Y (ST_Transform (tel.the_geom, 4326)) AS lat, " +
|
|
|
+ "ST_Z (ST_Transform (tel.the_geom, 4326)) AS alt " +
|
|
|
+ "FROM maplog.obs_telemetry AS tel " +
|
|
|
+ "JOIN maplog.unit u on u.unit_id = tel.unit_id " +
|
|
|
+ "JOIN maplog.unit_to_campaign utc on tel.unit_id = utc.unit_id " +
|
|
|
+ "WHERE utc.camp_id = $1 AND utc.unit_id = $2 AND " + whereTimestampClause + " " +
|
|
|
+ "ORDER BY tel.time_stamp OFFSET $3 LIMIT $4;";
|
|
|
|
|
|
return client.preparedQuery(sql)
|
|
|
.execute(tupleParams)
|
|
|
@@ -917,6 +916,65 @@ public class MapLogRepository implements SensLogRepository {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public Future<List<UnitLocation>> findLocationsByEventId(
|
|
|
+ long eventId, OffsetDateTime from, OffsetDateTime to, ZoneId zone, int offset, int limit
|
|
|
+ ) {
|
|
|
+ String whereTimestampClause;
|
|
|
+ Tuple tupleParams;
|
|
|
+ if (from != null && to != null) {
|
|
|
+ whereTimestampClause = "tel.time_stamp >= (CASE WHEN $5 < dta.from_time THEN $5 ELSE dta.from_time END) AND tel.time_stamp <= (CASE WHEN dta.to_time IS NULL OR $6 < dta.to_time THEN $6 ELSE dta.to_time END)";
|
|
|
+ tupleParams = Tuple.of(eventId, offset, limit, zone.getId(), from, to);
|
|
|
+ } else if (from != null) {
|
|
|
+ whereTimestampClause = "tel.time_stamp >= (CASE WHEN $5 < dta.from_time THEN $5 ELSE dta.from_time END) AND tel.time_stamp <= (CASE WHEN dta.to_time IS NULL THEN now() ELSE dta.to_time END)";
|
|
|
+ tupleParams = Tuple.of(eventId, offset, limit, zone.getId(), from);
|
|
|
+ } else if (to != null) {
|
|
|
+ whereTimestampClause = "tel.time_stamp >= dta.from_time AND tel.time_stamp <= (CASE WHEN dta.to_time IS NULL OR $5 < dta.to_time THEN $5 ELSE dta.to_time END)";
|
|
|
+ tupleParams = Tuple.of(eventId, offset, limit, zone.getId(), to);
|
|
|
+ } else {
|
|
|
+ whereTimestampClause = "tel.time_stamp >= dta.from_time AND tel.time_stamp <= (CASE WHEN dta.to_time IS NULL THEN now() ELSE dta.to_time END)";
|
|
|
+ tupleParams = Tuple.of(eventId, offset, limit, zone.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ String sql = "SELECT tel.unit_id, tel.time_stamp, $4 AS zone_id, " + // ::timestamp with time zone at time zone $4 AS time_stamp
|
|
|
+ "ST_X (ST_Transform (tel.the_geom, 4326)) AS long, " +
|
|
|
+ "ST_Y (ST_Transform (tel.the_geom, 4326)) AS lat, " +
|
|
|
+ "ST_Z (ST_Transform (tel.the_geom, 4326)) AS alt " +
|
|
|
+ "FROM maplog.obs_telemetry AS tel " +
|
|
|
+ "JOIN maplog.driver_to_action dta on tel.unit_id = dta.unit_id " +
|
|
|
+ "WHERE dta.id = $1 AND " + whereTimestampClause + " " +
|
|
|
+ "ORDER BY tel.time_stamp OFFSET $2 LIMIT $3";
|
|
|
+
|
|
|
+ return client.preparedQuery(sql)
|
|
|
+ .execute(tupleParams)
|
|
|
+ .map(rs -> StreamSupport.stream(rs.spliterator(), false)
|
|
|
+ .map(r -> UnitLocation.of(
|
|
|
+ r.getLong("unit_id"),
|
|
|
+ r.getOffsetDateTime("time_stamp"),
|
|
|
+ Location.of(
|
|
|
+ r.getFloat("long"),
|
|
|
+ r.getFloat("lat"),
|
|
|
+ r.getFloat("alt")
|
|
|
+ )
|
|
|
+ ))
|
|
|
+ .collect(Collectors.toList()))
|
|
|
+ .onFailure(logger::catching);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Future<PagingRetrieve<List<UnitLocation>>> findLocationsByEventIdWithPaging(
|
|
|
+ long eventId, OffsetDateTime from, OffsetDateTime to, ZoneId zone, int offset, int limit
|
|
|
+ ) {
|
|
|
+ return findLocationsByEventId(eventId, from, to, zone, offset, limit+1)
|
|
|
+ .map(data -> {
|
|
|
+ boolean hasNext = data.size() > limit;
|
|
|
+ if (hasNext) {
|
|
|
+ data.remove(data.size() - 1);
|
|
|
+ }
|
|
|
+ return new PagingRetrieve<>(hasNext, data.size(), data);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public Future<List<UnitLocation>> findUnitsLocationsByCampaignId(
|
|
|
long campaignId, int limitPerUnit, OffsetDateTime from, OffsetDateTime to, ZoneId zone, SortType sort
|
|
|
) {
|