bossenti commented on code in PR #1306:
URL: https://github.com/apache/streampipes/pull/1306#discussion_r1111048166


##########
streampipes-extensions/streampipes-processors-filters-jvm/src/main/java/org/apache/streampipes/processors/filters/jvm/processor/sdt/SwingingDoorTrendingFilter.java:
##########
@@ -0,0 +1,169 @@
+/*
+ * 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.sdt;
+
+import org.apache.streampipes.model.runtime.Event;
+import org.apache.streampipes.wrapper.routing.SpOutputCollector;
+
+public class SwingingDoorTrendingFilter {
+
+  /**
+   * the maximum absolute difference the user set if the data's value is 
within compressionDeviation, it
+   * will be compressed and discarded after compression, it will only store 
out of range (time, data) to form the trend
+   */
+  private final double compressionDeviation;
+
+  /**
+   * the minimum time distance between two stored data points if current point 
time to the last
+   * stored point time distance <= compressionMinTimeInterval, current point 
will NOT be stored regardless of
+   * compression deviation
+   */
+  private final long compressionMinTimeInterval;
+
+  /**
+   * the maximum time distance between two stored data points if current point 
time to the last
+   * stored point time distance >= compressionMaxTimeInterval, current point 
will be stored regardless of
+   * compression deviation
+   */
+  private final long compressionMaxTimeInterval;
+
+  /**
+   * isFirstValue is true when the encoder takes the first point or reset() 
when cur point's
+   * distance to the last stored point's distance exceeds 
compressionMaxTimeInterval
+   */
+  private boolean isFirstValue = true;
+
+  /**
+   * the maximum curUpperSlope between the lastStoredPoint to the current 
point upperDoor can only
+   * open up
+   */
+  private double upperDoor = Integer.MIN_VALUE;
+
+  /**
+   * the minimum curLowerSlope between the lastStoredPoint to the current 
point lowerDoor can only
+   * open downward
+   */
+  private double lowerDoor = Integer.MAX_VALUE;
+
+  /**
+   * the last read time and value if upperDoor >= lowerDoor meaning out of 
compressionDeviation range, will
+   * store lastReadPair
+   */
+  private long lastReadTimestamp;
+  private double lastReadDouble;
+  private Event lastReadEvent;
+
+  /**
+   * the last stored time and value we compare current point against 
lastStoredPair
+   */
+  private long lastStoredTimestamp;
+  private double lastStoredDouble;
+  private Event lastStoredEvent;
+
+  public SwingingDoorTrendingFilter(double compressionDeviation, long 
compressionMinTimeInterval,
+                                    long compressionMaxTimeInterval) {
+    this.compressionDeviation = compressionDeviation;
+    this.compressionMinTimeInterval = compressionMinTimeInterval;
+    this.compressionMaxTimeInterval = compressionMaxTimeInterval;
+  }
+
+  public boolean filter(long time, double value, Event event) {

Review Comment:
   From my point of view javadoc would be helpful here :) 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@streampipes.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to