Search in sources :

Example 11 with AnomalyFeedbackDTO

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

the class TestAlertFilterUtil method getMockMergedAnomalies.

private List<MergedAnomalyResultDTO> getMockMergedAnomalies(int posIdx, int negIdx) {
    List<MergedAnomalyResultDTO> anomalyResultDTOS = new ArrayList<>();
    int[] ws = { 1, 1, 2, 3, 4, 4, 5, 6, 7 };
    double[] severity = { 2.0, 4.0, 2.0, 3.0, 1.0, 3.0, 2.0, 1.0, 3.0 };
    AnomalyFeedbackDTO positiveFeedback = new AnomalyFeedbackDTO();
    AnomalyFeedbackDTO negativeFeedback = new AnomalyFeedbackDTO();
    positiveFeedback.setFeedbackType(ANOMALY);
    negativeFeedback.setFeedbackType(NOT_ANOMALY);
    for (int i = 0; i < ws.length; i++) {
        MergedAnomalyResultDTO anomaly = new MergedAnomalyResultDTO();
        anomaly.setStartTime(0l);
        anomaly.setEndTime(ws[i] * 3600 * 1000l);
        anomaly.setWeight(severity[i]);
        if (i == posIdx) {
            anomaly.setFeedback(positiveFeedback);
        } else if (i == negIdx) {
            anomaly.setFeedback(negativeFeedback);
        } else {
            anomaly.setFeedback(null);
        }
        anomalyResultDTOS.add(anomaly);
    }
    return anomalyResultDTOS;
}
Also used : MergedAnomalyResultDTO(com.linkedin.thirdeye.datalayer.dto.MergedAnomalyResultDTO) ArrayList(java.util.ArrayList) AnomalyFeedbackDTO(com.linkedin.thirdeye.datalayer.dto.AnomalyFeedbackDTO)

Example 12 with AnomalyFeedbackDTO

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

the class TestAnomalyResultManager method testResultFeedback.

@Test(dependsOnMethods = { "testAnomalyResultCRUD" })
public void testResultFeedback() {
    RawAnomalyResultDTO result = rawAnomalyResultDAO.findById(anomalyResult.getId());
    Assert.assertNotNull(result);
    Assert.assertNull(result.getFeedback());
    AnomalyFeedbackDTO feedback = new AnomalyFeedbackDTO();
    feedback.setComment("this is a good find");
    feedback.setFeedbackType(AnomalyFeedbackType.ANOMALY);
    feedback.setStatus(FeedbackStatus.NEW);
    result.setFeedback(feedback);
    rawAnomalyResultDAO.save(result);
    RawAnomalyResultDTO resultRet = rawAnomalyResultDAO.findById(anomalyResult.getId());
    Assert.assertEquals(resultRet.getId(), result.getId());
    Assert.assertNotNull(resultRet.getFeedback());
    AnomalyFunctionDTO functionSpec = result.getFunction();
    rawAnomalyResultDAO.deleteById(anomalyResult.getId());
    anomalyFunctionDAO.deleteById(functionSpec.getId());
}
Also used : RawAnomalyResultDTO(com.linkedin.thirdeye.datalayer.dto.RawAnomalyResultDTO) AnomalyFeedbackDTO(com.linkedin.thirdeye.datalayer.dto.AnomalyFeedbackDTO) AnomalyFunctionDTO(com.linkedin.thirdeye.datalayer.dto.AnomalyFunctionDTO) Test(org.testng.annotations.Test)

Example 13 with AnomalyFeedbackDTO

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

the class AnomaliesResource method updateAnomalyMergedResultFeedback.

/**
   * Update anomaly feedback
   * @param mergedAnomalyId : mergedAnomalyId
   * @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 = "/updateFeedback/{mergedAnomalyId}")
public void updateAnomalyMergedResultFeedback(@PathParam("mergedAnomalyId") long mergedAnomalyId, String payload) {
    try {
        MergedAnomalyResultDTO result = mergedAnomalyResultDAO.findById(mergedAnomalyId);
        if (result == null) {
            throw new IllegalArgumentException("AnomalyResult not found with id " + mergedAnomalyId);
        }
        AnomalyFeedbackDTO feedback = result.getFeedback();
        if (feedback == null) {
            feedback = new AnomalyFeedbackDTO();
            result.setFeedback(feedback);
        }
        AnomalyFeedbackDTO feedbackRequest = new ObjectMapper().readValue(payload, AnomalyFeedbackDTO.class);
        if (feedbackRequest.getStatus() == null) {
            feedback.setStatus(FeedbackStatus.NEW);
        } else {
            feedback.setStatus(feedbackRequest.getStatus());
        }
        feedback.setComment(feedbackRequest.getComment());
        feedback.setFeedbackType(feedbackRequest.getFeedbackType());
        mergedAnomalyResultDAO.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) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

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