Skip to content

Commit

Permalink
Rolled out JavaScript-based computation of durations for error classi…
Browse files Browse the repository at this point in the history
…fication and post-editing tasks.
  • Loading branch information
Christian Federmann committed Mar 19, 2012
1 parent d3b4948 commit 9b02f52
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 30 deletions.
34 changes: 15 additions & 19 deletions appraise/evaluation/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,6 @@ def _handle_ranking(request, task, items):
end_datetime = datetime.fromtimestamp(float(end_timestamp))
duration = end_datetime - start_datetime

LOGGER.debug('start_timestamp: {}'.format(start_timestamp))
LOGGER.debug('start__datetime: {}'.format(start_datetime))
LOGGER.debug('end_timestamp: {}'.format(end_timestamp))
LOGGER.debug('end_datetime: {}'.format(end_datetime))
LOGGER.debug('duration: {}'.format(duration))

# Initialise order from order_random.
order = [int(x) for x in order_random.split(',')]

Expand Down Expand Up @@ -273,21 +267,23 @@ def _handle_postediting(request, task, items):
and creates an EvaluationResult instance on HTTP POST submission.
"""
now = datetime.now()

if request.method == "POST":
item_id = request.POST.get('item_id')
edit_id = request.POST.get('edit_id', 0)
end_timestamp = request.POST.get('end_timestamp', None)
submit_button = request.POST.get('submit_button')
from_scratch = request.POST.get('from_scratch')
postedited = request.POST.get('postedited', 'EMPTY')
_now = request.POST.get('now')
start_timestamp = request.POST.get('start_timestamp', None)

current_item = get_object_or_404(EvaluationItem, pk=int(item_id))

# Compute duration for this item.
duration = None
if _now:
duration = now - datetime.fromtimestamp(float(_now))
if end_timestamp and start_timestamp:
start_datetime = datetime.fromtimestamp(float(start_timestamp))
end_datetime = datetime.fromtimestamp(float(end_timestamp))
duration = end_datetime - start_datetime

print
print "item_id: {0}".format(item_id)
Expand Down Expand Up @@ -322,7 +318,6 @@ def _handle_postediting(request, task, items):

dictionary = {'title': 'Post-editing', 'item_id': item.id,
'source_text': source_text, 'reference_text': reference_text,
'now': mktime(datetime.now().timetuple()),
'translations': item.translations,
'description': task.description,
'task_progress': '{0:03d}/{1:03d}'.format(_finished+1, _total),
Expand All @@ -340,22 +335,24 @@ def _handle_error_classification(request, task, items):
and creates an EvaluationResult instance on HTTP POST submission.
"""
now = datetime.now()

if request.method == "POST":
end_timestamp = request.POST.get('start_timestamp', None)
item_id = request.POST.get('item_id')
words = request.POST.get('words')
missing_words = request.POST.get('missing_words')
too_many_errors = request.POST.get('too_many_errors')
start_timestamp = request.POST.get('start_timestamp', None)
submit_button = request.POST.get('submit_button')
_now = request.POST.get('now')

current_item = get_object_or_404(EvaluationItem, pk=int(item_id))

# Compute duration for this item.
duration = None
if _now:
duration = now - datetime.fromtimestamp(float(_now))

if end_timestamp and start_timestamp:
start_datetime = datetime.fromtimestamp(float(start_timestamp))
end_datetime = datetime.fromtimestamp(float(end_timestamp))
duration = end_datetime - start_datetime

errors = {}
if words:
for index in range(int(words)):
Expand Down Expand Up @@ -407,7 +404,6 @@ def _handle_error_classification(request, task, items):
words = item.translations[0][0].split(' ')
dictionary = {'title': 'Error Classification', 'item_id': item.id,
'source_text': source_text, 'reference_text': reference_text,
'now': mktime(datetime.now().timetuple()),
'translation': translation,
'words': words,
'description': task.description,
Expand Down
14 changes: 10 additions & 4 deletions appraise/templates/evaluation/error_classification.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
$('#edit_'+i).hide();
$('#view_'+i).html('<em>Click to classify errors for this word...</em>');
}
$('input[name="now"]').val(Date.now()/1000.0);
$('input[name="start_timestamp"]').val(Date.now()/1000.0);
});

