Skip to content
Snippets Groups Projects
Commit f1c5100d authored by gwen-soleil's avatar gwen-soleil
Browse files

add support for LTTB downsampling on timescale.

parent 33e0baff
No related branches found
No related tags found
No related merge requests found
......@@ -111,4 +111,9 @@ public class MySqArchivingAttributeFetcher implements IArchivingAttributeFetcher
//TODO
return null;
}
@Override
public AttributeValueSeries getWithSamplingLttb(final String attributeName, final int nbPoints, final Timestamp startTime, final Timestamp endTime) {
throw new TangoTimeseriesException("LTTB sampling method not supported for MySQL");
}
}
......@@ -167,5 +167,20 @@ public class ArchivingAttributeFetcher implements IArchivingAttributeFetcher {
);
}
@Override
public AttributeValueSeries getWithSamplingLttb(String attributeName, int nbPoints, Timestamp startTime, Timestamp endTime) {
AttributeConfig attributeConfigDB = config.getAttribute(attributeName);
if (attributeConfigDB == null) {
throw new TangoTimeseriesException(attributeName + " has never been stored");
}
final AttributeValueSeries buckets = jdbi.withExtension(AttributeQueries.class, dao ->
AttributeValueSeriesMapper.getAttributeValueSeries(attributeConfigDB,
dao.selectWithSamplingLttb(attributeConfigDB.getTableName(),
attributeConfigDB.getId(), nbPoints, startTime, endTime))
);
logger.debug("got {} values", buckets.getAttributeValues().size());
return buckets;
}
}
......@@ -46,9 +46,6 @@ import java.util.List;
public interface AttributeQueries {
@SqlQuery("select distinct(att_conf_id) from <tableName> order by att_conf_id")
List<Integer> listID(@Define("tableName") String tableName);
// select data_time, value_r, value_w, details from att_scalar_devdouble where att_scalar_devdouble.att_conf_id = 1 and data_time > '2021-01-09 12:01:12.188'
@SqlQuery("select att_conf_id, data_time, value_r, value_w, quality, details from <tableName>" +
" where att_conf_id = :attConfID and data_time > :dataTime order by data_time")
......@@ -138,8 +135,17 @@ public interface AttributeQueries {
@Define("tableName") String tableName, @Define("aggregateFunction") String aggregateFunction,
@Bind("attConfID") int attributeID, @Bind("startTime") Timestamp startTime, @Bind("endTime") Timestamp endTime);
// TODO
@SqlQuery("SELECT time as data_time, value as value_r FROM unnest(" +
"(select lttb(data_time, value_r, :nbPoint)FROM <tableName> " +
"where data_time >:startTime and data_time < :endTime and att_conf_id = :attConfID)) ORDER BY 1")
@RegisterFieldMapper(AttributeEventScalarTable.class)
List<AttributeEventScalarTable> selectWithSamplingLttb(@Define("tableName") String tableName, @Bind("attConfID") int attConfID, @Bind("nbPoint") int nbPoint,
@Bind("startTime") Timestamp startTime, @Bind("endTime") Timestamp endTime);
// TODO
// select data_time,value_r[1:4] from att_array_devfloat where data_time between '2022-12-05 08:03:14.646 +01002' and '2022-12-06 08:03:14.646 +01002';
// selectSubArrayBetween
}
......@@ -48,4 +48,6 @@ public interface IArchivingAttributeFetcher {
AttributeValue getClosestValue(String attributeName, Timestamp timestamp, boolean withError);
AttributeValue getAggregateValue(String attributeName, String aggregateFunction, Timestamp from, Timestamp to);
AttributeValueSeries getWithSamplingLttb(String attributeName, int nbPoints, Timestamp startTime, Timestamp endTime);
}
......@@ -135,6 +135,18 @@ public class TangoArchivingFetcherServiceTest {
}
@Test
public void selectWithSamplingLttb() {
final AttributeValueSeries result = fetcherService.getWithSamplingLttb("a/b/c/sin",
17, Timestamp.valueOf("2020-01-10 01:00:00.000"), Timestamp.valueOf("2020-04-21 00:00:00"));
System.out.println(result);
assertEquals(17, result.getAttributeValues().size());
assertEquals(12.7015115293407, result.getAttributeValues().get(0).getValueR());
assertEquals(Timestamp.valueOf("2020-01-11 01:00:00.000"), result.getAttributeValues().get(0).getDataTime());
assertEquals(10.022128489940254, result.getAttributeValues().get(16).getValueR());
assertEquals(Timestamp.valueOf("2020-04-20 02:00:00.0"), result.getAttributeValues().get(16).getDataTime());
}
@Test
public void getAttributeParameters() {
final Optional<AttributeParameters> params = fetcherService.getAttributeParameters("BOO-C02/RP/CIG.038/ushort");
......
......@@ -33,3 +33,14 @@ VALUES(2, 'archiving/tdbarchiver/038', '2011-02-10 08:05:41.000', NULL, true, 60
INSERT INTO contexts (context_id, name, description, is_active)
VALUES(nextval('contexts_context_id_seq'), 'Technical shutdown', 'attributes paused during shutdowns', false);
insert into att_conf values (nextval('att_conf_att_conf_id_seq'), 'a/b/c/sin', 5, 1, 1, 'att_scalar_devdouble', 'cs_name', 'a', 'b', 'c', 'sin', 0,false);
SET TIME ZONE 'UTC';
INSERT INTO att_scalar_devdouble(att_conf_id,data_time, value_r)
SELECT
8,
'2020-01-01 UTC'::TIMESTAMPTZ + make_interval(days=>(foo*10)::int) as data_time,
10 + 5 * cos(foo) as value_r
FROM generate_series(1,11,0.1) foo
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment