You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by ze...@apache.org on 2020/08/31 21:15:44 UTC
[incubator-streampipes-extensions] branch dev updated: Improve
number labeling component
This is an automated email from the ASF dual-hosted git repository.
zehnder pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes-extensions.git
The following commit(s) were added to refs/heads/dev by this push:
new 2bb3f57 Improve number labeling component
new fe45266 Merge branch 'dev' of github.com:apache/incubator-streampipes-extensions into dev
2bb3f57 is described below
commit 2bb3f57c0540d891fd91b366116ee450339dcdb8
Author: Philipp Zehnder <ze...@fzi.de>
AuthorDate: Mon Aug 31 23:14:16 2020 +0200
Improve number labeling component
---
.../state/labeler/model/StatementUtils.java | 22 +++++++++
.../state/labeler/number/NumberLabeler.java | 11 +++--
.../labeler/number/NumberLabelerController.java | 56 ++++++++++++++++++----
.../labeler/number/NumberLabelerParameters.java | 36 ++++++++++----
.../strings.en | 12 +++--
5 files changed, 111 insertions(+), 26 deletions(-)
diff --git a/streampipes-processors-transformation-jvm/src/main/java/org/apache/streampipes/processors/transformation/jvm/processor/state/labeler/model/StatementUtils.java b/streampipes-processors-transformation-jvm/src/main/java/org/apache/streampipes/processors/transformation/jvm/processor/state/labeler/model/StatementUtils.java
index 69bef65..266bcf0 100644
--- a/streampipes-processors-transformation-jvm/src/main/java/org/apache/streampipes/processors/transformation/jvm/processor/state/labeler/model/StatementUtils.java
+++ b/streampipes-processors-transformation-jvm/src/main/java/org/apache/streampipes/processors/transformation/jvm/processor/state/labeler/model/StatementUtils.java
@@ -50,12 +50,30 @@ public class StatementUtils {
}
+
+ public static List<Statement> getStatements(List<Integer> numberValues, List<String> labelStrings, List<String> comparators) throws SpRuntimeException {
+
+ List<Statement> result = new ArrayList<>();
+
+ for (int i = 0; i < numberValues.size(); i++) {
+ Statement statement = new Statement();
+ statement.setLabel(labelStrings.get(i));
+ statement.setOperator(comparators.get(i));
+ statement.setValue(numberValues.get(i));
+
+ result.add(statement);
+ }
+
+ return result;
+ }
+
/**
* Extracts Statements from Strings
* @param statementStrings
* @return
* @throws SpRuntimeException
*/
+ @Deprecated
public static List<Statement> getStatements(List<String> statementStrings) throws SpRuntimeException {
List<Statement> statements = new ArrayList<>();
@@ -126,6 +144,10 @@ public class StatementUtils {
private static boolean condition(Statement statement, double calculatedValue) {
if (">".equals(statement.getOperator())) {
return calculatedValue > statement.getValue();
+ } else if (">=".equals(statement.getOperator())) {
+ return calculatedValue < statement.getValue();
+ } else if ("<=".equals(statement.getOperator())) {
+ return calculatedValue <= statement.getValue();
} else if ("<".equals(statement.getOperator())) {
return calculatedValue < statement.getValue();
} else if ("=".equals(statement.getOperator())) {
diff --git a/streampipes-processors-transformation-jvm/src/main/java/org/apache/streampipes/processors/transformation/jvm/processor/state/labeler/number/NumberLabeler.java b/streampipes-processors-transformation-jvm/src/main/java/org/apache/streampipes/processors/transformation/jvm/processor/state/labeler/number/NumberLabeler.java
index 34feca1..b8d5dfe 100644
--- a/streampipes-processors-transformation-jvm/src/main/java/org/apache/streampipes/processors/transformation/jvm/processor/state/labeler/number/NumberLabeler.java
+++ b/streampipes-processors-transformation-jvm/src/main/java/org/apache/streampipes/processors/transformation/jvm/processor/state/labeler/number/NumberLabeler.java
@@ -38,14 +38,17 @@ public class NumberLabeler implements EventProcessor<NumberLabelerParameters> {
private List<Statement> statements;
@Override
- public void onInvocation(NumberLabelerParameters stateBufferParameters,
+ public void onInvocation(NumberLabelerParameters numberLabelerParameters,
SpOutputCollector spOutputCollector,
EventProcessorRuntimeContext runtimeContext) throws SpRuntimeException {
- LOG = stateBufferParameters.getGraph().getLogger(NumberLabeler.class);
+ LOG = numberLabelerParameters.getGraph().getLogger(NumberLabeler.class);
- this.sensorListValueProperty = stateBufferParameters.getSensorListValueProperty();
+ this.statements = StatementUtils.getStatements(
+ numberLabelerParameters.getNumberValues(),
+ numberLabelerParameters.getLabelStrings(),
+ numberLabelerParameters.getComparators());
- this.statements = StatementUtils.getStatements(stateBufferParameters.getStatementsStrings());
+ this.sensorListValueProperty = numberLabelerParameters.getSensorListValueProperty();
}
@Override
diff --git a/streampipes-processors-transformation-jvm/src/main/java/org/apache/streampipes/processors/transformation/jvm/processor/state/labeler/number/NumberLabelerController.java b/streampipes-processors-transformation-jvm/src/main/java/org/apache/streampipes/processors/transformation/jvm/processor/state/labeler/number/NumberLabelerController.java
index 473bec6..44cf1ff 100644
--- a/streampipes-processors-transformation-jvm/src/main/java/org/apache/streampipes/processors/transformation/jvm/processor/state/labeler/number/NumberLabelerController.java
+++ b/streampipes-processors-transformation-jvm/src/main/java/org/apache/streampipes/processors/transformation/jvm/processor/state/labeler/number/NumberLabelerController.java
@@ -21,6 +21,9 @@ package org.apache.streampipes.processors.transformation.jvm.processor.state.lab
import org.apache.streampipes.model.graph.DataProcessorDescription;
import org.apache.streampipes.model.graph.DataProcessorInvocation;
import org.apache.streampipes.model.schema.PropertyScope;
+import org.apache.streampipes.model.staticproperty.*;
+import org.apache.streampipes.processors.transformation.jvm.processor.state.labeler.model.Statement;
+import org.apache.streampipes.processors.transformation.jvm.processor.state.labeler.model.StatementUtils;
import org.apache.streampipes.sdk.StaticProperties;
import org.apache.streampipes.sdk.builder.ProcessingElementBuilder;
import org.apache.streampipes.sdk.builder.StreamRequirementsBuilder;
@@ -32,11 +35,14 @@ import org.apache.streampipes.wrapper.standalone.ConfiguredEventProcessor;
import org.apache.streampipes.wrapper.standalone.declarer.StandaloneEventProcessingDeclarer;
import java.util.List;
+import java.util.stream.Collectors;
public class NumberLabelerController extends StandaloneEventProcessingDeclarer<NumberLabelerParameters> {
public static final String SENSOR_VALUE_ID = "sensorValueId";
public static final String LABEL_COLLECTION_ID = "labelCollectionId";
+ public static final String COMPARATOR_ID = "comparatorId";
+ public static final String NUMBER_VALUE_ID = "numberValueId";
public static final String LABEL_STRING_ID = "labelStringId";
public static final String LABEL = "label";
@@ -52,15 +58,15 @@ public class NumberLabelerController extends StandaloneEventProcessingDeclarer<N
Labels.withId(SENSOR_VALUE_ID),
PropertyScope.NONE)
.build())
- .requiredParameterAsCollection(
+ .requiredCollection(
Labels.withId(LABEL_COLLECTION_ID),
- StaticProperties.stringFreeTextProperty(Labels.withId(LABEL_STRING_ID)))
-
-// StaticProperties.collection(Labels.withId(PLC_NODES),
-// StaticProperties.stringFreeTextProperty(Labels.withId(PLC_NODE_RUNTIME_NAME)),
-// StaticProperties.stringFreeTextProperty(Labels.withId(PLC_NODE_NAME)),
-// StaticProperties.singleValueSelection(Labels.withId(PLC_NODE_TYPE),
-// Options.from("Bool", "Byte", "Int", "Word", "Real"))))
+ StaticProperties.group(Labels.from("group", "Group", ""), false,
+ StaticProperties.singleValueSelection(Labels.withId(COMPARATOR_ID),
+ Options.from("<", "<=", ">", ">=", "==", "*")),
+ StaticProperties.doubleFreeTextProperty(Labels.withId(NUMBER_VALUE_ID)),
+ StaticProperties.stringFreeTextProperty(Labels.withId(LABEL_STRING_ID))
+ )
+ )
.outputStrategy(OutputStrategies.append(
EpProperties.stringEp(Labels.withId(LABEL), LABEL, SPSensor.STATE, PropertyScope.DIMENSION_PROPERTY)
@@ -73,9 +79,39 @@ public class NumberLabelerController extends StandaloneEventProcessingDeclarer<N
String sensorListValueProperty = extractor.mappingPropertyValue(SENSOR_VALUE_ID);
- List<String> statementStrings = extractor.singleValueParameterFromCollection(LABEL_COLLECTION_ID, String.class);
+ List<StaticPropertyGroup> groupItems = extractor.collectionMembersAsGroup(LABEL_COLLECTION_ID);
+
+ List<Integer> numberValues = groupItems
+ .stream()
+ .map(group -> (
+ extractor
+ .extractGroupMember(NUMBER_VALUE_ID, group)
+ .as(FreeTextStaticProperty.class))
+ .getValue())
+ .map(Integer::parseInt)
+ .collect(Collectors.toList());
+
+ List<String> labelStrings = groupItems
+ .stream()
+ .map(group -> (extractor
+ .extractGroupMember(LABEL_STRING_ID, group)
+ .as(FreeTextStaticProperty.class))
+ .getValue())
+ .collect(Collectors.toList());
+
+ List<String> comparators = groupItems
+ .stream()
+ .map(group -> (extractor
+ .extractGroupMember(COMPARATOR_ID, group)
+ .as(OneOfStaticProperty.class))
+ .getOptions()
+ .stream()
+ .filter(Option::isSelected).findFirst().get().getName())
+ .collect(Collectors.toList());
+
+
+ NumberLabelerParameters params = new NumberLabelerParameters(graph, sensorListValueProperty, numberValues, labelStrings, comparators);
- NumberLabelerParameters params = new NumberLabelerParameters(graph, sensorListValueProperty, statementStrings);
return new ConfiguredEventProcessor<>(params, NumberLabeler::new);
}
diff --git a/streampipes-processors-transformation-jvm/src/main/java/org/apache/streampipes/processors/transformation/jvm/processor/state/labeler/number/NumberLabelerParameters.java b/streampipes-processors-transformation-jvm/src/main/java/org/apache/streampipes/processors/transformation/jvm/processor/state/labeler/number/NumberLabelerParameters.java
index 5063bb8..ef13001 100644
--- a/streampipes-processors-transformation-jvm/src/main/java/org/apache/streampipes/processors/transformation/jvm/processor/state/labeler/number/NumberLabelerParameters.java
+++ b/streampipes-processors-transformation-jvm/src/main/java/org/apache/streampipes/processors/transformation/jvm/processor/state/labeler/number/NumberLabelerParameters.java
@@ -26,14 +26,17 @@ import java.util.List;
public class NumberLabelerParameters extends EventProcessorBindingParams {
private String sensorListValueProperty;
- private List<String> statementsStrings;
- public NumberLabelerParameters(DataProcessorInvocation graph,
- String sensorListValueProperty,
- List<String> statementsStrings) {
+ private List<Integer> numberValues;
+ private List<String> labelStrings;
+ private List<String> comparators;
+
+ public NumberLabelerParameters(DataProcessorInvocation graph, String sensorListValueProperty, List<Integer> numberValues, List<String> labelStrings, List<String> comparators) {
super(graph);
this.sensorListValueProperty = sensorListValueProperty;
- this.statementsStrings = statementsStrings;
+ this.numberValues = numberValues;
+ this.labelStrings = labelStrings;
+ this.comparators = comparators;
}
public String getSensorListValueProperty() {
@@ -44,12 +47,27 @@ public class NumberLabelerParameters extends EventProcessorBindingParams {
this.sensorListValueProperty = sensorListValueProperty;
}
- public List<String> getStatementsStrings() {
- return statementsStrings;
+ public List<Integer> getNumberValues() {
+ return numberValues;
+ }
+
+ public void setNumberValues(List<Integer> numberValues) {
+ this.numberValues = numberValues;
+ }
+
+ public List<String> getLabelStrings() {
+ return labelStrings;
+ }
+
+ public void setLabelStrings(List<String> labelStrings) {
+ this.labelStrings = labelStrings;
}
- public void setStatementsStrings(List<String> statementsStrings) {
- this.statementsStrings = statementsStrings;
+ public List<String> getComparators() {
+ return comparators;
}
+ public void setComparators(List<String> comparators) {
+ this.comparators = comparators;
+ }
}
diff --git a/streampipes-processors-transformation-jvm/src/main/resources/org.apache.streampipes.processors.transformation.jvm.processor.state.labeler.number/strings.en b/streampipes-processors-transformation-jvm/src/main/resources/org.apache.streampipes.processors.transformation.jvm.processor.state.labeler.number/strings.en
index 31c6151..4d568d0 100644
--- a/streampipes-processors-transformation-jvm/src/main/resources/org.apache.streampipes.processors.transformation.jvm.processor.state.labeler.number/strings.en
+++ b/streampipes-processors-transformation-jvm/src/main/resources/org.apache.streampipes.processors.transformation.jvm.processor.state.labeler.number/strings.en
@@ -5,10 +5,16 @@ sensorValueId.title=Sensor value
sensorValueId.description=The value used for the labeling
labelCollectionId.title=Condition
-labelCollectionId.description=Add a condition with the following scheme (Order is important) '<;5;ok', '<;10;ok' or '*;nok' as a default label
+labelCollectionId.description=Add a condition to provide a label for the data
label.title=Label
label.description=User defined label for data
-labelStringId.title=Condition
-labelStringId.description=Add a condition with the following scheme (Order is important) '<;5;ok', '<;10;ok' or '*;nok' as a default label
+labelStringId.title=Label Value
+labelStringId.description=Provide the label value to be added to the event
+
+comparatorId.title=Comparator
+comparatorId.description=Select a comparator
+
+numberValueId.title=Numerical Value
+numberValueId.description=Specify the numerical value for the condition