Skip to content
Browse files

@ajpocus reported that a hit's completeness wasn't being reported cor…

…rectly. Cleaned up his implementation a bit to manually track the number of assignments.
  • Loading branch information...
1 parent 4e40b5a commit edfd7063cd78abfdece9dff461590a13adb90660 @aantix committed Feb 28, 2012
Showing with 21 additions and 11 deletions.
  1. +1 −0 lib/generators/turkee/templates/turkee_migration.rb.erb
  2. +20 −11 lib/turkee.rb
View
1 lib/generators/turkee/templates/turkee_migration.rb.erb
@@ -12,6 +12,7 @@ class CreateTurkeeTasks < ActiveRecord::Migration
t.integer "hit_num_assignments"
t.integer "hit_lifetime"
t.string "form_url"
+ t.integer "completed_assignments", :default => 0
t.boolean "complete"
t.timestamps
end
View
31 lib/turkee.rb
@@ -42,11 +42,12 @@ def self.process_hits(turkee_task = nil)
model = find_model(param_hash)
next if model.nil?
+ puts "param_hash = #{param_hash}"
result = model.create(param_hash[model.to_s.underscore])
# If there's a custom approve? method, see if we should approve the submitted assignment
# otherwise just approve it by default
- process_result(assignment, result)
+ process_result(assignment, result, turk)
TurkeeImportedAssignment.create(:assignment_id => assignment.id) rescue nil
end
@@ -133,30 +134,38 @@ def logger
end
def self.check_hit_completeness(hit, turk, models)
- mark_completed(hit, models, turk) if hit.completed_assignments == turk.hit_num_assignments
+ puts "#### turk.completed_assignments == turk.hit_num_assignments :: #{turk.completed_assignments} == #{turk.hit_num_assignments}"
+ if turk.completed_assignments == turk.hit_num_assignments
+ hit.dispose!
+ turk.complete = true
+ turk.save
+ models.each { |model| model.hit_complete(turk) if model.respond_to?(:hit_complete) }
+ end
end
- def self.mark_completed(hit, models, turk)
- hit.dispose!
-
- turk.complete = true
- turk.save
-
- models.each { |model| model.hit_complete(turk) if model.respond_to?(:hit_complete) }
- end
- def self.process_result(assignment, result)
+ def self.process_result(assignment, result, turk)
if result.errors.size > 0
logger.info "Errors : #{result.inspect}"
assignment.reject!('Failed to enter proper data.')
elsif result.respond_to?(:approve?)
logger.debug "Approving : #{result.inspect}"
+ increment_complete_assignments(turk)
result.approve? ? assignment.approve!('') : assignment.reject!('Rejected criteria.')
else
+ increment_complete_assignments(turk)
assignment.approve!('')
end
end
+ def self.increment_complete_assignments(turk)
+ # Backward compatibility; completed_assignments may not exist in the table
+ if turk.respond_to?(:completed_assignments)
+ turk.completed_assignments += 1
+ turk.save
+ end
+ end
+
def self.task_items(turkee_task)
turkee_task.nil? ? TurkeeTask.unprocessed_hits : Array.new << turkee_task
end

0 comments on commit edfd706

Please sign in to comment.
Something went wrong with that request. Please try again.