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 2021/11/04 14:20:17 UTC

[incubator-streampipes-extensions] branch STREAMPIPES-451 created (now 78dc072)

This is an automated email from the ASF dual-hosted git repository.

zehnder pushed a change to branch STREAMPIPES-451
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes-extensions.git.


      at 78dc072  WIP working on processor events per time

This branch includes the following new commits:

     new 78dc072  WIP working on processor events per time

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[incubator-streampipes-extensions] 01/01: WIP working on processor events per time

Posted by ze...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

zehnder pushed a commit to branch STREAMPIPES-451
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes-extensions.git

commit 78dc072c297cf96edab7812417773efb9249413a
Author: Philipp Zehnder <ze...@fzi.de>
AuthorDate: Thu Nov 4 15:19:16 2021 +0100

    WIP working on processor events per time
---
 streampipes-processors-filters-jvm/pom.xml         |   6 +
 .../processors/filters/jvm/FiltersJvmInit.java     |   2 +
 .../threshold/ThresholdDetectionProcessor.java     |   2 +-
 .../jvm/processor/time/EventsPerTimeProcessor.java | 143 +++++++++++++++++++++
 .../documentation.md                               |  50 +++++++
 .../icon.png                                       | Bin 0 -> 3172 bytes
 .../strings.en                                     |  20 +++
 .../processor/time/EventsPerTimeProcessorTest.java |  44 +++++++
 8 files changed, 266 insertions(+), 1 deletion(-)

diff --git a/streampipes-processors-filters-jvm/pom.xml b/streampipes-processors-filters-jvm/pom.xml
index 3750eaa..a0c13e8 100644
--- a/streampipes-processors-filters-jvm/pom.xml
+++ b/streampipes-processors-filters-jvm/pom.xml
@@ -77,6 +77,12 @@
             <groupId>org.quartz-scheduler</groupId>
             <artifactId>quartz</artifactId>
         </dependency>
+
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>
diff --git a/streampipes-processors-filters-jvm/src/main/java/org/apache/streampipes/processors/filters/jvm/FiltersJvmInit.java b/streampipes-processors-filters-jvm/src/main/java/org/apache/streampipes/processors/filters/jvm/FiltersJvmInit.java
index 24c545a..9dbfbed 100644
--- a/streampipes-processors-filters-jvm/src/main/java/org/apache/streampipes/processors/filters/jvm/FiltersJvmInit.java
+++ b/streampipes-processors-filters-jvm/src/main/java/org/apache/streampipes/processors/filters/jvm/FiltersJvmInit.java
@@ -39,6 +39,7 @@ import org.apache.streampipes.processors.filters.jvm.processor.projection.Projec
 import org.apache.streampipes.processors.filters.jvm.processor.schema.MergeBySchemaProcessor;
 import org.apache.streampipes.processors.filters.jvm.processor.textfilter.TextFilterProcessor;
 import org.apache.streampipes.processors.filters.jvm.processor.threshold.ThresholdDetectionProcessor;
+import org.apache.streampipes.processors.filters.jvm.processor.time.EventsPerTimeProcessor;
 
 public class FiltersJvmInit extends StandaloneModelSubmitter {
 
@@ -54,6 +55,7 @@ public class FiltersJvmInit extends StandaloneModelSubmitter {
             8090)
             .registerPipelineElements(
                     new BooleanFilterProcessor(),
+                    new EventsPerTimeProcessor(),
                     new TextFilterProcessor(),
                     new NumericalFilterProcessor(),
                     new ThresholdDetectionProcessor(),
diff --git a/streampipes-processors-filters-jvm/src/main/java/org/apache/streampipes/processors/filters/jvm/processor/threshold/ThresholdDetectionProcessor.java b/streampipes-processors-filters-jvm/src/main/java/org/apache/streampipes/processors/filters/jvm/processor/threshold/ThresholdDetectionProcessor.java
index 86cccf1..fcc2bd8 100644
--- a/streampipes-processors-filters-jvm/src/main/java/org/apache/streampipes/processors/filters/jvm/processor/threshold/ThresholdDetectionProcessor.java
+++ b/streampipes-processors-filters-jvm/src/main/java/org/apache/streampipes/processors/filters/jvm/processor/threshold/ThresholdDetectionProcessor.java
@@ -62,7 +62,7 @@ public class ThresholdDetectionProcessor extends StreamPipesDataProcessor {
                             EpProperties.booleanEp(Labels.empty(), RESULT_FIELD, SO.Boolean)))
             .requiredSingleValueSelection(Labels.withId(OPERATION), Options.from("<", "<=", ">",
                     ">=", "==", "!="))
-            .requiredFloatParameter(Labels.withId(VALUE), NUMBER_MAPPING)
+            .requiredFloatParameter(Labels.withId(VALUE))
             .build();
 
   }
