Java Code Examples for org.apache.commons.collections4.MapUtils#getDoubleValue()

The following examples show how to use org.apache.commons.collections4.MapUtils#getDoubleValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaselineAlgorithm.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
public BaselineAlgorithm(DataProvider provider, DetectionConfigDTO config, long startTime, long endTime) {
  super(provider, config, startTime, endTime);

  Preconditions.checkArgument(config.getProperties().containsKey(PROP_METRIC_URN));

  String metricUrn = MapUtils.getString(config.getProperties(), PROP_METRIC_URN);
  MetricEntity me = MetricEntity.fromURN(metricUrn);
  this.slice = MetricSlice.from(me.getId(), this.startTime, this.endTime, me.getFilters());

  int weeks = MapUtils.getIntValue(config.getProperties(), PROP_WEEKS, PROP_WEEKS_DEFAULT);
  BaselineAggregateType aggregation = BaselineAggregateType.valueOf(MapUtils.getString(config.getProperties(), PROP_AGGREGATION, PROP_AGGREGATION_DEFAULT));
  DateTimeZone timezone = DateTimeZone.forID(MapUtils.getString(this.config.getProperties(), PROP_TIMEZONE, PROP_TIMEZONE_DEFAULT));
  this.baseline = BaselineAggregate.fromWeekOverWeek(aggregation, weeks, 1, timezone);

  this.change = MapUtils.getDoubleValue(config.getProperties(), PROP_CHANGE, PROP_CHANGE_DEFAULT);
  this.difference = MapUtils.getDoubleValue(config.getProperties(), PROP_DIFFERENCE, PROP_DIFFERENCE_DEFAULT);
}
 
Example 2
Source File: CallGraphPipeline.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
public CallGraphPipeline(String outputName, Set<String> inputNames, Map<String, Object> properties) {
  super(outputName, inputNames);
  this.metricDAO = DAORegistry.getInstance().getMetricConfigDAO();
  this.datasetDAO = DAORegistry.getInstance().getDatasetConfigDAO();
  this.cache = ThirdEyeCacheRegistry.getInstance().getQueryCache();
  this.dataset = MapUtils.getString(properties, PROP_DATASET, PROP_DATASET_DEFAULT);
  this.metricCount = MapUtils.getString(properties, PROP_METRIC_COUNT, PROP_METRIC_COUNT_DEFAULT);
  this.metricLatency = MapUtils.getString(properties, PROP_METRIC_LATENCY, PROP_METRIC_LATENCY_DEFAULT);
  this.k = MapUtils.getIntValue(properties, PROP_K, PROP_K_DEFAULT);
  this.cutoffFraction = MapUtils.getDoubleValue(properties, PROP_CUTOFF_FRACTION, PROP_CUTOFF_FRACTION_DEFAULT);

  if (properties.containsKey(PROP_INCLUDE_DIMENSIONS)) {
    this.includeDimensions = new HashSet<>((Collection<String>) properties.get(PROP_INCLUDE_DIMENSIONS));
  } else {
    this.includeDimensions = new HashSet<>();
  }

  if (properties.containsKey(PROP_EXCLUDE_DIMENSIONS)) {
    this.excludeDimensions = new HashSet<>((Collection<String>) properties.get(PROP_EXCLUDE_DIMENSIONS));
  } else {
    this.excludeDimensions = new HashSet<>();
  }
}
 
Example 3
Source File: MockThirdEyeDataSource.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a DataFrame populated with mock data for a given config and time range.
 *
 * @param config metric generator config
 * @param start start time
 * @param end end time
 * @param interval time granularity
 * @return DataFrame with mock data
 */
