Commit 6f7883ab authored by Chris's avatar Chris
Browse files

Started functions to make partial train buttons do something

parent ed1eaa8d
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@ def display_greeting():
# Endpoint to load js files
@app.route('/js/main.js')
def get_script():
    doctype = 'application/js'
    doctype = 'text/js'
    return send_from_directory('web/js', 'main.js', mimetype=doctype)

# Return the prediction label to the frontend
+2 −2
Original line number Diff line number Diff line
@@ -16,8 +16,8 @@
            <p>Is it spam or ham? <button onclick="getPrediction()">Find out!</button> </p>
            <p id="prediction"></p>
            <p>Is this prediction correct?</p>
            <button id="report_ham">This is actually a ham!</button>
            <button id="report_spam">This is actually a spam!</button>
            <button id="report_ham" onclick="correctPrediction('ham')">This is actually a ham!</button>
            <button id="report_spam" onclick="correctPrediction('spam')">This is actually a spam!</button>
            <button id="clear" onclick="clearIndex()">Clear</button>
        </div>
        <br>
+33 −0
Original line number Diff line number Diff line

// todo fix this to actually send the message data
function getPrediction() {
    var url = "http://localhost:8080"
    var endpoint = "/predict"
@@ -25,6 +26,38 @@ function getPrediction() {
    }
}

// todo fix this to actually send the message data
function correctPrediction(correctLabel) {
    // debug
    var message = document.getElementById('message').value;
    console.log(message + " is " + correctLabel);

    // starter code
    var url = "http://localhost:8080"
    var endpoint = "/correctPrediction"

    var http = new XMLHttpRequest();

    http.open("GET", url + endpoint, true);

    http.onreadystatechange = function() {
        var DONE = 4;       // 4 means that the request is done
        var OK = 200;       // 200 means a successful return
        if (http.readyState == DONE && http.status == OK && http.responseText) {
            // JSON string
            replyString = http.responseText;

            // JSON -> JS obj
            replyObj = JSON.parse(replyString);

            document.getElementById("prediction").innerText = replyObj.prediction;  // signifies that we need a string called prediction from the backend
        }
        else {
            console.log("Error correcting prediction from the backend server. (Is it running?)");
        }
    }
}

function getTopFiveAlgorithms() {
    var url = "http://localhost:8080"
    var endpoint = "/getAlgorithms"