Explorar el Código

Fixed bugs in endpoints.

Lukas Cerny hace 1 año
padre
commit
3c3248868a

+ 3 - 3
init.sql

@@ -50,8 +50,8 @@ CREATE TABLE maplog.campaign (
     name TEXT NOT NULL,
     description TEXT NOT NULL,
     from_time TIMESTAMP WITH TIME ZONE NOT NULL,
-    to_time TIMESTAMP WITH TIME ZONE NOT NULL,
-    CONSTRAINT campaign_check_time CHECK (from_time < to_time)
+    to_time TIMESTAMP WITH TIME ZONE
+--     CONSTRAINT campaign_check_time CHECK (from_time < to_time)
 );
 ALTER TABLE maplog.campaign OWNER TO senslog;
 
@@ -196,7 +196,7 @@ CREATE TABLE maplog.unit_to_campaign (
     campaign_id INTEGER NOT NULL,
     unit_id BIGINT NOT NULL,
     from_time TIMESTAMP WITH TIME ZONE NOT NULL,
-    to_time TIMESTAMP WITH TIME ZONE NOT NULL
+    to_time TIMESTAMP WITH TIME ZONE
 );
 ALTER TABLE maplog.unit_to_campaign OWNER TO senslog;
 

+ 4 - 4
src/main/java/cz/senslog/telemetry/database/domain/SensorTelemetry.java