private static DataFrame makeData(Map<String, Object> config, DateTime start, DateTime end, Period interval) {
  List<Long> timestamps = new ArrayList<>();
  List<Double> values = new ArrayList<>();

  double mean = MapUtils.getDoubleValue(config, "mean", 0);
  double std = MapUtils.getDoubleValue(config, "std", 1);
  double daily = MapUtils.getDoubleValue(config, "daily", mean);
  double weekly = MapUtils.getDoubleValue(config, "weekly", daily);
  NormalDistribution dist = new NormalDistribution(mean, std);

  DateTime origin = start.withFields(DataFrameUtils.makeOrigin(PeriodType.days()));
  while (origin.isBefore(end)) {
    if (origin.isBefore(start)) {
      origin = origin.plus(interval);
      continue;
    }

    timestamps.add(origin.getMillis());

    double compDaily = weekly * (COMPONENT_ALPHA_WEEKLY + Math.sin(origin.getDayOfWeek() / 7.0 * 2 * Math.PI + 1) / 2 * (1 - COMPONENT_ALPHA_WEEKLY));
    double compHourly = daily * (COMPONENT_ALPHA_DAILY + Math.sin(origin.getHourOfDay() / 24.0 * 2 * Math.PI + 1) / 2 * (1 - COMPONENT_ALPHA_DAILY));
    double compEpsilon = dist.sample();

    values.add((double) Math.max(Math.round(compDaily + compHourly + compEpsilon), 0));
    origin = origin.plus(interval);
  }

  return new DataFrame()
      .addSeries(COL_TIME, ArrayUtils.toPrimitive(timestamps.toArray(new Long[0])))
      .addSeries(COL_VALUE, ArrayUtils.toPrimitive(values.toArray(new Double[0])))
      .setIndex(COL_TIME);
}
 
Example 4
Source File: DimensionWrapper.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
public DimensionWrapper(DataProvider provider, DetectionConfigDTO config, long startTime, long endTime) {
  super(provider, config, startTime, endTime);

  // the metric used in dimension exploration
  this.metricUrn = MapUtils.getString(config.getProperties(), "metricUrn", null);

  this.minContribution = MapUtils.getDoubleValue(config.getProperties(), "minContribution", Double.NaN);
  this.minValue = MapUtils.getDoubleValue(config.getProperties(), "minValue", Double.NaN);
  this.minValueHourly = MapUtils.getDoubleValue(config.getProperties(), "minValueHourly", Double.NaN);
  this.maxValueHourly = MapUtils.getDoubleValue(config.getProperties(), "maxValueHourly", Double.NaN);
  this.minValueDaily = MapUtils.getDoubleValue(config.getProperties(), "minValueDaily", Double.NaN);
  this.maxValueDaily = MapUtils.getDoubleValue(config.getProperties(), "maxValueDaily", Double.NaN);
  this.k = MapUtils.getIntValue(config.getProperties(), "k", -1);
  this.dimensions = ConfigUtils.getList(config.getProperties().get("dimensions"));
  this.lookback = ConfigUtils.parsePeriod(MapUtils.getString(config.getProperties(), "lookback", "1w"));
  this.timezone = DateTimeZone.forID(MapUtils.getString(config.getProperties(), "timezone", "America/Los_Angeles"));

  /*
   * A bucket of the time series is taken into consider only if its value is above the minLiveZone. In other words,
   * if a bucket's value is smaller than minLiveZone, then this bucket is ignored when calculating the average value.
   * Used for outlier removal. Replace legacy average threshold filter.
   */
  this.minLiveZone = MapUtils.getDoubleValue(config.getProperties(), "minLiveZone", Double.NaN);
  this.liveBucketPercentageThreshold = MapUtils.getDoubleValue(config.getProperties(), "liveBucketPercentageThreshold", 0.5);

  // the metric to run the detection for
  this.nestedMetricUrns = ConfigUtils.getList(config.getProperties().get(PROP_NESTED_METRIC_URNS), Collections.singletonList(this.metricUrn));
  this.nestedMetricUrnKey = MapUtils.getString(config.getProperties(), PROP_NESTED_METRIC_URN_KEY, PROP_NESTED_METRIC_URN_KEY_DEFAULT);
  this.nestedProperties = ConfigUtils.getList(config.getProperties().get(PROP_NESTED));

  this.start = new DateTime(this.startTime, this.timezone);
  this.end = new DateTime(this.endTime, this.timezone);

  DateTime minStart = this.end.minus(this.lookback);
  if (minStart.isBefore(this.start)) {
    this.start = minStart;
  }

  this.evaluationMetricUrns = new HashSet<>();
}
 
