From 22c79bb678ceee6d6a06b5c1211145d8957f603f Mon Sep 17 00:00:00 2001 From: Wenbo Tao Date: Wed, 19 Nov 2014 16:53:40 +0800 Subject: [PATCH 1/7] Added javascript code to track worker behaviour. --- .../basecrowd/templates/basecrowd/base.html | 57 ++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/src/main/python/crowd_server/basecrowd/templates/basecrowd/base.html b/src/main/python/crowd_server/basecrowd/templates/basecrowd/base.html index 3f68d05..eeedded 100644 --- a/src/main/python/crowd_server/basecrowd/templates/basecrowd/base.html +++ b/src/main/python/crowd_server/basecrowd/templates/basecrowd/base.html @@ -13,6 +13,14 @@ return $(".label_container :input"); } {% endblock get_answer_inputs_func %} + + {% block get_task_divs_func %} + function get_task_divs() + { + return $(".panel.panel-default"); + } + {% endblock get_task_divs_func%} + {% block validate_func %} function validate_answers() { @@ -32,6 +40,14 @@ return answers; } {% endblock build_answer_data_func %} + + //make metric dictionary + {% block build_metric_data_func %} + function build_metric_data() + { + return {"time" : time}; + } + {% endblock build_metric_data_func %} {% block get_submit_context_func %} function get_submit_context(urlParamStrings) @@ -47,12 +63,15 @@ { // build the user's answers into the right format var answers = build_answer_data(); - + var metrics = build_metric_data(); + // get additional context from the URL or page var paramstr = window.location.search.substring(1); var parampairs = paramstr.split("&"); var data = get_submit_context(parampairs); data.answers = JSON.stringify(answers); + data.metrics = JSON.stringify(metrics); + return data; } {% endblock prepare_submit_data_func %} @@ -86,6 +105,38 @@ } {% endblock handle_is_accepted_func %} + {% block initialize_metric_func %} + function initialize_metric() + { + {% block create_global_variables %} + + // A map that maps task_id to the time the worker spent on it. + time = {} + // The task_id of the task the mouse is currently on, empty if the mouse is outside any task. + focus = ""; + // The update freqency of the setInterval function, in ms. + delay = 10; + + {% endblock %} + + {% Register_event_listeners %} + + // Register a mouseenter event listener for each task divs. + get_task_divs.mouseenter(function(){ + focus = $(this).find(":radio:first").attr("id"); + } + + // Use setInterval to track timing + setInterval(function(){ + if (focus != "") + time[focus] += delay; + ), delay); + + {% endblock %} + + } + {% endblock initialize_metric_func %} + {% block initialize_form_validation_func %} function initialize_form_validation() { @@ -137,6 +188,10 @@ // Prepare form validation initialize_form_validation(); + + // Prepare metric collection + initialize_metric(); + }); {% endblock ready_func %} From 6738c7dc397d1d055c67d56d8e0d0cd11ca17ac0 Mon Sep 17 00:00:00 2001 From: Wenbo Tao Date: Wed, 19 Nov 2014 16:59:28 +0800 Subject: [PATCH 2/7] Change Tab to spaces. --- .../python/crowd_server/basecrowd/templates/basecrowd/base.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/python/crowd_server/basecrowd/templates/basecrowd/base.html b/src/main/python/crowd_server/basecrowd/templates/basecrowd/base.html index eeedded..b6b03e4 100644 --- a/src/main/python/crowd_server/basecrowd/templates/basecrowd/base.html +++ b/src/main/python/crowd_server/basecrowd/templates/basecrowd/base.html @@ -13,7 +13,7 @@ return $(".label_container :input"); } {% endblock get_answer_inputs_func %} - + {% block get_task_divs_func %} function get_task_divs() { From 9f539f0c249e270932c7bf29036c9d3da01e692e Mon Sep 17 00:00:00 2001 From: Wenbo Tao Date: Wed, 19 Nov 2014 17:01:19 +0800 Subject: [PATCH 3/7] Change Tab to spaces again. --- .../basecrowd/templates/basecrowd/base.html | 122 +++++++++--------- 1 file changed, 61 insertions(+), 61 deletions(-) diff --git a/src/main/python/crowd_server/basecrowd/templates/basecrowd/base.html b/src/main/python/crowd_server/basecrowd/templates/basecrowd/base.html index b6b03e4..a8b12e6 100644 --- a/src/main/python/crowd_server/basecrowd/templates/basecrowd/base.html +++ b/src/main/python/crowd_server/basecrowd/templates/basecrowd/base.html @@ -14,13 +14,13 @@ } {% endblock get_answer_inputs_func %} - {% block get_task_divs_func %} - function get_task_divs() - { - return $(".panel.panel-default"); - } - {% endblock get_task_divs_func%} - + {% block get_task_divs_func %} + function get_task_divs() + { + return $(".panel.panel-default"); + } + {% endblock get_task_divs_func%} + {% block validate_func %} function validate_answers() { @@ -40,14 +40,14 @@ return answers; } {% endblock build_answer_data_func %} - - //make metric dictionary - {% block build_metric_data_func %} - function build_metric_data() - { - return {"time" : time}; - } - {% endblock build_metric_data_func %} + + //make metric dictionary + {% block build_metric_data_func %} + function build_metric_data() + { + return {"time" : time}; + } + {% endblock build_metric_data_func %} {% block get_submit_context_func %} function get_submit_context(urlParamStrings) @@ -63,15 +63,15 @@ { // build the user's answers into the right format var answers = build_answer_data(); - var metrics = build_metric_data(); - + var metrics = build_metric_data(); + // get additional context from the URL or page var paramstr = window.location.search.substring(1); var parampairs = paramstr.split("&"); var data = get_submit_context(parampairs); data.answers = JSON.stringify(answers); - data.metrics = JSON.stringify(metrics); - + data.metrics = JSON.stringify(metrics); + return data; } {% endblock prepare_submit_data_func %} @@ -105,38 +105,38 @@ } {% endblock handle_is_accepted_func %} - {% block initialize_metric_func %} - function initialize_metric() - { - {% block create_global_variables %} - - // A map that maps task_id to the time the worker spent on it. - time = {} - // The task_id of the task the mouse is currently on, empty if the mouse is outside any task. - focus = ""; - // The update freqency of the setInterval function, in ms. - delay = 10; - - {% endblock %} - - {% Register_event_listeners %} - - // Register a mouseenter event listener for each task divs. - get_task_divs.mouseenter(function(){ - focus = $(this).find(":radio:first").attr("id"); - } - - // Use setInterval to track timing - setInterval(function(){ - if (focus != "") - time[focus] += delay; - ), delay); - - {% endblock %} - - } - {% endblock initialize_metric_func %} - + {% block initialize_metric_func %} + function initialize_metric() + { + {% block create_global_variables %} + + // A map that maps task_id to the time the worker spent on it. + time = {} + // The task_id of the task the mouse is currently on, empty if the mouse is outside any task. + focus = ""; + // The update freqency of the setInterval function, in ms. + delay = 10; + + {% endblock %} + + {% Register_event_listeners %} + + // Register a mouseenter event listener for each task divs. + get_task_divs.mouseenter(function(){ + focus = $(this).find(":radio:first").attr("id"); + } + + // Use setInterval to track timing + setInterval(function(){ + if (focus != "") + time[focus] += delay; + ), delay); + + {% endblock %} + + } + {% endblock initialize_metric_func %} + {% block initialize_form_validation_func %} function initialize_form_validation() { @@ -188,10 +188,10 @@ // Prepare form validation initialize_form_validation(); - - // Prepare metric collection - initialize_metric(); - + + // Prepare metric collection + initialize_metric(); + }); {% endblock ready_func %} @@ -234,15 +234,15 @@
{% block instruction %} - {% if group_context.instruction %} - {{group_context.instruction | safe}} - {% else %} - {% block default_instruction %} - Hey, I am an instruction! + {% if group_context.instruction %} + {{group_context.instruction | safe}} + {% else %} + {% block default_instruction %} + Hey, I am an instruction! {% endblock %} {% endif %} - {% endblock %} + {% endblock %}
{% endblock instruction_panel %} From 6e63fc8404668e14789dc7772889f09017761678 Mon Sep 17 00:00:00 2001 From: Wenbo Tao Date: Wed, 19 Nov 2014 10:47:42 +0000 Subject: [PATCH 4/7] Tweak in base.html. --- .../basecrowd/templates/basecrowd/base.html | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/main/python/crowd_server/basecrowd/templates/basecrowd/base.html b/src/main/python/crowd_server/basecrowd/templates/basecrowd/base.html index a8b12e6..175e691 100644 --- a/src/main/python/crowd_server/basecrowd/templates/basecrowd/base.html +++ b/src/main/python/crowd_server/basecrowd/templates/basecrowd/base.html @@ -64,6 +64,7 @@ // build the user's answers into the right format var answers = build_answer_data(); var metrics = build_metric_data(); + alert(JSON.stringify(metrics)); // get additional context from the URL or page var paramstr = window.location.search.substring(1); @@ -71,7 +72,8 @@ var data = get_submit_context(parampairs); data.answers = JSON.stringify(answers); data.metrics = JSON.stringify(metrics); - + alert(data); + return data; } {% endblock prepare_submit_data_func %} @@ -118,20 +120,25 @@ delay = 10; {% endblock %} - - {% Register_event_listeners %} + alert("created global variables"); + {% block Register_event_listeners %} // Register a mouseenter event listener for each task divs. - get_task_divs.mouseenter(function(){ + get_task_divs().mouseenter(function(){ focus = $(this).find(":radio:first").attr("id"); - } - + alert(focus); + }); + alert("mouseenter listener set up"); // Use setInterval to track timing setInterval(function(){ if (focus != "") - time[focus] += delay; - ), delay); - + if (focus in time) + time[focus] += delay; + else + time[focus] = delay; + }, delay); + alert("setInterval"); + {% endblock %} } @@ -171,6 +178,7 @@ {% block ready_func %} $(document).ready(function() { + alert("haha"); // Make sure to send data to our backend when the user submits $("#submitButton").click(function(event) { @@ -191,7 +199,7 @@ // Prepare metric collection initialize_metric(); - + alert("metric preparation finished!"); }); {% endblock ready_func %} From 3b1941f8842b434797cde4eefba2e3374ce987c3 Mon Sep 17 00:00:00 2001 From: Wenbo Tao Date: Wed, 19 Nov 2014 11:55:53 +0000 Subject: [PATCH 5/7] Modified Django models to store metrics --- src/main/python/crowd_server/amt/interface.py | 1 + src/main/python/crowd_server/basecrowd/interface.py | 3 ++- src/main/python/crowd_server/basecrowd/models.py | 3 +++ .../crowd_server/basecrowd/templates/basecrowd/base.html | 2 +- src/main/python/crowd_server/basecrowd/views.py | 3 ++- 5 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/python/crowd_server/amt/interface.py b/src/main/python/crowd_server/amt/interface.py index 9b379f9..b26261d 100644 --- a/src/main/python/crowd_server/amt/interface.py +++ b/src/main/python/crowd_server/amt/interface.py @@ -72,6 +72,7 @@ def get_assignment_context(request): def get_response_context(request): # Extract data from the request return {'answers': request.POST.get('answers'), + 'metrics': request.POST.get('metrics'), 'task_id': request.POST.get('HITId'), 'worker_id': request.POST.get('workerId'), 'assignment_id': request.POST.get('assignmentId') diff --git a/src/main/python/crowd_server/basecrowd/interface.py b/src/main/python/crowd_server/basecrowd/interface.py index 7e0c5eb..fdecbd9 100644 --- a/src/main/python/crowd_server/basecrowd/interface.py +++ b/src/main/python/crowd_server/basecrowd/interface.py @@ -114,7 +114,8 @@ def get_response_context(request): return {'task_id': request.POST.get('task_id', None), 'worker_id': request.POST.get('worker_id', None), 'assignment_id': request.POST.get('assignment_id', None), - 'answers': request.POST.get('answers', None) + 'answers': request.POST.get('answers', None), + 'metrics': request.POST.get('metrics', None) } diff --git a/src/main/python/crowd_server/basecrowd/models.py b/src/main/python/crowd_server/basecrowd/models.py index 3c4e93b..7151c38 100644 --- a/src/main/python/crowd_server/basecrowd/models.py +++ b/src/main/python/crowd_server/basecrowd/models.py @@ -102,6 +102,9 @@ class AbstractCrowdWorkerResponse(models.Model): # The content of the response (specific to the task type). content = models.TextField() + # The content of recorded experimental metrics + metrics = models.TextField() + # The assignment id of this response assignment_id = models.CharField(max_length=200) diff --git a/src/main/python/crowd_server/basecrowd/templates/basecrowd/base.html b/src/main/python/crowd_server/basecrowd/templates/basecrowd/base.html index 175e691..27c3d37 100644 --- a/src/main/python/crowd_server/basecrowd/templates/basecrowd/base.html +++ b/src/main/python/crowd_server/basecrowd/templates/basecrowd/base.html @@ -72,7 +72,7 @@ var data = get_submit_context(parampairs); data.answers = JSON.stringify(answers); data.metrics = JSON.stringify(metrics); - alert(data); + alert(JSON.stringify(data)); return data; } diff --git a/src/main/python/crowd_server/basecrowd/views.py b/src/main/python/crowd_server/basecrowd/views.py index 1db0e64..3686a30 100644 --- a/src/main/python/crowd_server/basecrowd/views.py +++ b/src/main/python/crowd_server/basecrowd/views.py @@ -178,7 +178,7 @@ def post_response(request, crowd_name): # validate context interface.require_context( - context, ['assignment_id', 'task_id', 'worker_id', 'answers'], + context, ['assignment_id', 'task_id', 'worker_id', 'answers', 'metrics'], ValueError("Response context missing required keys.")) # Check if this is a duplicate response @@ -196,6 +196,7 @@ def post_response(request, crowd_name): task=current_task, worker=current_worker, content=context['answers'], + metrics=context['metrics'], assignment_id=context['assignment_id']) interface.response_pre_save(current_response) current_response.save() From 888af75c70a22b482f082b18297a26d3ea882176 Mon Sep 17 00:00:00 2001 From: Wenbo Tao Date: Wed, 19 Nov 2014 20:02:34 +0800 Subject: [PATCH 6/7] Removed several debug alerts. --- .../basecrowd/templates/basecrowd/base.html | 55 +++++++++---------- 1 file changed, 25 insertions(+), 30 deletions(-) diff --git a/src/main/python/crowd_server/basecrowd/templates/basecrowd/base.html b/src/main/python/crowd_server/basecrowd/templates/basecrowd/base.html index 27c3d37..4ebc974 100644 --- a/src/main/python/crowd_server/basecrowd/templates/basecrowd/base.html +++ b/src/main/python/crowd_server/basecrowd/templates/basecrowd/base.html @@ -64,7 +64,6 @@ // build the user's answers into the right format var answers = build_answer_data(); var metrics = build_metric_data(); - alert(JSON.stringify(metrics)); // get additional context from the URL or page var paramstr = window.location.search.substring(1); @@ -110,34 +109,32 @@ {% block initialize_metric_func %} function initialize_metric() { - {% block create_global_variables %} - - // A map that maps task_id to the time the worker spent on it. - time = {} - // The task_id of the task the mouse is currently on, empty if the mouse is outside any task. - focus = ""; - // The update freqency of the setInterval function, in ms. - delay = 10; - + {% block create_global_variables %} + + // A map that maps task_id to the time the worker spent on it. + time = {} + // The task_id of the task the mouse is currently on, empty if the mouse is outside any task. + focus = ""; + // The update freqency of the setInterval function, in ms. + delay = 10; + {% endblock %} - alert("created global variables"); - {% block Register_event_listeners %} - - // Register a mouseenter event listener for each task divs. - get_task_divs().mouseenter(function(){ - focus = $(this).find(":radio:first").attr("id"); - alert(focus); - }); - alert("mouseenter listener set up"); - // Use setInterval to track timing - setInterval(function(){ - if (focus != "") - if (focus in time) - time[focus] += delay; - else - time[focus] = delay; - }, delay); - alert("setInterval"); + + {% block Register_event_listeners %} + + // Register a mouseenter event listener for each task divs. + get_task_divs().mouseenter(function(){ + focus = $(this).find(":radio:first").attr("id"); + }); + + // Use setInterval to track timing + setInterval(function(){ + if (focus != "") + if (focus in time) + time[focus] += delay; + else + time[focus] = delay; + }, delay); {% endblock %} @@ -178,7 +175,6 @@ {% block ready_func %} $(document).ready(function() { - alert("haha"); // Make sure to send data to our backend when the user submits $("#submitButton").click(function(event) { @@ -199,7 +195,6 @@ // Prepare metric collection initialize_metric(); - alert("metric preparation finished!"); }); {% endblock ready_func %} From 4ce3277b8a648b0d080d0d6110351d264c5b827a Mon Sep 17 00:00:00 2001 From: Wenbo Tao Date: Wed, 19 Nov 2014 12:27:44 +0000 Subject: [PATCH 7/7] Removed the last alert. --- .../crowd_server/basecrowd/templates/basecrowd/base.html | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/python/crowd_server/basecrowd/templates/basecrowd/base.html b/src/main/python/crowd_server/basecrowd/templates/basecrowd/base.html index 4ebc974..f40a5f5 100644 --- a/src/main/python/crowd_server/basecrowd/templates/basecrowd/base.html +++ b/src/main/python/crowd_server/basecrowd/templates/basecrowd/base.html @@ -71,8 +71,7 @@ var data = get_submit_context(parampairs); data.answers = JSON.stringify(answers); data.metrics = JSON.stringify(metrics); - alert(JSON.stringify(data)); - + return data; } {% endblock prepare_submit_data_func %}