diff --git a/streampipes-processors-filters-jvm/src/main/java/org/apache/streampipes/processors/filters/jvm/processor/time/EventsPerTimeProcessor.java b/streampipes-processors-filters-jvm/src/main/java/org/apache/streampipes/processors/filters/jvm/processor/time/EventsPerTimeProcessor.java
new file mode 100644
index 0000000..3d1178f
--- /dev/null
+++ b/streampipes-processors-filters-jvm/src/main/java/org/apache/streampipes/processors/filters/jvm/processor/time/EventsPerTimeProcessor.java
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.streampipes.processors.filters.jvm.processor.time;
+
+import org.apache.streampipes.commons.exceptions.SpRuntimeException;
+import org.apache.streampipes.model.DataProcessorType;
+import org.apache.streampipes.model.graph.DataProcessorDescription;
+import org.apache.streampipes.model.runtime.Event;
+import org.apache.streampipes.model.schema.PropertyScope;
+import org.apache.streampipes.sdk.builder.ProcessingElementBuilder;
+import org.apache.streampipes.sdk.builder.StreamRequirementsBuilder;
+import org.apache.streampipes.sdk.helpers.*;
+import org.apache.streampipes.sdk.utils.Assets;
+import org.apache.streampipes.wrapper.context.EventProcessorRuntimeContext;
+import org.apache.streampipes.wrapper.routing.SpOutputCollector;
+import org.apache.streampipes.wrapper.standalone.ProcessorParams;
+import org.apache.streampipes.wrapper.standalone.StreamPipesDataProcessor;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class EventsPerTimeProcessor extends StreamPipesDataProcessor {
+
+  private static final String TIMESTAMP_MAPPING = "timestamp-mapping";
+  private static final String NUMBER_OF_EVENTS = "number-of-events";
+  private static final String TIME_WINDOW = "time-window";
+  private static final String TIME_OPTION = "time-option";
+  private static final String FREEZE_TIME = "freeze-time";
+  private static final String FIRE_OPTION = "fire-option";
+
+  public static final String HOUR = "Hour";
+  public static final String MINUTE = "Minute";
+  public static final String SECOND = "Second";
+  public static final String ONCE = "Once";
+  public static final String EACH = "Each event";
+
+  private String timestampKey;
+  private int numberOfEvents;
+  private int timeWindow;
+  private String timeOption;
+  private int freezeTime;
+  private String fireOption;
+
+  List<Long> timestamps;
+
+  public EventsPerTimeProcessor() {
+   super();
+  }
+
+  public EventsPerTimeProcessor(List<Long> timestamps,
+                                int numberOfEvents,
+                                int timeWindow,
+                                String timeOption,
+                                int freezeTime,
+                                String fireOption) {
+    this.timestampKey = timestampKey;
+    this.numberOfEvents = numberOfEvents;
+    this.timeWindow = timeWindow;
+    this.timeOption = timeOption;
+    this.freezeTime = freezeTime;
+    this.fireOption = fireOption;
+  }
+
+  @Override
+  public DataProcessorDescription declareModel() {
+    return ProcessingElementBuilder.create("org.apache.streampipes.processors.filters.jvm.processor.time")
+            .category(DataProcessorType.FILTER)
+            .withAssets(Assets.DOCUMENTATION, Assets.ICON)
+            .withLocales(Locales.EN)
+            .requiredStream(StreamRequirementsBuilder.create()
+                    .requiredPropertyWithUnaryMapping(
+                            EpRequirements.timestampReq(),
+                            Labels.withId(TIMESTAMP_MAPPING),
+                            PropertyScope.HEADER_PROPERTY).build())
+
+            .requiredIntegerParameter(Labels.withId(NUMBER_OF_EVENTS))
+
+            .requiredSingleValueSelection(Labels.withId(TIME_OPTION), Options.from(HOUR, MINUTE, SECOND))
+            .requiredIntegerParameter(Labels.withId(TIME_WINDOW))
+            .requiredIntegerParameter(Labels.withId(FREEZE_TIME))
+            .requiredSingleValueSelection(Labels.withId(FIRE_OPTION), Options.from(ONCE, EACH))
+
+            .outputStrategy(OutputStrategies.keep())
+
+            .build();
+
+  }
+
+
+  @Override
+  public void onInvocation(ProcessorParams processorParams, SpOutputCollector spOutputCollector, EventProcessorRuntimeContext eventProcessorRuntimeContext) throws SpRuntimeException {
+    this.timestampKey = processorParams.extractor().mappingPropertyValue(TIMESTAMP_MAPPING);
+    this.numberOfEvents = processorParams.extractor().singleValueParameter(NUMBER_OF_EVENTS, Integer.class);
+    this.timeWindow = processorParams.extractor().singleValueParameter(TIME_WINDOW, Integer.class);
+    this.timeOption = processorParams.extractor().selectedSingleValue(TIME_OPTION, String.class);
+    this.freezeTime = processorParams.extractor().singleValueParameter(FREEZE_TIME, Integer.class);
+    this.fireOption = processorParams.extractor().selectedSingleValue(FIRE_OPTION, String.class);
+
+    this.timestamps = new ArrayList<>();
+  }
+
+  @Override
+  public void onEvent(Event event, SpOutputCollector spOutputCollector) throws SpRuntimeException {
+    long timestamp = event.getFieldBySelector(this.timestampKey).getAsPrimitive().getAsLong();
+
+
+    spOutputCollector.collect(event);
+  }
+
+  @Override
+  public void onDetach() throws SpRuntimeException {
+
+  }
+
+  public boolean applyRule() {
+    boolean result = false;
+
+    // remove old events
+
+
+    return result;
+  }
+
+  public List<Long> getTimestamps() {
+    return timestamps;
+  }
+}
diff --git a/streampipes-processors-filters-jvm/src/main/resources/org.apache.streampipes.processors.filters.jvm.processor.time/documentation.md b/streampipes-processors-filters-jvm/src/main/resources/org.apache.streampipes.processors.filters.jvm.processor.time/documentation.md
new file mode 100644
index 0000000..dff0d71
--- /dev/null
+++ b/streampipes-processors-filters-jvm/src/main/resources/org.apache.streampipes.processors.filters.jvm.processor.time/documentation.md
@@ -0,0 +1,50 @@
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one or more
+  ~ contributor license agreements.  See the NOTICE file distributed with
+  ~ this work for additional information regarding copyright ownership.
+  ~ The ASF licenses this file to You under the Apache License, Version 2.0
+  ~ (the "License"); you may not use this file except in compliance with
+  ~ the License.  You may obtain a copy of the License at
+  ~
+  ~    http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  ~
+  -->
+
+## Threshold Detector
+
+<p align="center"> 
+    <img src="icon.png" width="150px;" class="pe-image-documentation"/>
+</p>
+
+***
+
+## Description
+The Threshold Detector processor appends a boolean whether the condition is fulfilled or not
+
+***
+
+## Required input
+The processor works with any input event that has one field containing a numerical value.
+
+***
+
+## Configuration
+
+### Field
+Specifies the field name where the filter operation should be applied on.
+
+
+### Operation
+Specifies the filter operation that should be applied on the field.
+
+### Threshold value
+Specifies the threshold value.
+
+## Output
+Appends a boolean with the value whether the condition is fulfilled or not.
diff --git a/streampipes-processors-filters-jvm/src/main/resources/org.apache.streampipes.processors.filters.jvm.processor.time/icon.png b/streampipes-processors-filters-jvm/src/main/resources/org.apache.streampipes.processors.filters.jvm.processor.time/icon.png
new file mode 100644
index 0000000..643d474
Binary files /dev/null and b/streampipes-processors-filters-jvm/src/main/resources/org.apache.streampipes.processors.filters.jvm.processor.time/icon.png differ
diff --git a/streampipes-processors-filters-jvm/src/main/resources/org.apache.streampipes.processors.filters.jvm.processor.time/strings.en b/streampipes-processors-filters-jvm/src/main/resources/org.apache.streampipes.processors.filters.jvm.processor.time/strings.en
new file mode 100644
index 0000000..182d282
--- /dev/null
+++ b/streampipes-processors-filters-jvm/src/main/resources/org.apache.streampipes.processors.filters.jvm.processor.time/strings.en
@@ -0,0 +1,20 @@
+org.apache.streampipes.processors.filters.jvm.processor.time.title=Events Per Time
+org.apache.streampipes.processors.filters.jvm.processor.time.description=
+
+timestamp-mapping.title=Timestamp
+timestamp-mapping.description=
+
+number-of-events.title=Number of events
+number-of-events.description=The amount of events that must occur before the rule fires
+
+time-window.title=Time Window Length
+time-window.description=The length of the time window in which the events are counted
+
+time-option.title=Time Option
+time-option.description=The unit of the time configurations
+
+freeze-time.title=Wait Time
+freeze-time.description=The time that is waited before the rule fires again.
+
+fire-option.title=Fire option
+fire-option.description=How often should the results be forwarded.
diff --git a/streampipes-processors-filters-jvm/src/test/java/org/apache/streampipes/processors/filters/jvm/processor/time/EventsPerTimeProcessorTest.java b/streampipes-processors-filters-jvm/src/test/java/org/apache/streampipes/processors/filters/jvm/processor/time/EventsPerTimeProcessorTest.java
new file mode 100644
index 0000000..e3bf419
--- /dev/null
+++ b/streampipes-processors-filters-jvm/src/test/java/org/apache/streampipes/processors/filters/jvm/processor/time/EventsPerTimeProcessorTest.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.streampipes.processors.filters.jvm.processor.time;
+
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+
+public class EventsPerTimeProcessorTest {
+
+    @Test
+    public void testFieldAddition() {
+        List<Long> timestamps = Arrays.asList(1000L, 2000L, 3000L, 4000L);
+
+        EventsPerTimeProcessor eventsPerTimeProcessor = new EventsPerTimeProcessor(
+                timestamps,
+                3,
+                5,
+                EventsPerTimeProcessor.SECOND,
+                2,
+                EventsPerTimeProcessor.EACH);
+
+        assertEquals(true, eventsPerTimeProcessor.applyRule());
+        assertEquals(4, eventsPerTimeProcessor.getTimestamps().size());
+    }
+}
\ No newline at end of file