package com.linkedin.thirdeye.detector.email.filter;

import com.linkedin.thirdeye.datalayer.dto.MergedAnomalyResultDTO;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * Created by ychung on 2/14/17.
 *
 * This WeightThresholdAlertFilter checks if the weight level of given merged anomaly result is between given up
 * and down threshold. The up and down threshold should be positive floating point number. This class return false if
 * - downThreshold < weight < upThreshold; otherwise, return true.
 * Note that, down and up thresholds are supposed to be positive double value
 */
public class WeightThresholdAlertFilter extends BaseAlertFilter {
  private final static Logger LOG = LoggerFactory.getLogger(WeightThresholdAlertFilter.class);

  public static final String DEFAULT_UP_THRESHOLD = Double.toString(Double.POSITIVE_INFINITY);
  public static final String DEFAULT_DOWN_THRESHOLD = Double.toString(Double.POSITIVE_INFINITY);

  public static final String UP_THRESHOLD = "upThreshold";
  public static final String DOWN_THRESHOLD = "downThreshold";

  private double upThreshold = Double.parseDouble(DEFAULT_UP_THRESHOLD);
  private double dwnThreshold = Double.parseDouble(DEFAULT_DOWN_THRESHOLD);

  public double getUpThreshold() {
    return upThreshold;
  }

  public void setUpThreshold(double upThreshold) {
    this.upThreshold = Math.abs(upThreshold);
  }

  public double getDownThreshold() {
    return dwnThreshold;
  }

  public void setDownThreshold(double dwnThreshold) {
    this.dwnThreshold = Math.abs(dwnThreshold);
  }


  public WeightThresholdAlertFilter(){

  }

  public WeightThresholdAlertFilter(double upThreshold, double downThreshold){
    setUpThreshold(upThreshold);
    setDownThreshold(downThreshold);
  }

  @Override
  public List<String> getPropertyNames() {
    return Collections.unmodifiableList(new ArrayList<>(Arrays.asList(UP_THRESHOLD, DOWN_THRESHOLD)));
  }

  // Check if the weight of the given MergedAnomalyResultDTO is greater or equal to the up threshold
  // or is less or equal to the down threshold.
  @Override
  public boolean isQualified(MergedAnomalyResultDTO anomaly) {
    double weight = anomaly.getWeight();
    return (weight >= upThreshold) || (weight <= -1*dwnThreshold);
  }
}

@@ -1260,32 +1260,33 @@
 private double d
+o
 wnThreshold = Do
@@ -1543,16 +1543,17 @@
 return d
+o
 wnThresh
@@ -1601,16 +1601,17 @@
 double d
+o
 wnThresh
@@ -1627,16 +1627,17 @@
   this.d
+o
 wnThresh
@@ -1652,16 +1652,17 @@
 th.abs(d
+o
 wnThresh
@@ -2355,10 +2355,13 @@
 = -1
-*d
+ * do
 wnTh

Fix parameter name of WeightThresholdAlertFilter (#1198)