diff --git a/app/experiment/views.py b/app/experiment/views.py index c3d925315270f262d982e02f9e8c58e69d08c673..5f8c952520299d2adaf498eb90b0064dfa557146 100644 --- a/app/experiment/views.py +++ b/app/experiment/views.py @@ -927,7 +927,7 @@ def statistics(): # map slider_answers from str to int and calculate mean a = [map(int,i) for i in list(slider_answers.values())] - slider_answers['mean'] = [float(sum(l))/len(l) for l in zip(*a)] + slider_answers['mean'] = [round(float(sum(l))/len(l), 2) for l in zip(*a)] #Background question answers diff --git a/app/routes.py b/app/routes.py index da3705edce18427fe45f003f14b93f24f9725807..ada9a29402d470cecb2406d09ace7dc181e4d0b3 100644 --- a/app/routes.py +++ b/app/routes.py @@ -372,14 +372,14 @@ def download_csv(): # create CSV-header header = 'participant id;' - header += ';'.join([str(count) +'. bg_question: '+ question.background_question for count,question in enumerate(bg_questions, 1)]) + header += ';'.join([str(count) +'. bg_question: '+ question.background_question.strip() for count,question in enumerate(bg_questions, 1)]) for idx in range(1,len(pages) + 1): if len(questions) > 0: - header += ';' + ';'.join(['page' + str(idx) + '_' + str(count) +'. slider_question: ' + question.question for count,question in enumerate(questions, 1)]) + header += ';' + ';'.join(['page' + str(idx) + '_' + str(count) +'. slider_question: ' + question.question.strip() for count,question in enumerate(questions, 1)]) for idx in range(1,len(pages) + 1): if len(embody_questions) > 0: - header += ';' + ';'.join(['page' + str(idx) + '_' + str(count) +'. embody_question: '+ question.picture for count,question in enumerate(embody_questions, 1)]) + header += ';' + ';'.join(['page' + str(idx) + '_' + str(count) +'. embody_question: '+ question.picture.strip() for count,question in enumerate(embody_questions, 1)]) csv += header + '\r\n' answer_row = '' @@ -414,8 +414,7 @@ def download_csv(): for point in list(zip( embody_answer_data['x'], embody_answer_data['y'])): coordinates_to_bitmap[point[0]][point[1]] += 0.1 - answers_list.append('hello') - #answers_list.append(json.dumps(coordinates_to_bitmap)) + answers_list.append(json.dumps(coordinates_to_bitmap)) # old way to save only visited points: # answers_list = [ json.dumps(list(zip( json.loads(a.coordinates)['x'], json.loads(a.coordinates)['y']))) for a in embody_answers] diff --git a/app/static/css/main.css b/app/static/css/main.css index c9296490b9522ef7efd00054efc0567fa27a87b8..eeb85710389fc8101bdd970f30d073288b47bf9d 100644 --- a/app/static/css/main.css +++ b/app/static/css/main.css @@ -14,7 +14,7 @@ body { display: block; margin: 0 auto; margin-bottom: 30px; - + max-width: 100%; } .clear-button { @@ -63,3 +63,16 @@ body { .thumbnail { max-height: 100px; } + +.embody-question { + text-align: center; +} + + +@media (max-width: 600px) { + + .stimulus { + max-width: 90%; + } + +} \ No newline at end of file diff --git a/app/static/js/canvas.js b/app/static/js/canvas.js index 5cc87d247cd26737b4f0bf0a5c15bc20f133548d..0f8bf30e0a0979f4382582f4b61dd213899dc957 100644 --- a/app/static/js/canvas.js +++ b/app/static/js/canvas.js @@ -26,6 +26,7 @@ $(document).ready(function()Â { //var oldimg = document.getElementById("baseImage"); var img = $('.embody-image.selected-embody')[0] + var instruction = $('.embody-question.selected-embody')[0] img.onload = function()Â { drawImage() @@ -82,6 +83,9 @@ $(document).ready(function()Â { e.preventDefault() var mouseX = e.touches[0].pageX - this.offsetLeft; var mouseY = e.touches[0].pageY - this.offsetTop; + + [mouseX, mouseY] = scaleClickCoordinates($(this)[0], mouseX, mouseY) + if (paint && pointInsideBaseImage([mouseX, mouseY])){ addClick(mouseX, mouseY, true); redraw(); @@ -93,12 +97,30 @@ $(document).ready(function()Â { var mouseX = e.touches[0].pageX - this.offsetLeft; var mouseY = e.touches[0].pageY - this.offsetTop; paint = true; + + [mouseX, mouseY] = scaleClickCoordinates($(this)[0], mouseX, mouseY) + if (pointInsideBaseImage([mouseX, mouseY])) { addClick(mouseX, mouseY); redraw(); } }); + function scaleClickCoordinates(element, x, y) { + var clientHeight = element.clientHeight; + var trueHeight = element.height + var clientWidth = element.clientWidth; + var trueWidth = element.width + + if (clientHeight !== trueHeight) { + y = y * (trueHeight / clientHeight) + x = x * (trueWidth / clientWidth) + } + + return [x,y] + + }; + canvas.mouseup(function(e){ paint = false; }); @@ -173,6 +195,9 @@ $(document).ready(function()Â { // Show next picture img = img.nextElementSibling + $(instruction).addClass("hidden") + $(instruction.nextElementSibling).removeClass("hidden") + try { drawImage() } catch(e) { diff --git a/app/task/templates/task.html b/app/task/templates/task.html index 622f199961baef2ca8425ef0ae98b4797fccaae0..6e322ac105947dda8ac4796a6fa3e6fcf0b086b9 100644 --- a/app/task/templates/task.html +++ b/app/task/templates/task.html @@ -90,19 +90,21 @@ <!-- Select form type --> - page num: {{page_num}} <br> - {% if form.__name__ == 'embody' %} <div class="canvas-container"> <span class="canvas-info"></span> <canvas id="embody-canvas" class="crosshair" width="20" height="20" style="border: 1px solid blue;" ></canvas> + </div> {% for embody_question in embody_questions %} <img id="idembody-{{embody_question.idembody}}" class="embody-image {% if loop.last %}last-embody{% endif %} {% if loop.index != 1 %}hidden{% else %}selected-embody{% endif %}" src={{ embody_question.picture }} /> {% endfor %} + {% for embody_question in embody_questions %} + <p id="idquestion-{{ embody_question.idembody }}" class="embody-question {% if loop.index != 1 %}hidden{% else %}selected-embody{% endif %}"> {{ embody_question.question }}</p> + {% endfor %} <img id="baseImageMask" class="hidden" src={{ url_for('static', filename='img/dummy_600_mask.png') }} /> @@ -113,8 +115,10 @@ <input id="canvas-data" type="hidden" value="" name="coordinates"> - <div class="row justify-content-md-center"> - <button type="button" class="btn btn-primary clear-button">Clear</button> + <div class="form-row text-center"> + <div class="centered col-12"> + <button type="button" class="btn btn-primary clear-button">Clear</button> + </div> </div> <div class="form-row text-center"> diff --git a/requirements.txt b/requirements.txt index aa01c65b14a53c72103b395363501e5bb51eaaa9..b16b64a57e0eab8546e4b50f4ab5855fef2faaca 100644 --- a/requirements.txt +++ b/requirements.txt @@ -32,7 +32,6 @@ mysql-connector==2.2.9 networkx==2.2 numpy==1.16.2 Pillow==6.0.0 -pkg-resources==0.0.0 ply==3.11 pycodestyle==2.5.0 pyexcel==0.5.9.1