-
Notifications
You must be signed in to change notification settings - Fork 26
Track worker behaviour(timing for now) #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
22c79bb
6738c7d
9f539f0
6e63fc8
3b1941f
888af75
4ce3277
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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,41 @@ | |
| } | ||
| {% 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 = {} | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Theoretically we could store any metric in here, right? No reason to limit the metrics to task_ids and timings... a map from 'metric_name' to 'metric_value' is all we need. |
||
| // 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 %} | ||
|
|
||
| {% 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(){ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This feels like an odd implementation choice. You're already using mouseenter event listeners to track focus, why not just track timing inside the event functions? For example, on mouseenter, record the focus and the timestamp at which the focus started, and on mouseleave, take a new timestamp and determine how long the focus was held. In general, setInterval is a pretty ugly solution, as it constantly churns the CPU even when the user isn't doing anything. |
||
| if (focus != "") | ||
| if (focus in time) | ||
| time[focus] += delay; | ||
| else | ||
| time[focus] = delay; | ||
| }, delay); | ||
|
|
||
| {% endblock %} | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We also might as well record total time on the page here, right? I don't think it's necessarily the sum of all the values in the |
||
|
|
||
| } | ||
| {% endblock initialize_metric_func %} | ||
|
|
||
| {% block initialize_form_validation_func %} | ||
| function initialize_form_validation() | ||
| { | ||
|
|
@@ -137,6 +191,9 @@ | |
|
|
||
| // Prepare form validation | ||
| initialize_form_validation(); | ||
|
|
||
| // Prepare metric collection | ||
| initialize_metric(); | ||
| }); | ||
| {% endblock ready_func %} | ||
| </script> | ||
|
|
@@ -179,15 +236,15 @@ | |
| <div class="panel-body"> | ||
| {% 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 %} | ||
| </div> | ||
| </div> | ||
| {% endblock instruction_panel %} | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I wonder if we should normalize metrics as their own model, since we might want to query over them (e.g. 'get the average response time per task grouped by task type').
What do you think? Is there a reason you chose to keep it as denormalized JSON here?