Commit b4fed458 authored by root's avatar root
Browse files

fixed paths for socket connections

parent 2b6167a5
......@@ -3,6 +3,7 @@ __pycache__/
/rating
/logs
/app/static/experiment_stimuli
/app/static/embody_drawings/*
cmd.txt
DB_inserts.txt
dumb.sql
......
......@@ -13,7 +13,9 @@ from config import Config
from flask_cors import CORS, cross_origin
app = Flask(__name__)
CORS(app)
#CORS(app, resources={r"/*": {"cors_allowed_origins":"*"} } )
#app.config['BABEL_DEFAULT_LOCALE'] = 'fin'
#app.config['BABEL_TRANSLATION_DIRECTORIES'] ='C:/Users/Timo/git/pet-rating/app/translations'
......@@ -62,6 +64,7 @@ def get_locale():
@babel.localeselector
def get_locale():
return request.accept_languages.best_match(app.config['LANGUAGES'])
"""
......
......@@ -89,7 +89,11 @@
<tbody>
{% for participant in participants_and_answers %}
<tr>
{% if participant == 'mean' %}
<td><b>{{ participant }}</b></td>
{% else %}
<td>{{ participant }}</td>
{% endif %}
{% for answer in participants_and_answers[participant] %}
<td>{{ answer }}</td>
{% endfor %}
......@@ -186,4 +190,4 @@
<script src="{{ url_for('static', filename='lib/js/socket.io.js') }}" ></script>
<script src="{{ url_for('static', filename='js/getDrawing.js') }}" ></script>
{% endblock %}
\ No newline at end of file
{% endblock %}
......@@ -963,35 +963,23 @@ def statistics():
)
def remove_rows(rows):
"""Remove list of rows from database"""
for a in range(len(rows)):
db.session.delete(rows[a])
db.session.commit()
import embody_plot
from flask_cors import CORS,cross_origin
from flask_socketio import emit
from app import socketio
'''
Old method
#@experiment_blueprint.route('/create_embody', methods=['POST'])
#@cross_origin()
def create_embody():
#page = request.args.get("page")
page = request.form["page"]
img_path = embody_plot.get_coordinates(page)
#return send_file('static/' + img_path, 'test')
return json.dumps({'path':img_path})
'''
# (https://flask-socketio.readthedocs.io/en/latest/)
# TODO: Using nginx as a WebSocket Reverse Proxy
# TODO: Gunicorn Web Server
@cross_origin()
@socketio.on('connect', namespace="/create_embody")
def create_embody():
print("connection succesful")
emit('success', {'connection': 'on'})
@cross_origin()
@socketio.on('draw', namespace="/create_embody")
def create_embody(page_id):
page = page_id["page"]
......@@ -1001,18 +989,10 @@ def create_embody(page_id):
print(img_path)
emit('end', {'path':img_path})
'''
@socketio.on('end', namespace="/create_embody")
def create_embody():
print("connection end")
emit('end', {'connection': 'off'})
'''
def remove_rows(rows):
"""Remove list of rows from database"""
for a in range(len(rows)):
db.session.delete(rows[a])
db.session.commit()
# EOF
const baseURI = 'http://127.0.0.1:8000/';
const baseURI = 'http://onni.utu.fi/';
var getDrawingURI = baseURI + 'create_embody';
//var getDrawingURI = baseURI + 'experiment/create_embody';
$(document).ready(function()  {
......@@ -13,6 +12,7 @@ $(document).ready(function()  {
// With sockets
function initConnection(socket) {
socket.on('success', function(msg) {
console.log(msg)
});
......@@ -22,12 +22,13 @@ $(document).ready(function()  {
});
socket.on('end', function(img) {
socket.disconnect()
// Draw image to statistic -page
var source = img.path
d = new Date()
imageContainer.attr("src", "/static/" + source + "?" +d.getTime())
imageContainer.attr("src", "/static/embody_drawings/" + source + "?" +d.getTime())
// Remove progress bar
progressBarContainer.addClass("hidden")
......@@ -77,4 +78,4 @@ $(document).ready(function()  {
}, 500);
}
})
\ No newline at end of file
})
......@@ -37,6 +37,7 @@ from matplotlib.figure import Figure
from flask_socketio import emit
from app import socketio
from config import Config
# Hard coded image size for default embody image
......@@ -46,7 +47,7 @@ HEIGHT = 600
# image paths
DEFAULT_IMAGE_PATH = './app/static/img/dummy_600.png'
IMAGE_PATH_MASK = './app/static/img/dummy_600_mask.png'
STATIC_PATH = './app/static/'
STATIC_PATH = './app/static/embody_drawings/'
# Interpolation methods
METHODS = ['none','bilinear', 'bicubic', 'gaussian']
......@@ -66,7 +67,11 @@ DATE_STRING = now.strftime("%Y-%m-%d")
class MyDB(object):
def __init__(self):
self._db_connection = mariadb.connect(user='rating', password='rating_passwd', database='rating_db')
self._db_connection = mariadb.connect(
user = Config.MYSQL_USER,
password = Config.MYSQL_PASSWORD,
database = Config.MYSQL_DB
)
self._db_cur = self._db_connection.cursor()
def query(self, query, params):
......@@ -110,6 +115,7 @@ def timeit(method):
return timed
import sys
@timeit
def get_coordinates(idpage, idembody=None, select_clause=SELECT_BY_PAGE_AND_PICTURE):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment