miguelgfierro / ai_projects

AI projects
https://miguelgfierro.com/
Other
773 stars 175 forks source link

Images not refreshing with websocket and amcharts #88

Closed miguelgfierro closed 5 years ago

miguelgfierro commented 6 years ago

The way to add a new image is: map.dataProvider.images.push(newLocation);.

Still there is an error because when doing:

socket.on("map_update", function (msg) {  
    console.log(msg.title);
    console.log(msg.latitude);
    console.log(typeof msg.latitude);
    newLocation = new Location(msg.title, msg.latitude, msg.longitude);
    map.dataProvider.images.push(newLocation);
    map.validateData(); //call to redraw the map with new data
});

and calling the API:

@app.route('/predict_map', methods=['POST'])
def predict_map():
    X = manage_query(request)
    y_pred = model.predict(X)[0]
    row = select_random_row(conn, TABLE_LOCATIONS)
    location = {"title": row[0], "latitude": row[1], "longitude": row[2]}
    socketio.emit('map_update', location, broadcast=True)

I don't see any logs

miguelgfierro commented 6 years ago

https://www.amcharts.com/kbase/real-time-data-updates-using-websockets/

miguelgfierro commented 6 years ago

"dataProvider": { "map": "worldLow", "images": [ { "latitude": 40.3951, "longitude": -73.5619, "type": "circle", "color": "#6c00ff" } ] }

https://www.amcharts.com/kbase/your-first-ammap/

miguelgfierro commented 6 years ago

There is something odd happening, if I remove everything and just leave in JS:

    // Handler for health signal
    socket.on("health_signal", function (msg) {
        console.log("Response from server: " + msg.data + " (note: " + msg.note + ")");
    });

and in python:

# Health end point
@app.route('/health')
def health_check():
    socketio.emit('health_signal',
                  {'data': 'HEALTH CHECK', 'note': 'OK'},
                  broadcast=True)
    return make_response(jsonify({'health': 'OK'}), STATUS_OK)

in the browser I don't see the logs. I have to start from scratch just with the health point in python and JS, and then build up from there