Example 5
Source File: BaselineRuleFilterWrapper.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
public BaselineRuleFilterWrapper(DataProvider provider, DetectionConfigDTO config, long startTime, long endTime) {
  super(provider, config, startTime, endTime);
  int weeks = MapUtils.getIntValue(config.getProperties(), PROP_WEEKS, PROP_WEEKS_DEFAULT);
  DateTimeZone timezone =
      DateTimeZone.forID(MapUtils.getString(this.config.getProperties(), PROP_TIMEZONE, PROP_TIMEZONE_DEFAULT));
  this.baseline = BaselineAggregate.fromWeekOverWeek(BaselineAggregateType.MEDIAN, weeks, 1, timezone);
  // percentage change
  this.change = MapUtils.getDoubleValue(config.getProperties(), PROP_CHANGE, PROP_CHANGE_DEFAULT);
  // absolute change
  this.difference = MapUtils.getDoubleValue(config.getProperties(), PROP_DIFFERENCE, PROP_DIFFERENCE_DEFAULT);
  // site wide impact
  this.siteWideImpactThreshold = MapUtils.getDoubleValue(config.getProperties(), PROP_SITEWIDE_THRESHOLD, PROP_SITEWIDE_THRESHOLD_DEFAULT);
  this.siteWideMetricUrn = MapUtils.getString(config.getProperties(), PROP_SITEWIDE_METRIC);
}
 
Example 6
Source File: ThresholdAlgorithm.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
public ThresholdAlgorithm(DataProvider provider, DetectionConfigDTO config, long startTime, long endTime) {
  super(provider, config, startTime, endTime);
  this.min = MapUtils.getDoubleValue(config.getProperties(), "min", Double.NaN);
  this.max = MapUtils.getDoubleValue(config.getProperties(), "max", Double.NaN);

  String metricUrn = MapUtils.getString(config.getProperties(), "metricUrn");
  MetricEntity me = MetricEntity.fromURN(metricUrn);
  this.slice = MetricSlice.from(me.getId(), this.startTime, this.endTime, me.getFilters());
}
 
Example 7
Source File: MetricDatasetPipeline.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
/**
 * Alternate constructor for RCAFrameworkLoader
 *
 * @param outputName pipeline output name
 * @param inputNames input pipeline names
 * @param properties configuration properties ({@code PROP_COEFFICIENT}, {@code PROP_DIRECTION})
 */
public MetricDatasetPipeline(String outputName, Set<String> inputNames, Map<String, Object> properties) {
  super(outputName, inputNames);
  this.metricDAO = DAORegistry.getInstance().getMetricConfigDAO();
  this.datasetDAO = DAORegistry.getInstance().getDatasetConfigDAO();
  this.coefficient = MapUtils.getDoubleValue(properties, PROP_COEFFICIENT, PROP_COEFFICIENT_DEFAULT);
  this.direction = MappingDirection.valueOf(MapUtils.getString(properties, PROP_DIRECTION, PROP_DIRECTION_DEFAULT));
}
 
Example 8
Source File: ThresholdRuleFilterWrapper.java    From incubator-pinot with Apache License 2.0 4 votes vote down vote up
public ThresholdRuleFilterWrapper(DataProvider provider, DetectionConfigDTO config, long startTime, long endTime) {
  super(provider, config, startTime, endTime);
  this.min = MapUtils.getDoubleValue(config.getProperties(), PROP_MIN, PROP_MIN_DEFAULT);
  this.max = MapUtils.getDoubleValue(config.getProperties(), PROP_MAX, PROP_MAX_DEFAULT);
}
 
