Search in sources :

Example 1 with AnomalyFeedbackDTO

use of com.linkedin.thirdeye.datalayer.dto.AnomalyFeedbackDTO in project pinot by linkedin.

the class AnomalyResource method updateAnomalyMergedResultFeedback.

/**
   * @param anomalyResultId : anomaly merged result id
   * @param payload         : Json payload containing feedback @see com.linkedin.thirdeye.constant.AnomalyFeedbackType
   *                        eg. payload
   *                        <p/>
   *                        { "feedbackType": "NOT_ANOMALY", "comment": "this is not an anomaly" }
   */
@POST
@Path(value = "anomaly-merged-result/feedback/{anomaly_merged_result_id}")
public void updateAnomalyMergedResultFeedback(@PathParam("anomaly_merged_result_id") long anomalyResultId, String payload) {
    try {
        MergedAnomalyResultDTO result = anomalyMergedResultDAO.findById(anomalyResultId);
        if (result == null) {
            throw new IllegalArgumentException("AnomalyResult not found with id " + anomalyResultId);
        }
        AnomalyFeedbackDTO feedbackRequest = OBJECT_MAPPER.readValue(payload, AnomalyFeedbackDTO.class);
        AnomalyFeedbackDTO feedback = result.getFeedback();
        if (feedback == null) {
            feedback = new AnomalyFeedbackDTO();
            result.setFeedback(feedback);
        }
        if (feedbackRequest.getStatus() == null) {
            feedback.setStatus(FeedbackStatus.NEW);
        } else {
            feedback.setStatus(feedbackRequest.getStatus());
        }
        feedback.setComment(feedbackRequest.getComment());
        feedback.setFeedbackType(feedbackRequest.getFeedbackType());
        anomalyMergedResultDAO.updateAnomalyFeedback(result);
    } catch (IOException e) {
        throw new IllegalArgumentException("Invalid payload " + payload, e);
    }
}
Also used : MergedAnomalyResultDTO(com.linkedin.thirdeye.datalayer.dto.MergedAnomalyResultDTO) AnomalyFeedbackDTO(com.linkedin.thirdeye.datalayer.dto.AnomalyFeedbackDTO) IOException(java.io.IOException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 2 with AnomalyFeedbackDTO

use of com.linkedin.thirdeye.datalayer.dto.AnomalyFeedbackDTO in project pinot by linkedin.

the class AnomalyResource method updateAnomalyResultFeedback.

@POST
@Path(value = "anomaly-result/feedback/{anomaly_result_id}")
public void updateAnomalyResultFeedback(@PathParam("anomaly_result_id") long anomalyResultId, String payload) {
    try {
        RawAnomalyResultDTO result = rawAnomalyResultDAO.findById(anomalyResultId);
        if (result == null) {
            throw new IllegalArgumentException("AnomalyResult not found with id " + anomalyResultId);
        }
        AnomalyFeedbackDTO feedbackRequest = OBJECT_MAPPER.readValue(payload, AnomalyFeedbackDTO.class);
        AnomalyFeedbackDTO feedback = result.getFeedback();
        if (feedback == null) {
            feedback = new AnomalyFeedbackDTO();
            result.setFeedback(feedback);
        }
        if (feedbackRequest.getStatus() == null) {
            feedback.setStatus(FeedbackStatus.NEW);
        } else {
            feedback.setStatus(feedbackRequest.getStatus());
        }
        feedback.setComment(feedbackRequest.getComment());
        feedback.setFeedbackType(feedbackRequest.getFeedbackType());
        rawAnomalyResultDAO.update(result);
    } catch (IOException e) {
        throw new IllegalArgumentException("Invalid payload " + payload, e);
    }
}
Also used : RawAnomalyResultDTO(com.linkedin.thirdeye.datalayer.dto.RawAnomalyResultDTO) AnomalyFeedbackDTO(com.linkedin.thirdeye.datalayer.dto.AnomalyFeedbackDTO) IOException(java.io.IOException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 3 with AnomalyFeedbackDTO

use of com.linkedin.thirdeye.datalayer.dto.AnomalyFeedbackDTO in project pinot by linkedin.

the class AnomaliesResource method getAnomalyCountForMetricInRange.

/**
   * Get count of anomalies for metric in time range
   * @param metricId
   * @param startTime
   * @param endTime
   * @return
   */
@GET
@Path("getAnomalyCount/{metricId}/{startTime}/{endTime}")
public AnomaliesSummary getAnomalyCountForMetricInRange(@PathParam("metricId") Long metricId, @PathParam("startTime") Long startTime, @PathParam("endTime") Long endTime) {
    AnomaliesSummary anomaliesSummary = new AnomaliesSummary();
    List<MergedAnomalyResultDTO> mergedAnomalies = getAnomaliesForMetricIdInRange(metricId, startTime, endTime);
    int resolvedAnomalies = 0;
    int unresolvedAnomalies = 0;
    for (MergedAnomalyResultDTO mergedAnomaly : mergedAnomalies) {
        AnomalyFeedbackDTO anomalyFeedback = mergedAnomaly.getFeedback();
        if (anomalyFeedback == null || anomalyFeedback.getFeedbackType() == null) {
            unresolvedAnomalies++;
        } else if (anomalyFeedback != null && anomalyFeedback.getFeedbackType() != null && anomalyFeedback.getFeedbackType().equals(AnomalyFeedbackType.ANOMALY)) {
            unresolvedAnomalies++;
        } else {
            resolvedAnomalies++;
        }
    }
    anomaliesSummary.setMetricId(metricId);
    anomaliesSummary.setStartTime(startTime);
    anomaliesSummary.setEndTime(endTime);
    anomaliesSummary.setNumAnomalies(mergedAnomalies.size());
    anomaliesSummary.setNumAnomaliesResolved(resolvedAnomalies);
    anomaliesSummary.setNumAnomaliesUnresolved(unresolvedAnomalies);
    return anomaliesSummary;
}
Also used : AnomaliesSummary(com.linkedin.thirdeye.dashboard.resources.v2.pojo.AnomaliesSummary) MergedAnomalyResultDTO(com.linkedin.thirdeye.datalayer.dto.MergedAnomalyResultDTO) AnomalyFeedbackDTO(com.linkedin.thirdeye.datalayer.dto.AnomalyFeedbackDTO) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 4 with AnomalyFeedbackDTO

use of com.linkedin.thirdeye.datalayer.dto.AnomalyFeedbackDTO in project pinot by linkedin.

the class AlertFilterEvaluationUtil method updatePrecisionAndRecall.

/**
   * Evaluate alert filter given merged anomalies and output precision and recall
   * @param mergedAnomalyResultDTOS
   * @throws Exception
   */
public void updatePrecisionAndRecall(List<MergedAnomalyResultDTO> mergedAnomalyResultDTOS) throws Exception {
    int TP = 0;
    int FP = 0;
    int FN = 0;
    for (MergedAnomalyResultDTO anomaly : mergedAnomalyResultDTOS) {
        boolean predLabel = alertFilter.isQualified(anomaly);
        AnomalyFeedbackDTO feedback = anomaly.getFeedback();
        boolean label = !(feedback == null || feedback.getFeedbackType() == AnomalyFeedbackType.NOT_ANOMALY);
        //predicted true
        if (predLabel) {
            if (label) {
                TP++;
            } else {
                FP++;
            }
        } else if (label) {
            // else if predicted false but label is true
            FN++;
        }
    }
    if (TP + FN == 0) {
        throw new Exception("No true labels in dataset. Check data");
    }
    if (TP + FP == 0) {
        throw new Exception("No predicted true labels. Check model input");
    }
    this.precision = 1.000 * TP / (TP + FP);
    this.recall = 1.000 * TP / (TP + FN);
}
Also used : MergedAnomalyResultDTO(com.linkedin.thirdeye.datalayer.dto.MergedAnomalyResultDTO) AnomalyFeedbackDTO(com.linkedin.thirdeye.datalayer.dto.AnomalyFeedbackDTO)

Example 5 with AnomalyFeedbackDTO

use of com.linkedin.thirdeye.datalayer.dto.AnomalyFeedbackDTO in project pinot by linkedin.

the class AlertFilterEvaluationUtil method updateFeedbackSummary.

/**
   * Provide feedback summary give a list of merged anomalies
   * @param anomalies
   */
public void updateFeedbackSummary(List<MergedAnomalyResultDTO> anomalies) {
    int totalAnomalies = 0;
    int totalResponses = 0;
    int trueAnomalies = 0;
    int falseAlarm = 0;
    int nonActionable = 0;
    for (MergedAnomalyResultDTO anomaly : anomalies) {
        totalAnomalies++;
        // evaluate feedbacks
        AnomalyFeedbackDTO feedback = anomaly.getFeedback();
        if (feedback != null) {
            totalResponses++;
            AnomalyFeedbackType feedbackType = feedback.getFeedbackType();
            switch(feedbackType) {
                case ANOMALY:
                    trueAnomalies++;
                    break;
                case ANOMALY_NO_ACTION:
                    nonActionable++;
                    break;
                case NOT_ANOMALY:
                    falseAlarm++;
                    break;
            }
        }
    }
    this.totalAnomalies = totalAnomalies;
    this.totalResponses = totalResponses;
    this.trueAnomalies = trueAnomalies;
    this.falseAlarm = falseAlarm;
    this.nonActionable = nonActionable;
}
Also used : MergedAnomalyResultDTO(com.linkedin.thirdeye.datalayer.dto.MergedAnomalyResultDTO) AnomalyFeedbackType(com.linkedin.thirdeye.constant.AnomalyFeedbackType) AnomalyFeedbackDTO(com.linkedin.thirdeye.datalayer.dto.AnomalyFeedbackDTO)

Aggregations

AnomalyFeedbackDTO (com.linkedin.thirdeye.datalayer.dto.AnomalyFeedbackDTO)13 MergedAnomalyResultDTO (com.linkedin.thirdeye.datalayer.dto.MergedAnomalyResultDTO)9 AnomalyFunctionDTO (com.linkedin.thirdeye.datalayer.dto.AnomalyFunctionDTO)5 RawAnomalyResultDTO (com.linkedin.thirdeye.datalayer.dto.RawAnomalyResultDTO)5 ArrayList (java.util.ArrayList)4 Path (javax.ws.rs.Path)4 IOException (java.io.IOException)3 POST (javax.ws.rs.POST)3 AnomalyFeedbackBean (com.linkedin.thirdeye.datalayer.pojo.AnomalyFeedbackBean)2 AnomalyFunctionBean (com.linkedin.thirdeye.datalayer.pojo.AnomalyFunctionBean)2 DateTime (org.joda.time.DateTime)2 Test (org.testng.annotations.Test)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 AnomalyFeedbackType (com.linkedin.thirdeye.constant.AnomalyFeedbackType)1 AnomaliesSummary (com.linkedin.thirdeye.dashboard.resources.v2.pojo.AnomaliesSummary)1 RawAnomalyResultBean (com.linkedin.thirdeye.datalayer.pojo.RawAnomalyResultBean)1 GET (javax.ws.rs.GET)1