function update_error_summary()
Expand Down Expand Up @@ -107,6 +107,11 @@
}
}

function add_end_timestamp()
{
$('input[name="end_timestamp"]').val(Date.now()/1000.0);
}

function reset_form()
{
$('input[name="missing_words"]').removeAttr('checked');
Expand All @@ -124,7 +129,7 @@
}
}
$('#error_summary').html('<em>No errors classified yet...</em>');
$('input[name="now"]').val(Date.now()/1000.0);
$('input[name="start_timestamp"]').val(Date.now()/1000.0);
}

function validate_form()
Expand Down Expand Up @@ -192,10 +197,11 @@
</div>
</div>

<form action="{{action_url}}" method="post">
<form action="{{action_url}}" method="post" onsubmit="javascript:add_end_timestamp();">

<input name="end_timestamp" type="hidden" value="" />
<input name="item_id" type="hidden" value="{{item_id}}" />
<input name="now" type="hidden" value="{{now}}" />
<input name="start_timestamp" type="hidden" value="" />
<input name="words" type="hidden" value="{{words|length}}" />

<input name="missing_words" type="checkbox" value="MISSING_WORDS" />
Expand Down
14 changes: 10 additions & 4 deletions appraise/templates/evaluation/postediting.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{% else %}
$('textarea[name="postedited"]').html($('input[name="translation"]').val());
{% endif %}
$('input[name="now"]').val(Date.now()/1000.0);
$('input[name="start_timestamp"]').val(Date.now()/1000.0);
});

function select_sentence(parent)
Expand All @@ -38,6 +38,11 @@
$('textarea[name="postedited"]').val('');
}

function add_end_timestamp()
{
$('input[name="end_timestamp"]').val(Date.now()/1000.0);
}

function reset_form()
{
{% if translations|length > 1 %}
Expand All @@ -50,7 +55,7 @@

$('input[name="from_scratch"]').removeAttr('checked');
$('input[name="from_scratch"]').attr('disabled', true);
$('input[name="now"]').val(Date.now()/1000.0);
$('input[name="start_timestamp"]').val(Date.now()/1000.0);
selection_done = false;
}

Expand Down Expand Up @@ -119,10 +124,11 @@
{% endif %}
</div>

<form action="{{action_url}}" method="post" onsubmit="javascript:on_submit_activate_from_scratch_again();">
<form action="{{action_url}}" method="post" onsubmit="javascript:add_end_timestamp;on_submit_activate_from_scratch_again();">

<input name="end_timestamp" type="hidden" value="" />
<input name="item_id" type="hidden" value="{{item_id}}" />
<input name="now" type="hidden" value="{{now}}" />
<input name="start_timestamp" type="hidden" value="" />

{% if translations|length > 1 %}
<span id="translations">
Expand Down
6 changes: 3 additions & 3 deletions appraise/templates/evaluation/ranking.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
$('input[name="start_timestamp"]').val(Date.now()/1000.0);
});

function add_submit_timestamp()
function add_end_timestamp()
{
$('input[name="end_timestamp"]').val(Date.now()/1000.0);
}
Expand Down Expand Up @@ -73,12 +73,12 @@
{% endif %}
</div>

<form action="{{action_url}}" method="post" onsubmit="javascript:add_submit_timestamp();">
<form action="{{action_url}}" method="post" onsubmit="javascript:add_end_timestamp();">

<input name="end_timestamp" type="hidden" value="" />
<input name="item_id" type="hidden" value="{{item_id}}" />
<input name="start_timestamp" type="hidden" value="" />
<input name="order" type="hidden" value="{{order}}" />
<input name="end_timestamp" type="hidden" value="" />

<span id="translations">
{% for translation in translations %}
Expand Down

0 comments on commit 9b02f52

Please sign in to comment.