Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix comments from pull request

  • Loading branch information...
commit d108b11277c2bd56ed445600e4065002277fbcf1 1 parent be4cfdc
@benweissmann benweissmann authored
View
2  app/models/evaluation.rb
@@ -339,7 +339,7 @@ def median_time
# Effective pay rate, in cents per hour, based on mean time
# tasks per second * seconds per hour * pay per task = pay per hour
def mean_pay_rate
- worker_stats.mean_pay_rate
+ worker_stats.overall_pay_rate
end
# Effective pay rate, in cents per hour, based on median time
View
8 app/views/m_turk_users/index.html.haml
@@ -19,7 +19,7 @@
%tr
%th ID
%th Name
- %th # of Evalutions Worked On
+ %th # of Evaluations Worked On
%th # of Responses
%th Average Responses per Evaluation
%th Mean Time (s)
@@ -35,9 +35,9 @@
%td= user.evaluation_count
%td= user.task_responses.count
%td= user.task_responses.count.to_f / user.evaluation_count
- %td= user.stats.mean_time
- %td= user.stats.median_time
- %td= format_cents(user.stats.mean_pay_rate)
+ %td= user.stats.mean_time.round(2)
+ %td= user.stats.median_time.round(2)
+ %td= format_cents(user.stats.overall_pay_rate)
%td= format_cents(user.stats.median_pay_rate)
%td
= link_to m_turk_user_path(user), :class => 'btn' do
View
8 app/views/m_turk_users/show.html.haml
@@ -34,7 +34,7 @@
= f.text_field :name, :class => 'text_field'
.control-group
.control-label
- \# of Evalutions Worked On
+ \# of Evaluations Worked On
.controls
= @m_turk_user.evaluation_count
.control-group
@@ -51,17 +51,17 @@
.control-label
Mean Time (s)
.controls
- = @m_turk_user.stats.mean_time
+ = @m_turk_user.stats.mean_time.round(2)
.control-group
.control-label
Median Time (s)
.controls
- = @m_turk_user.stats.median_time
+ = @m_turk_user.stats.median_time.round(2)
.control-group
.control-label
Mean Pay Rate ($/hr)
.controls
- = format_cents(@m_turk_user.stats.mean_pay_rate)
+ = format_cents(@m_turk_user.stats.overall_pay_rate)
.control-group
.control-label
Median Pay Rate ($/hr)
View
25 lib/stats.rb
@@ -1,6 +1,7 @@
# Tools for generating worker stats based on response times an payments
class CRStats
# tasks: tuples of [[time to complete task, amount paid for task], ...]
+ # Times are in seconds, payments are in cents.
def initialize tasks
@tasks = tasks
@times = tasks.map(&:first)
@@ -23,18 +24,22 @@ def median_time
median @times
end
- # Effective pay rate, in cents per hour, based on mean time
+ # Effective pay rate, in cents per hour, over all tasks
# This is calculated as:
# sum(pay rate for task * time spent on task) / sum(time spent on task)
# e.g. the average pay rate for each task weighted by the time spent on the
- # task -- which is mathematically equivalent to the pay rate based on the mean
- # payment and the mean task time.
+ # task -- which is mathematically equivalent to the pay rate based on the sum
+ # of payments and the sum of task times,
+ def overall_pay_rate
+ pay_rate(sum(@times), sum(@payments))
+ end
+
+ # Mean of the tasks' pay rates
def mean_pay_rate
- pay_rate(mean(@times), mean(@payments))
+ mean(pay_rates)
end
- # Effective pay rate, in cents per hour, based on median time
- # (This is calculated as the median of the pay rates)
+ # Median of the tasks' pay rates
def median_pay_rate
median(pay_rates)
end
@@ -43,10 +48,12 @@ def median_pay_rate
def pay_rates
@tasks.map do |task|
- pay_rate *task
+ pay_rate(*task)
end
end
+ # Returns the pay rate, in cents per hour, given the time in seconds
+ # and the payment in cents.
def pay_rate time, payment
if time == 0
# assume time is actually 1
@@ -57,12 +64,12 @@ def pay_rate time, payment
end
def sum ary
- ary.inject &:+
+ ary.inject 0, &:+
end
def mean ary
return 0 if ary.length == 0
- sum(ary) / ary.length
+ sum(ary).to_f / ary.length
end
def median ary
View
4 test/functional/views/task_responses/index_test.rb
@@ -149,7 +149,7 @@ class TaskResponsesIndexTest < ActionController::TestCase
assert_select "tbody tr:first-child td:nth-child(8):content('#{@mc2_opt2.label}')"
assert_select "tbody tr:first-child td:nth-child(9):content('response 1')"
assert_select "tbody tr:first-child td:nth-child(10):content('response 2')"
- assert_select "tbody tr:first-child td:nth-child(11):content('#{@r1.m_turk_user_id}')"
+ assert_select "tbody tr:first-child td:nth-child(11) a:content('#{@r1.m_turk_user_id}')"
assert_select "tbody tr:first-child td:nth-child(12):content('10')"
assert_select "tbody tr:first-child td:nth-child(13) .approval-status:content('Undecided')"
@@ -164,7 +164,7 @@ class TaskResponsesIndexTest < ActionController::TestCase
assert_select "tbody tr:nth-child(2) td:nth-child(8):content('#{@mc2_opt3.label}')"
assert_select "tbody tr:nth-child(2) td:nth-child(9):content('response 3')"
assert_select "tbody tr:nth-child(2) td:nth-child(10):content('response 4')"
- assert_select "tbody tr:nth-child(2) td:nth-child(11):content('#{@r2.m_turk_user_id}')"
+ assert_select "tbody tr:nth-child(2) td:nth-child(11) a:content('#{@r2.m_turk_user_id}')"
assert_select "tbody tr:nth-child(2) td:nth-child(12):content('20')"
assert_select "tbody tr:nth-child(2) td:nth-child(13) .approval-status:content('Rejected')"
end
View
8 test/unit/models/evaluations_test.rb
@@ -411,8 +411,8 @@ class EvaluationsTest < ActiveSupport::TestCase
end
assert_equal 9, eval1.mean_time
assert_equal 8.5, eval1.median_time
- assert_equal 14000, eval1.mean_pay_rate
- assert_in_delta 14800, eval1.median_pay_rate, 1
+ assert_in_delta 14000, eval1.mean_pay_rate, 1
+ assert_equal 14875, eval1.median_pay_rate
# payment $0.15, times: 0, 10, 35
# mean: 15, median: 10
@@ -424,7 +424,7 @@ class EvaluationsTest < ActiveSupport::TestCase
end
assert_equal 15, eval2.mean_time
assert_equal 10, eval2.median_time
- assert_equal 3600, eval2.mean_pay_rate
+ assert_in_delta 3600, eval2.mean_pay_rate, 1
assert_equal 5400, eval2.median_pay_rate
# test 0 responses
@@ -442,7 +442,5 @@ class EvaluationsTest < ActiveSupport::TestCase
end
assert_equal 0, eval4.mean_time
assert_equal 0, eval4.median_time
- assert_equal 0, eval4.mean_pay_rate
- assert_equal 0, eval4.median_pay_rate
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.