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);
}
}
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);
}
}
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;
}
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);
}
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;
}
Aggregations