Example 9
Source File: MovingWindowAlgorithm.java    From incubator-pinot with Apache License 2.0 4 votes vote down vote up
public MovingWindowAlgorithm(DataProvider provider, DetectionConfigDTO config, long startTime, long endTime) {
  super(provider, config, startTime, endTime);

  Preconditions.checkArgument(config.getProperties().containsKey(PROP_METRIC_URN));

  String metricUrn = MapUtils.getString(config.getProperties(), PROP_METRIC_URN);
  MetricEntity me = MetricEntity.fromURN(metricUrn);

  this.quantileMin = MapUtils.getDoubleValue(config.getProperties(), "quantileMin", Double.NaN);
  this.quantileMax = MapUtils.getDoubleValue(config.getProperties(), "quantileMax", Double.NaN);
  this.zscoreMin = MapUtils.getDoubleValue(config.getProperties(), "zscoreMin", Double.NaN);
  this.zscoreMax = MapUtils.getDoubleValue(config.getProperties(), "zscoreMax", Double.NaN);
  this.zscoreOutlier = MapUtils.getDoubleValue(config.getProperties(), "zscoreOutlier", Double.NaN);
  this.kernelSize = MapUtils.getIntValue(config.getProperties(), "kernelSize", 1);
  this.timezone = DateTimeZone.forID(MapUtils.getString(config.getProperties(), "timezone", "UTC"));
  this.windowSize = ConfigUtils.parsePeriod(MapUtils.getString(config.getProperties(), "windowSize", "1week"));
  this.lookbackPeriod = ConfigUtils.parsePeriod(MapUtils.getString(config.getProperties(), "lookbackPeriod", "1week"));
  this.reworkPeriod = ConfigUtils.parsePeriod(MapUtils.getString(config.getProperties(), "reworkPeriod", "1day"));
  this.changeDuration = ConfigUtils.parsePeriod(MapUtils.getString(config.getProperties(), "changeDuration", "5days"));
  this.changeFraction = MapUtils.getDoubleValue(config.getProperties(), "changeFraction", 0.666);
  this.baselineWeeks = MapUtils.getIntValue(config.getProperties(), "baselineWeeks", 0);
  this.applyLog = MapUtils.getBooleanValue(config.getProperties(), "applyLog", true);
  this.learningRate = MapUtils.getDoubleValue(config.getProperties(), "learningRate", 0.666);

  Preconditions.checkArgument(Double.isNaN(this.quantileMin) || (this.quantileMin >= 0 && this.quantileMin <= 1.0), "quantileMin must be between 0.0 and 1.0");
  Preconditions.checkArgument(Double.isNaN(this.quantileMax) || (this.quantileMax >= 0 && this.quantileMax <= 1.0), "quantileMax must be between 0.0 and 1.0");

  this.effectiveStartTime = new DateTime(startTime, this.timezone).minus(this.lookbackPeriod).getMillis();

  DateTime trainStart = new DateTime(this.effectiveStartTime, this.timezone).minus(this.windowSize);
  DateTime dataStart = trainStart.minus(new Period().withField(DurationFieldType.weeks(), baselineWeeks));
  DateTime detectionStart = new DateTime(startTime, this.timezone).minus(this.reworkPeriod);

  this.sliceData = MetricSlice.from(me.getId(), dataStart.getMillis(), endTime, me.getFilters());
  this.sliceDetection = MetricSlice.from(me.getId(), detectionStart.getMillis(), endTime, me.getFilters());

  AnomalySlice slice = new AnomalySlice().withStart(this.sliceData.getStart()).withEnd(this.sliceData.getEnd());
  if (this.config.getId() != null) {
    this.anomalySlice = slice.withDetectionId(this.config.getId());
  } else {
    this.anomalySlice = slice;
  }
}