Commit 2b6167a5 authored by Ossi Laine's avatar Ossi Laine
Browse files

Responsive experiment handling

parent 951b39f3
......@@ -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
......
......@@ -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]
......
......@@ -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
......@@ -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) {
......
......@@ -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">
......
......@@ -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
......
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