Ejemplo n.º 1
0
def test_feedback_inserted(sample_feedback):
    """Test inserting events into the fact_store."""
    fact_store = FactStore(True)
    fact_store.session.query(FeedbackModel).delete()
    for feedback in sample_feedback:
        fact_store.write_feedback(**feedback)
    items = fact_store.readall_feedback()
    assert len(items) is 3
Ejemplo n.º 2
0
def test_feedback_inserted():
    """Test inserting events into the fact_store."""
    CUSTOMER_ID = "#123456"
    fact_store = FactStore(True)
    fact_store.session.query(FeedbackModel).delete()
    fact_store.write_feedback(
        predict_id="a2b35c5b-016d-4e2c-8ec5-87d1b962b2f8", message="222JSJSJJS",
        anomaly_status=True, customer_id=CUSTOMER_ID
    )
    fact_store.write_feedback(predict_id="18bd090d-ae27-4b19-a0db-ed5f589b4e2e",
                              customer_id=CUSTOMER_ID, message="SSJJSJS", anomaly_status=True)
    fact_store.write_feedback(predict_id="74a6b1bd-efea-4e7b-87a9-8f7330885160", message="AJJSJS",
                              customer_id=CUSTOMER_ID, anomaly_status=False)
    items = fact_store.readall_feedback()
    assert len(items) is 3
Ejemplo n.º 3
0
def feedback():
    """Feedback Service to provide user input on which false predictions this model provided."""
    try:

        content = request.json
        # When deploying fact_store per customer you should set env var
        customer_id = os.getenv("CUSTOMER_ID")
        logging.info("id: {} ".format(content["lad_id"]))
        logging.info("anomaly: {} ".format(content["is_anomaly"]))
        logging.info("message: {} ".format(content["message"]))
        logging.info("customer_id: {} ".format(customer_id))

        if not content["lad_id"] or not content["is_anomaly"]:
            raise Exception("This service requires that you provide the id" +
                            ", anomaly=True|False and notes are optional ")

        fs = FactStore()
        # Record feedback
        HUMAN_FEEDBACK_COUNT.labels(
            customer_id=customer_id,
            anomaly_status=content["is_anomaly"]).inc()

        # Note id is the prediction id that is found in the email.
        if (fs.write_feedback(predict_id=content["lad_id"],
                              message=content["message"],
                              anomaly_status=bool(content["is_anomaly"]),
                              customer_id=customer_id) is False):
            raise Exception("Predict ID must be unique. This anomaly" +
                            " feedback  has been reported before")
    except Exception as e:
        logging.info(e)
        HUMAN_FEEDBACK_ERROR_COUNT.labels(
            err_msg="failure to write to db in factstore").inc()
        result = {"feedback_service": "failure", "error_msg": "{0}".format(e)}
        return make_response(jsonify(result), 403)
    else:
        result = {"feedback_service": "success"}
        return make_response(jsonify(result), 200)

    return ""
Ejemplo n.º 4
0
def false_positive():
    """Service to provide list of false anomalies to be relabeled during ml training run."""
    fs = FactStore()
    df = fs.readall_false_positive()
    return jsonify({"feedback": df})