@@ -5,16 +5,16 @@ import java.time.OffsetDateTime;
 public class SensorTelemetry {
 
     private final long id;
-    private final long value;
+    private final double value;
     private final OffsetDateTime timestamp;
     private final Location location;
     private final int speed;
 
-    public static SensorTelemetry of(long id, long value, OffsetDateTime timestamp, Location location, int speed) {
+    public static SensorTelemetry of(long id, double value, OffsetDateTime timestamp, Location location, int speed) {
         return new SensorTelemetry(id, value, timestamp, location, speed);
     }
 
-    public SensorTelemetry(long id, long value, OffsetDateTime timestamp, Location location, int speed) {
+    public SensorTelemetry(long id, double value, OffsetDateTime timestamp, Location location, int speed) {
         this.id = id;
         this.value = value;
         this.timestamp = timestamp;
@@ -38,7 +38,7 @@ public class SensorTelemetry {
         return speed;
     }
 
-    public long getValue() {
+    public double getValue() {
         return value;
     }
 }

+ 21 - 21
src/main/java/cz/senslog/telemetry/database/repository/MapLogRepository.java

@@ -168,8 +168,8 @@ public class MapLogRepository implements SensLogRepository {
                 .map(rs -> StreamSupport.stream(rs.spliterator(), false)
                         .map((row) -> Unit.of(
                                 row.getLong("unit_id"),
-                                row.getString("imei"),
                                 row.getString("name"),
+                                row.getString("imei"),
                                 row.getString("description")
                         ))
                         .collect(toList())
@@ -319,7 +319,7 @@ public class MapLogRepository implements SensLogRepository {
         return client.preparedQuery("SELECT s.sensor_id, s.name, s.type " +
                         "FROM maplog.unit_to_sensor AS uts " +
                         "JOIN maplog.sensor s on s.sensor_id = uts.sensor_id " +
-                        "WHERE uts.unit_id = $1 AND s.io_id != 0 ORDER BY s.sensor_id")
+                        "WHERE uts.unit_id = $1 ORDER BY s.sensor_id")
                 .execute(Tuple.of(unitId))
                 .map(rs -> StreamSupport.stream(rs.spliterator(), false)
                         .map((row) -> Sensor.of(
@@ -1310,7 +1310,7 @@ public class MapLogRepository implements SensLogRepository {
                 case SENSOR -> {
                     switch (filter.getAttribute()) {
                         case ID          -> of(tupleParams.addLong(filter.getAttributeValueAsLong()).addFloat(optValue))
-                                .map(p -> format(" AND (tel.observed_values::jsonb ->> $%d::bigint::text::varchar)::integer %s $%d", p.size()-1, opt, p.size()))
+                                .map(p -> format(" AND (tel.observed_values::jsonb ->> $%d::bigint::text::varchar)::double precision %s $%d", p.size()-1, opt, p.size()))
                                 .ifPresent(whereFiltersClause::append);
                     }
                 }
@@ -1390,7 +1390,7 @@ public class MapLogRepository implements SensLogRepository {
                 case SENSOR -> {
                     switch (filter.getAttribute()) {
                         case ID          -> of(tupleParams.addLong(filter.getAttributeValueAsLong()).addFloat(optValue))
-                                .map(p -> format(" AND (tel.observed_values::jsonb ->> $%d::bigint::text::varchar)::integer %s $%d", p.size()-1, opt, p.size()))
+                                .map(p -> format(" AND (tel.observed_values::jsonb ->> $%d::bigint::text::varchar)::double precision %s $%d", p.size()-1, opt, p.size()))
                                 .ifPresent(whereFiltersClause::append);
                     }
                 }
@@ -1444,7 +1444,7 @@ public class MapLogRepository implements SensLogRepository {
         String whereTimestampClause;
         Tuple tupleParams;
         if (from != null && to != null) {
-            whereTimestampClause = "tel.time_stamp <= (CASE WHEN $5 > utc.to_time THEN utc.to_time ELSE $5 END) AND tel.time_stamp >= (CASE WHEN $6 > utc.from_time THEN utc.from_time ELSE $6 END)";
+            whereTimestampClause = "tel.time_stamp >= (CASE WHEN $5 > utc.from_time THEN utc.from_time ELSE $5 END) AND tel.time_stamp <= (CASE WHEN $6 > utc.to_time THEN utc.to_time ELSE $6 END)";
             tupleParams = Tuple.of(campaignId, unitId, offset, limit, from, to);
         } else if (from != null) {
             whereTimestampClause = "tel.time_stamp >= (CASE WHEN $5 > utc.from_time THEN utc.from_time ELSE $5 END) AND tel.time_stamp <= utc.to_time";
@@ -1473,7 +1473,7 @@ public class MapLogRepository implements SensLogRepository {
                 case SENSOR -> {
                     switch (filter.getAttribute()) {
                         case ID          -> of(tupleParams.addLong(filter.getAttributeValueAsLong()).addFloat(optValue))
-                                .map(p -> format(" AND (tel.observed_values::jsonb ->> $%d::bigint::text::varchar)::integer %s $%d", p.size()-1, opt, p.size()))
+                                .map(p -> format(" AND (tel.observed_values::jsonb ->> $%d::bigint::text::varchar)::double precision %s $%d", p.size()-1, opt, p.size()))
                                 .ifPresent(whereFiltersClause::append);
                     }
                 }
@@ -1551,7 +1551,7 @@ public class MapLogRepository implements SensLogRepository {
                 case SENSOR -> {
                     switch (filter.getAttribute()) {
                         case ID          -> of(tupleParams.addLong(filter.getAttributeValueAsLong()).addFloat(optValue))
-                                .map(p -> format(" AND (tel.observed_values::jsonb ->> $%d::bigint::text::varchar)::integer %s $%d", p.size()-1, opt, p.size()))
+                                .map(p -> format(" AND (tel.observed_values::jsonb ->> $%d::bigint::text::varchar)::double precision %s $%d", p.size()-1, opt, p.size()))
                                 .ifPresent(whereFiltersClause::append);
                     }
                 }
@@ -1632,7 +1632,7 @@ public class MapLogRepository implements SensLogRepository {
                 case SENSOR -> {
                     switch (filter.getAttribute()) {
                         case ID          -> of(tupleParams.addLong(filter.getAttributeValueAsLong()).addFloat(optValue))
-                                .map(p -> format(" AND (tel.observed_values::jsonb ->> $%d::bigint::text::varchar)::integer %s $%d", p.size()-1, opt, p.size()))
+                                .map(p -> format(" AND (tel.observed_values::jsonb ->> $%d::bigint::text::varchar)::double precision %s $%d", p.size()-1, opt, p.size()))
                                 .ifPresent(whereFiltersClause::append);
                     }
                 }
@@ -1711,7 +1711,7 @@ public class MapLogRepository implements SensLogRepository {
                 case SENSOR -> {
                     switch (filter.getAttribute()) {
                         case ID          -> of(tupleParams.addLong(filter.getAttributeValueAsLong()).addFloat(optValue))
-                                .map(p -> format(" AND (tel.observed_values::jsonb ->> $%d::bigint::text::varchar)::integer %s $%d", p.size()-1, opt, p.size()))
+                                .map(p -> format(" AND (tel.observed_values::jsonb ->> $%d::bigint::text::varchar)::double precision %s $%d", p.size()-1, opt, p.size()))
                                 .ifPresent(whereFiltersClause::append);
                     }
                 }
@@ -1793,14 +1793,14 @@ public class MapLogRepository implements SensLogRepository {
                 case SENSOR -> {
                     switch (filter.getAttribute()) {
                         case ID          -> of(tupleParams.addLong(filter.getAttributeValueAsLong()).addFloat(optValue))
-                                .map(p -> format(" AND (tel.observed_values::jsonb ->> $%d::bigint::text::varchar)::integer %s $%d", p.size()-1, opt, p.size()))
+                                .map(p -> format(" AND (tel.observed_values::jsonb ->> $%d::bigint::text::varchar)::double precision %s $%d", p.size()-1, opt, p.size()))
                                 .ifPresent(whereFiltersClause::append);
                     }
                 }
             }
         }
 
-        String sql = "SELECT tel.id, (tel.observed_values::jsonb ->> $3::bigint::text::varchar)::integer AS value, tel.speed, tel.time_stamp, " +
+        String sql = "SELECT tel.id, (tel.observed_values::jsonb ->> $3::bigint::text::varchar)::double precision AS value, tel.speed, tel.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, " +
@@ -1816,7 +1816,7 @@ public class MapLogRepository implements SensLogRepository {
                 .map(rs -> StreamSupport.stream(rs.spliterator(), false)
                         .map(r -> SensorTelemetry.of(
                                 r.getLong("id"),
-                                r.getLong("value"),
+                                r.getDouble("value"),
                                 r.getOffsetDateTime("time_stamp"),
                                 Location.of(
                                         r.getFloat("long"),
@@ -1864,14 +1864,14 @@ public class MapLogRepository implements SensLogRepository {
                 case SENSOR -> {
                     switch (filter.getAttribute()) {
                         case ID          -> of(tupleParams.addLong(filter.getAttributeValueAsLong()).addFloat(optValue))
-                                .map(p -> format(" AND (tel.observed_values::jsonb ->> $%d::bigint::text::varchar)::integer %s $%d", p.size()-1, opt, p.size()))
+                                .map(p -> format(" AND (tel.observed_values::jsonb ->> $%d::bigint::text::varchar)::double precision %s $%d", p.size()-1, opt, p.size()))
                                 .ifPresent(whereFiltersClause::append);
                     }
                 }
             }
         }
 
-        String sql = "SELECT tel.id, (tel.observed_values::jsonb ->> $3::bigint::text::varchar)::integer AS value, tel.speed, tel.time_stamp, " +
+        String sql = "SELECT tel.id, (tel.observed_values::jsonb ->> $3::bigint::text::varchar)::double precision AS value, tel.speed, tel.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, " +
@@ -1891,7 +1891,7 @@ public class MapLogRepository implements SensLogRepository {
                 .map(rs -> StreamSupport.stream(rs.spliterator(), false)
                         .map(r -> SensorTelemetry.of(
                                 r.getLong("id"),
-                                r.getLong("value"),
+                                r.getDouble("value"),
                                 r.getOffsetDateTime("time_stamp"),
                                 Location.of(
                                         r.getFloat("long"),
@@ -1939,7 +1939,7 @@ public class MapLogRepository implements SensLogRepository {
                 case SENSOR -> {
                        switch (filter.getAttribute()) {
                             case ID          -> of(tupleParams.addLong(filter.getAttributeValueAsLong()).addFloat(optValue))
-                                    .map(p -> format(" AND (tel.observed_values::jsonb ->> $%d::bigint::text::varchar)::integer %s $%d", p.size()-1, opt, p.size()))
+                                    .map(p -> format(" AND (tel.observed_values::jsonb ->> $%d::bigint::text::varchar)::double precision %s $%d", p.size()-1, opt, p.size()))
                                     .ifPresent(whereFiltersClause::append);
                     }
                 }
@@ -2008,7 +2008,7 @@ public class MapLogRepository implements SensLogRepository {
                 case SENSOR -> {
                     switch (filter.getAttribute()) {
                         case ID          -> of(tupleParams.addLong(filter.getAttributeValueAsLong()).addFloat(optValue))
-                                .map(p -> format(" AND (tel.observed_values::jsonb ->> $%d::bigint::text::varchar)::integer %s $%d", p.size()-1, opt, p.size()))
+                                .map(p -> format(" AND (tel.observed_values::jsonb ->> $%d::bigint::text::varchar)::double precision %s $%d", p.size()-1, opt, p.size()))
                                 .ifPresent(whereFiltersClause::append);
                     }
                 }
@@ -2080,7 +2080,7 @@ public class MapLogRepository implements SensLogRepository {
                 case SENSOR -> {
                     switch (filter.getAttribute()) {
                         case ID          -> of(tupleParams.addLong(filter.getAttributeValueAsLong()).addFloat(optValue))
-                                .map(p -> format(" AND (tel.observed_values::jsonb ->> $%d::bigint::text::varchar)::integer %s $%d", p.size()-1, opt, p.size()))
+                                .map(p -> format(" AND (tel.observed_values::jsonb ->> $%d::bigint::text::varchar)::double precision %s $%d", p.size()-1, opt, p.size()))
                                 .ifPresent(whereFiltersClause::append);
                     }
                 }
@@ -2148,7 +2148,7 @@ public class MapLogRepository implements SensLogRepository {
                 case SENSOR -> {
                     switch (filter.getAttribute()) {
                         case ID          -> of(tupleParams.addLong(filter.getAttributeValueAsLong()).addFloat(optValue))
-                                .map(p -> format(" AND (tel.observed_values::jsonb ->> $%d::bigint::text::varchar)::integer %s $%d", p.size()-1, opt, p.size()))
+                                .map(p -> format(" AND (tel.observed_values::jsonb ->> $%d::bigint::text::varchar)::double precision %s $%d", p.size()-1, opt, p.size()))
                                 .ifPresent(whereFiltersClause::append);
                     }
                 }
@@ -2218,7 +2218,7 @@ public class MapLogRepository implements SensLogRepository {
                 case SENSOR -> {
                     switch (filter.getAttribute()) {
                         case ID          -> of(tupleParams.addLong(filter.getAttributeValueAsLong()).addFloat(optValue))
-                                .map(p -> format(" AND (observed_values::jsonb ->> $%d::bigint::text::varchar)::integer %s $%d", p.size()-1, opt, p.size()))
+                                .map(p -> format(" AND (observed_values::jsonb ->> $%d::bigint::text::varchar)::double precision %s $%d", p.size()-1, opt, p.size()))
                                 .ifPresent(whereFiltersClause::append);
                     }
                 }
@@ -2285,7 +2285,7 @@ public class MapLogRepository implements SensLogRepository {
                 case SENSOR -> {
                     switch (filter.getAttribute()) {
                         case ID          -> of(tupleParams.addLong(filter.getAttributeValueAsLong()).addFloat(optValue))
-                                .map(p -> format(" AND (observed_values::jsonb ->> $%d::bigint::text::varchar)::integer %s $%d", p.size()-1, opt, p.size()))
+                                .map(p -> format(" AND (observed_values::jsonb ->> $%d::bigint::text::varchar)::double precision %s $%d", p.size()-1, opt, p.size()))
                                 .ifPresent(whereFiltersClause::append);
                     }
                 }