Image aggregation.
This commit is contained in:
@ -60,8 +60,10 @@ public class QueryValidator implements Validator {
|
||||
long pulsesPerBin = query.getAggregation().getPulsesPerBin();
|
||||
int nrOfBins = query.getAggregation().getNrOfBins();
|
||||
if ((durationPerBin != Request.NOT_SET && (pulsesPerBin != Request.NOT_SET || nrOfBins != Request.NOT_SET))
|
||||
|| (pulsesPerBin != Request.NOT_SET && (durationPerBin != Request.NOT_SET || nrOfBins != Request.NOT_SET))
|
||||
|| (nrOfBins != Request.NOT_SET && (durationPerBin != Request.NOT_SET || pulsesPerBin != Request.NOT_SET))) {
|
||||
|| (pulsesPerBin != Request.NOT_SET
|
||||
&& (durationPerBin != Request.NOT_SET || nrOfBins != Request.NOT_SET))
|
||||
|| (nrOfBins != Request.NOT_SET
|
||||
&& (durationPerBin != Request.NOT_SET || pulsesPerBin != Request.NOT_SET))) {
|
||||
errors.reject("durationPerBin", "Only one binning element must be defined.");
|
||||
errors.reject("pulsesPerBin", "Only one binning element must be defined.");
|
||||
errors.reject("nrOfBins", "Only one binning element must be defined.");
|
||||
@ -88,7 +90,7 @@ public class QueryValidator implements Validator {
|
||||
// }
|
||||
}
|
||||
|
||||
if (query.getValueTransformation() != null) {
|
||||
if (query.getValueTransformations() != null && !query.getValueTransformations().isEmpty()) {
|
||||
// without this field, json will not contain transformedValue
|
||||
query.addField(QueryField.transformedValue);
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package ch.psi.daq.test.queryrest.controller;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.awt.Color;
|
||||
@ -45,6 +46,7 @@ import ch.psi.daq.domain.query.transform.image.ImageEncodingValueTransformation;
|
||||
import ch.psi.daq.domain.query.transform.image.ImageDownScaleValueTransformation;
|
||||
import ch.psi.daq.domain.query.transform.image.ImageFormat;
|
||||
import ch.psi.daq.domain.query.transform.image.encoding.Base64ImageEncoder;
|
||||
import ch.psi.daq.domain.query.transform.sampling.ValueSamplerValueTransformation;
|
||||
import ch.psi.daq.domain.request.range.RequestRangeDate;
|
||||
import ch.psi.daq.domain.request.range.RequestRangePulseId;
|
||||
import ch.psi.daq.domain.request.range.RequestRangeTime;
|
||||
@ -619,8 +621,7 @@ public class JsonQueryRestControllerTableTest extends AbstractDaqRestTest {
|
||||
MockMvcRequestBuilders
|
||||
.post(DomainConfig.PATH_QUERY)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(content)
|
||||
)
|
||||
.content(content))
|
||||
.andDo(MockMvcResultHandlers.print())
|
||||
.andExpect(MockMvcResultMatchers.status().isOk())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.data").isArray())
|
||||
@ -725,8 +726,7 @@ public class JsonQueryRestControllerTableTest extends AbstractDaqRestTest {
|
||||
MockMvcRequestBuilders
|
||||
.post(DomainConfig.PATH_QUERY)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(content)
|
||||
)
|
||||
.content(content))
|
||||
.andDo(MockMvcResultHandlers.print())
|
||||
.andExpect(MockMvcResultMatchers.status().isOk())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.data").isArray())
|
||||
@ -807,8 +807,7 @@ public class JsonQueryRestControllerTableTest extends AbstractDaqRestTest {
|
||||
MockMvcRequestBuilders
|
||||
.post(DomainConfig.PATH_QUERY)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(content)
|
||||
)
|
||||
.content(content))
|
||||
.andDo(MockMvcResultHandlers.print())
|
||||
.andExpect(MockMvcResultMatchers.status().isOk())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.data").isArray())
|
||||
@ -925,8 +924,7 @@ public class JsonQueryRestControllerTableTest extends AbstractDaqRestTest {
|
||||
MockMvcRequestBuilders
|
||||
.post(DomainConfig.PATH_QUERY)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(content)
|
||||
)
|
||||
.content(content))
|
||||
.andDo(MockMvcResultHandlers.print())
|
||||
.andExpect(MockMvcResultMatchers.status().isOk())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.data").isArray())
|
||||
@ -1217,8 +1215,7 @@ public class JsonQueryRestControllerTableTest extends AbstractDaqRestTest {
|
||||
MockMvcRequestBuilders
|
||||
.post(DomainConfig.PATH_QUERY)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(content)
|
||||
)
|
||||
.content(content))
|
||||
.andDo(MockMvcResultHandlers.print())
|
||||
.andExpect(MockMvcResultMatchers.status().isOk())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.data").isArray())
|
||||
@ -1312,8 +1309,7 @@ public class JsonQueryRestControllerTableTest extends AbstractDaqRestTest {
|
||||
MockMvcRequestBuilders
|
||||
.post(DomainConfig.PATH_QUERY)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(content)
|
||||
)
|
||||
.content(content))
|
||||
.andDo(MockMvcResultHandlers.print())
|
||||
.andExpect(MockMvcResultMatchers.status().isOk())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.data").isArray())
|
||||
@ -2224,8 +2220,9 @@ public class JsonQueryRestControllerTableTest extends AbstractDaqRestTest {
|
||||
request.addField(QueryField.iocSeconds);
|
||||
request.addField(QueryField.iocMillis);
|
||||
request.setMapping(new Mapping());
|
||||
request.setValueTransformation(
|
||||
request.addValueTransformation(
|
||||
new ValueTransformationSequence(
|
||||
ValueTransformationSequence.ALL_CHANNELS,
|
||||
new ImageDownScaleValueTransformation(8, Color.BLUE, Color.RED),
|
||||
new ImageEncodingValueTransformation(
|
||||
ImageFormat.PNG,
|
||||
@ -2251,4 +2248,105 @@ public class JsonQueryRestControllerTableTest extends AbstractDaqRestTest {
|
||||
image = JsonPath.read(document, "$.data[1][0].transformedValue");
|
||||
assertTrue(image.startsWith(imageScheme));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValueTransformation_02() throws Exception {
|
||||
String channelName = "TestImage";
|
||||
DAQQuery request = new DAQQuery(
|
||||
new RequestRangePulseId(
|
||||
100,
|
||||
101),
|
||||
channelName);
|
||||
request.addField(QueryField.pulseId);
|
||||
request.addField(QueryField.globalSeconds);
|
||||
request.addField(QueryField.globalMillis);
|
||||
request.addField(QueryField.iocSeconds);
|
||||
request.addField(QueryField.iocMillis);
|
||||
request.setMapping(new Mapping());
|
||||
request.addValueTransformation(
|
||||
new ValueTransformationSequence(
|
||||
channelName,
|
||||
new ValueSamplerValueTransformation(2)));
|
||||
|
||||
String content = mapper.writeValueAsString(request);
|
||||
System.out.println(content);
|
||||
|
||||
MvcResult result = this.mockMvc
|
||||
.perform(MockMvcRequestBuilders
|
||||
.post(DomainConfig.PATH_QUERY)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(content))
|
||||
.andReturn();
|
||||
String response = result.getResponse().getContentAsString();
|
||||
System.out.println("Response: " + response);
|
||||
|
||||
Object document = Configuration.defaultConfiguration().jsonProvider().parse(response);
|
||||
String shape = JsonPath.read(document, "$.data[0][0].transformedValue.shape").toString();
|
||||
assertEquals("[40,20]", shape);
|
||||
String value = JsonPath.read(document, "$.data[0][0].transformedValue.value").toString();
|
||||
assertTrue(value.startsWith("[100.0,"));
|
||||
|
||||
shape = JsonPath.read(document, "$.data[1][0].transformedValue.shape").toString();
|
||||
assertEquals("[40,20]", shape);
|
||||
value = JsonPath.read(document, "$.data[1][0].transformedValue.value").toString();
|
||||
assertTrue(value.startsWith("[101.0,"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValueTransformation_03() throws Exception {
|
||||
String channelName = "TestImage";
|
||||
String channelName2 = "Test2Image";
|
||||
DAQQuery request = new DAQQuery(
|
||||
new RequestRangePulseId(
|
||||
100,
|
||||
101),
|
||||
channelName, channelName2);
|
||||
request.addField(QueryField.pulseId);
|
||||
request.addField(QueryField.globalSeconds);
|
||||
request.addField(QueryField.globalMillis);
|
||||
request.addField(QueryField.iocSeconds);
|
||||
request.addField(QueryField.iocMillis);
|
||||
request.setMapping(new Mapping());
|
||||
request.addValueTransformation(
|
||||
new ValueTransformationSequence(
|
||||
null,
|
||||
new ImageDownScaleValueTransformation(8, Color.BLUE, Color.RED),
|
||||
new ImageEncodingValueTransformation(
|
||||
ImageFormat.PNG,
|
||||
new Base64ImageEncoder(StandardCharsets.UTF_8, true, false))));
|
||||
request.addValueTransformation(
|
||||
new ValueTransformationSequence(
|
||||
"Test2",
|
||||
new ValueSamplerValueTransformation(2)));
|
||||
|
||||
String content = mapper.writeValueAsString(request);
|
||||
System.out.println(content);
|
||||
|
||||
MvcResult result = this.mockMvc
|
||||
.perform(MockMvcRequestBuilders
|
||||
.post(DomainConfig.PATH_QUERY)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(content))
|
||||
.andReturn();
|
||||
String response = result.getResponse().getContentAsString();
|
||||
System.out.println("Response: " + response);
|
||||
|
||||
String imageScheme = "data:image/png;charset=UTF-8;base64,";
|
||||
assertTrue(response.contains(imageScheme));
|
||||
Object document = Configuration.defaultConfiguration().jsonProvider().parse(response);
|
||||
String image = JsonPath.read(document, "$.data[0][0].transformedValue");
|
||||
assertTrue(image.startsWith(imageScheme));
|
||||
image = JsonPath.read(document, "$.data[1][0].transformedValue");
|
||||
assertTrue(image.startsWith(imageScheme));
|
||||
|
||||
String shape = JsonPath.read(document, "$.data[0][1].transformedValue.shape").toString();
|
||||
assertEquals("[40,20]", shape);
|
||||
String value = JsonPath.read(document, "$.data[0][1].transformedValue.value").toString();
|
||||
assertTrue(value.startsWith("[100.0,"));
|
||||
|
||||
shape = JsonPath.read(document, "$.data[1][1].transformedValue.shape").toString();
|
||||
assertEquals("[40,20]", shape);
|
||||
value = JsonPath.read(document, "$.data[1][1].transformedValue.value").toString();
|
||||
assertTrue(value.startsWith("[101.0,"));
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package ch.psi.daq.test.queryrest.controller;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.awt.Color;
|
||||
@ -40,6 +41,7 @@ import ch.psi.daq.domain.query.transform.image.ImageEncodingValueTransformation;
|
||||
import ch.psi.daq.domain.query.transform.image.ImageDownScaleValueTransformation;
|
||||
import ch.psi.daq.domain.query.transform.image.ImageFormat;
|
||||
import ch.psi.daq.domain.query.transform.image.encoding.Base64ImageEncoder;
|
||||
import ch.psi.daq.domain.query.transform.sampling.ValueSamplerValueTransformation;
|
||||
import ch.psi.daq.domain.request.range.RequestRangeDate;
|
||||
import ch.psi.daq.domain.request.range.RequestRangePulseId;
|
||||
import ch.psi.daq.domain.request.range.RequestRangeTime;
|
||||
@ -559,8 +561,7 @@ public class JsonQueryRestControllerTest extends AbstractDaqRestTest {
|
||||
MockMvcRequestBuilders
|
||||
.post(DomainConfig.PATH_QUERY)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(content)
|
||||
)
|
||||
.content(content))
|
||||
.andDo(MockMvcResultHandlers.print())
|
||||
.andExpect(MockMvcResultMatchers.status().isOk())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$").isArray())
|
||||
@ -649,8 +650,7 @@ public class JsonQueryRestControllerTest extends AbstractDaqRestTest {
|
||||
MockMvcRequestBuilders
|
||||
.post(DomainConfig.PATH_QUERY)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(content)
|
||||
)
|
||||
.content(content))
|
||||
.andDo(MockMvcResultHandlers.print())
|
||||
.andExpect(MockMvcResultMatchers.status().isOk())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$").isArray())
|
||||
@ -701,8 +701,7 @@ public class JsonQueryRestControllerTest extends AbstractDaqRestTest {
|
||||
MockMvcRequestBuilders
|
||||
.post(DomainConfig.PATH_QUERY)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(content)
|
||||
)
|
||||
.content(content))
|
||||
.andDo(MockMvcResultHandlers.print())
|
||||
.andExpect(MockMvcResultMatchers.status().isOk())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$").isArray())
|
||||
@ -769,8 +768,7 @@ public class JsonQueryRestControllerTest extends AbstractDaqRestTest {
|
||||
MockMvcRequestBuilders
|
||||
.post(DomainConfig.PATH_QUERY)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(content)
|
||||
)
|
||||
.content(content))
|
||||
.andDo(MockMvcResultHandlers.print())
|
||||
.andExpect(MockMvcResultMatchers.status().isOk())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$").isArray())
|
||||
@ -885,8 +883,7 @@ public class JsonQueryRestControllerTest extends AbstractDaqRestTest {
|
||||
MockMvcRequestBuilders
|
||||
.post(DomainConfig.PATH_QUERY)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(content)
|
||||
)
|
||||
.content(content))
|
||||
.andDo(MockMvcResultHandlers.print())
|
||||
.andExpect(MockMvcResultMatchers.status().isOk())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$").isArray())
|
||||
@ -946,8 +943,7 @@ public class JsonQueryRestControllerTest extends AbstractDaqRestTest {
|
||||
MockMvcRequestBuilders
|
||||
.post(DomainConfig.PATH_QUERY)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(content)
|
||||
)
|
||||
.content(content))
|
||||
.andDo(MockMvcResultHandlers.print())
|
||||
.andExpect(MockMvcResultMatchers.status().isOk())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$").isArray())
|
||||
@ -1146,12 +1142,13 @@ public class JsonQueryRestControllerTest extends AbstractDaqRestTest {
|
||||
request.addField(QueryField.globalMillis);
|
||||
request.addField(QueryField.iocSeconds);
|
||||
request.addField(QueryField.iocMillis);
|
||||
request.setValueTransformation(
|
||||
request.addValueTransformation(
|
||||
new ValueTransformationSequence(
|
||||
ValueTransformationSequence.ALL_CHANNELS,
|
||||
new ImageDownScaleValueTransformation(8, Color.BLUE, Color.RED),
|
||||
new ImageEncodingValueTransformation(
|
||||
ImageFormat.PNG,
|
||||
new Base64ImageEncoder(StandardCharsets.UTF_8, true, false))));
|
||||
new ImageEncodingValueTransformation(
|
||||
ImageFormat.PNG,
|
||||
new Base64ImageEncoder(StandardCharsets.UTF_8, true, false))));
|
||||
|
||||
String content = mapper.writeValueAsString(request);
|
||||
System.out.println(content);
|
||||
@ -1173,4 +1170,104 @@ public class JsonQueryRestControllerTest extends AbstractDaqRestTest {
|
||||
image = JsonPath.read(document, "$[0].data[1].transformedValue");
|
||||
assertTrue(image.startsWith(imageScheme));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValueTransformation_02() throws Exception {
|
||||
String channelName = "TestImage";
|
||||
DAQQuery request = new DAQQuery(
|
||||
new RequestRangePulseId(
|
||||
100,
|
||||
101),
|
||||
channelName);
|
||||
request.addField(QueryField.pulseId);
|
||||
request.addField(QueryField.globalSeconds);
|
||||
request.addField(QueryField.globalMillis);
|
||||
request.addField(QueryField.iocSeconds);
|
||||
request.addField(QueryField.iocMillis);
|
||||
request.addValueTransformation(
|
||||
new ValueTransformationSequence(
|
||||
channelName,
|
||||
new ValueSamplerValueTransformation(2))
|
||||
);
|
||||
|
||||
String content = mapper.writeValueAsString(request);
|
||||
System.out.println(content);
|
||||
|
||||
MvcResult result = this.mockMvc
|
||||
.perform(MockMvcRequestBuilders
|
||||
.post(DomainConfig.PATH_QUERY)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(content))
|
||||
.andReturn();
|
||||
String response = result.getResponse().getContentAsString();
|
||||
System.out.println("Response: " + response);
|
||||
|
||||
Object document = Configuration.defaultConfiguration().jsonProvider().parse(response);
|
||||
String shape = JsonPath.read(document, "$[0].data[0].transformedValue.shape").toString();
|
||||
assertEquals("[40,20]", shape);
|
||||
String value = JsonPath.read(document, "$[0].data[0].transformedValue.value").toString();
|
||||
assertTrue(value.startsWith("[100.0,"));
|
||||
|
||||
shape = JsonPath.read(document, "$[0].data[1].transformedValue.shape").toString();
|
||||
assertEquals("[40,20]", shape);
|
||||
value = JsonPath.read(document, "$[0].data[1].transformedValue.value").toString();
|
||||
assertTrue(value.startsWith("[101.0,"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValueTransformation_03() throws Exception {
|
||||
String channelName = "TestImage";
|
||||
String channelName2 = "Test2Image";
|
||||
DAQQuery request = new DAQQuery(
|
||||
new RequestRangePulseId(
|
||||
100,
|
||||
101),
|
||||
channelName, channelName2);
|
||||
request.addField(QueryField.pulseId);
|
||||
request.addField(QueryField.globalSeconds);
|
||||
request.addField(QueryField.globalMillis);
|
||||
request.addField(QueryField.iocSeconds);
|
||||
request.addField(QueryField.iocMillis);
|
||||
request.addValueTransformation(
|
||||
new ValueTransformationSequence(
|
||||
null,
|
||||
new ImageDownScaleValueTransformation(8, Color.BLUE, Color.RED),
|
||||
new ImageEncodingValueTransformation(
|
||||
ImageFormat.PNG,
|
||||
new Base64ImageEncoder(StandardCharsets.UTF_8, true, false))));
|
||||
request.addValueTransformation(
|
||||
new ValueTransformationSequence(
|
||||
"Test2",
|
||||
new ValueSamplerValueTransformation(2)));
|
||||
|
||||
String content = mapper.writeValueAsString(request);
|
||||
System.out.println(content);
|
||||
|
||||
MvcResult result = this.mockMvc
|
||||
.perform(MockMvcRequestBuilders
|
||||
.post(DomainConfig.PATH_QUERY)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(content))
|
||||
.andReturn();
|
||||
String response = result.getResponse().getContentAsString();
|
||||
System.out.println("Response: " + response);
|
||||
|
||||
String imageScheme = "data:image/png;charset=UTF-8;base64,";
|
||||
assertTrue(response.contains(imageScheme));
|
||||
Object document = Configuration.defaultConfiguration().jsonProvider().parse(response);
|
||||
String image = JsonPath.read(document, "$[0].data[0].transformedValue");
|
||||
assertTrue(image.startsWith(imageScheme));
|
||||
image = JsonPath.read(document, "$[0].data[1].transformedValue");
|
||||
assertTrue(image.startsWith(imageScheme));
|
||||
|
||||
String shape = JsonPath.read(document, "$[1].data[0].transformedValue.shape").toString();
|
||||
assertEquals("[40,20]", shape);
|
||||
String value = JsonPath.read(document, "$[1].data[0].transformedValue.value").toString();
|
||||
assertTrue(value.startsWith("[100.0,"));
|
||||
|
||||
shape = JsonPath.read(document, "$[1].data[1].transformedValue.shape").toString();
|
||||
assertEquals("[40,20]", shape);
|
||||
value = JsonPath.read(document, "$[1].data[1].transformedValue.value").toString();
|
||||
assertTrue(value.startsWith("[101.0,"));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user