From c21c9bd936bd900c2d7c8aaca74f674f47f763e0 Mon Sep 17 00:00:00 2001 From: osmala <ossi.laine@utu.fi> Date: Wed, 10 Jun 2020 11:45:52 +0300 Subject: [PATCH] Fixed socket connection in embody genration --- app/experiment/views.py | 8 +++++++- embody_plot.py | 22 +++++++++++++++------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/app/experiment/views.py b/app/experiment/views.py index d365138..46d148c 100644 --- a/app/experiment/views.py +++ b/app/experiment/views.py @@ -950,6 +950,8 @@ def statistics(): questions = question.query.filter_by(experiment_idexperiment=exp_id).all() pages_and_questions = {} + ''' + for p in pages: questions_list = [(p.idpage, a.idquestion) for a in questions] pages_and_questions[p.idpage] = questions_list @@ -979,9 +981,13 @@ def statistics(): # slider_answers['mean'] = get_mean_from_slider_answers(slider_answers) slider_answers = { - 'mean': mean + 'mean': mean } + ''' + + slider_answers = {} + # Background question answers bg_questions = background_question.query.filter_by( experiment_idexperiment=exp_id).all() diff --git a/embody_plot.py b/embody_plot.py index cd74f0b..169587b 100644 --- a/embody_plot.py +++ b/embody_plot.py @@ -183,6 +183,7 @@ def plot_coordinates(coordinates, image_path=DEFAULT_IMAGE_PATH): # Total amount of points points_count = len(coordinates['coordinates']) + step = 1 # Load image to a plot image = mpimg.imread(image_path) @@ -205,21 +206,28 @@ def plot_coordinates(coordinates, image_path=DEFAULT_IMAGE_PATH): for idx, point in enumerate(coordinates["coordinates"]): try: - frame[int(point[1]), int(point[0])] = 1 + frame[int(point[1]), int(point[0])] = 1 except IndexError as err: - app.logger.info(err) + app.logger.info(err) point = ndimage.gaussian_filter(frame, sigma=5) ax2.imshow(point, cmap='hot', interpolation='none') # Try to send progress information to socket.io - try: - emit('progress', {'done':idx+1/points_count, 'from':points_count}) - socketio.sleep(0) - except RuntimeError as err: - print(err) + + if idx == 0: continue + if round((idx / points_count) * 100) % (step * 5) == 0: + try: + emit('progress', {'done':step * 5, 'from':100}) + socketio.sleep(0.05) + except RuntimeError as err: + print(err) + continue + + step += 1 + image_mask = mpimg.imread(IMAGE_PATH_MASK) ax2.imshow(image_mask) -- GitLab